H5Editor.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="H5Editor">
  3. <div class="H5Editor_left">1</div>
  4. <div class="H5Editor_center">
  5. <div class="pageClient">
  6. <div class="page">
  7. <div
  8. class="pageMain"
  9. :style="{
  10. width: page.width + 'px',
  11. 'height': page.height ? page.height + 'px' : undefined,
  12. ...backgroundStyle(),
  13. }"
  14. >
  15. <template
  16. v-for="(item, index) in hoversList[selectPage].components || []"
  17. :key="index"
  18. >
  19. <h5-image v-if="item.type === 'image'" :item="item"></h5-image>
  20. <h5-paragraph
  21. v-if="item.type === 'paragraph'"
  22. :item="item"
  23. @saveParagraph="text => saveParagraph(text, index)"
  24. ></h5-paragraph>
  25. <h5-from-component
  26. v-if="item.type === 'fromComponent'"
  27. :item="item"
  28. >
  29. <!-- <div style="padding: 5px">
  30. <van-button block type="danger" native-type="submit" disabled>
  31. 我要报名
  32. </van-button>
  33. </div> -->
  34. <template v-for="(v, i) in (item.child_list || [])" :key="i">
  35. <h5-van-field v-if="v.type === 'van-field'" :item="v"></h5-van-field>
  36. <h5-van-buttom v-if="v.type === 'van-buttom'" :item="v"></h5-van-buttom>
  37. </template>
  38. </h5-from-component>
  39. </template>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. <div class="H5Editor_right">
  45. <div v-for="(item, index) in hoversList" :key="item.url">
  46. <el-image
  47. @click="() => selectPageFunc(index, item)"
  48. :class="{ selectPage: selectPage === index }"
  49. :src="item.url"
  50. :fit="item.background_mode || 'fill'"
  51. />
  52. <div class="title">第 {{ index + 1 }} 页</div>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script setup>
  58. import { ref } from 'vue';
  59. import { useRoute } from 'vue-router';
  60. import H5Image from './components/H5Editor/img.vue';
  61. import H5Paragraph from './components/H5Editor/paragraph.vue';
  62. import H5FromComponent from './components/H5Editor/from.vue';
  63. import H5VanField from './components/H5Editor/van_field.vue';
  64. import H5VanButtom from './components/H5Editor/van_buttom.vue';
  65. const route = useRoute();
  66. const item = JSON.parse(route.query.item || '{}');
  67. const selectPage = ref(0);
  68. const hoversList = ref(item.hoversList || []);
  69. const page = ref({ width: 375, height: 0 });
  70. const selectPageFunc = (index = 0) => {
  71. selectPage.value = index;
  72. };
  73. // 查看页面大小,
  74. const img = new Image();
  75. img.src = hoversList.value[selectPage.value].background_url || '';
  76. img.onload = function () {
  77. page.value.height = (this.height / this.width) * page.value.width;
  78. };
  79. const backgroundStyle = () => {
  80. const back = hoversList.value[selectPage.value].background_url;
  81. const color = /^#|^rgb/g.test(back);
  82. if (color)
  83. return {
  84. 'background-color': back,
  85. };
  86. return {
  87. 'background-image': 'url(' + back + ')',
  88. };
  89. };
  90. const saveParagraph = (paragraph, index) => {
  91. console.log(paragraph, index);
  92. };
  93. </script>
  94. <style scoped>
  95. .H5Editor_right .el-image {
  96. width: 184px;
  97. height: 280px;
  98. margin: 0 auto;
  99. display: block;
  100. border: 3px solid #fff;
  101. }
  102. .H5Editor {
  103. background-color: #d0cfd8;
  104. height: 100%;
  105. }
  106. .H5Editor_left,
  107. .H5Editor_center,
  108. .H5Editor_right {
  109. display: inline-block;
  110. height: 100%;
  111. }
  112. .H5Editor_center {
  113. width: calc(100% - 500px);
  114. position: relative;
  115. }
  116. .H5Editor_center .pageClient {
  117. position: absolute;
  118. top: 50%;
  119. left: 50%;
  120. transform: translate(-50%, -50%);
  121. padding: 15px 5px;
  122. /* background-color: #000; */
  123. border-radius: 1em;
  124. }
  125. .H5Editor_center .page {
  126. width: 375px;
  127. height: 667px;
  128. background-color: #fff;
  129. overflow: auto;
  130. }
  131. .H5Editor_center .pageMain {
  132. min-height: 100%;
  133. background-repeat: no-repeat;
  134. background-size: 100% 100%;
  135. }
  136. .H5Editor_right {
  137. overflow-y: auto;
  138. padding: 1em;
  139. width: 300px;
  140. background-color: #f3f3f3;
  141. }
  142. .H5Editor_left {
  143. width: 200px;
  144. background-color: #f3f3f3;
  145. }
  146. .H5Editor_right .selectPage {
  147. border: 3px solid #409eff;
  148. }
  149. .H5Editor_right .title {
  150. text-align: center;
  151. color: #333;
  152. padding: 8px 0;
  153. font-size: 16px;
  154. }
  155. </style>