H5Mall.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div class="H5Mall">
  3. <div class="mainBody">
  4. <div
  5. class="item"
  6. @click="() => toH5Editor(item)"
  7. v-for="(item, index) in list"
  8. :key="index"
  9. >
  10. <component :is="components[item.type]" :item="item"></component>
  11. <div class="main_item" v-text="item.title"></div>
  12. </div>
  13. </div>
  14. <el-button @click="showData" class="createPageList"> 已创建页面 </el-button>
  15. <el-dialog v-model="show" title="已创建页面">
  16. <el-table :data="localList.list">
  17. <el-table-column property="title" label="页面名称" />
  18. <el-table-column label="封面图" header-align="center" width="100px">
  19. <template #default="scope">
  20. <el-image style="width: 76px; height: 100px" :src="scope.row.cover" fit="contain" />
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="状态" width="100px">
  24. <template #default="scope">
  25. {{ h5Status[scope.row.h5Status] }}
  26. </template>
  27. </el-table-column>
  28. <el-table-column property="url" label="操作">
  29. <template #default="scope">
  30. <el-button
  31. v-if="showCopy(scope.row.url)"
  32. type="primary"
  33. link
  34. @click="() => copyurl(scope.row.url)"
  35. >
  36. 复制链接
  37. </el-button>
  38. <el-button
  39. v-if="scope.row.url"
  40. type="primary"
  41. link
  42. @click="() => openurl(scope.row.url)"
  43. >
  44. 打开
  45. </el-button>
  46. <el-button link type="primary" @click="() => editBL(scope)">
  47. 修改
  48. </el-button>
  49. <el-popconfirm
  50. title="是否确认删除?"
  51. @confirm="() => deleteBL(scope)"
  52. >
  53. <template #reference>
  54. <el-button link type="danger"> 删除 </el-button>
  55. </template>
  56. </el-popconfirm>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. <template #footer>
  61. <el-pagination
  62. @current-change="currentChange"
  63. background
  64. layout="prev, pager, next"
  65. :total="localList.total"
  66. />
  67. </template>
  68. </el-dialog>
  69. </div>
  70. </template>
  71. <script setup>
  72. import { ref } from 'vue';
  73. import { ElMessage } from 'element-plus';
  74. import { useRouter } from 'vue-router';
  75. import H5 from './components/H5.vue';
  76. import LONGPAGE from './components/LONGPAGE.vue';
  77. import POSTER from './components/POSTER.vue';
  78. import {
  79. getTemplateList,
  80. getPersonalList,
  81. deletePersonalList,
  82. } from '../../api/index.js';
  83. const components = {
  84. H5,
  85. LONGPAGE,
  86. POSTER,
  87. };
  88. const router = useRouter();
  89. // const route = useRoute();
  90. const show = ref(false);
  91. const localList = ref({
  92. list: [],
  93. size: 20,
  94. page: 1,
  95. });
  96. const list = ref([]);
  97. const h5Status = ['生成中', '已生成'];
  98. getTemplateList({}).then(r => {
  99. list.value = r || [];
  100. });
  101. const toH5Editor = item => {
  102. router.push({
  103. path: '/h5editor',
  104. query: {
  105. item: JSON.stringify(item),
  106. },
  107. });
  108. };
  109. const showData = () => {
  110. localList.value.page = 1;
  111. show.value = true;
  112. personalListFunc();
  113. };
  114. const currentChange = page => {
  115. localList.value.page = page;
  116. personalListFunc();
  117. };
  118. const personalListFunc = () => {
  119. getPersonalList({
  120. data: {
  121. page: localList.value.page,
  122. size: localList.value.size,
  123. },
  124. }).then(r => {
  125. localList.value.list = r.records || [];
  126. localList.value.total = r.total || 0;
  127. localList.value.page += 1;
  128. });
  129. };
  130. const editBL = item => {
  131. router.push({
  132. path: '/h5editor',
  133. query: {
  134. item: JSON.stringify(item.row),
  135. },
  136. });
  137. };
  138. const deleteBL = item => {
  139. deletePersonalList({
  140. data: {
  141. operateId: item.row.operateId,
  142. },
  143. }).then(() => {
  144. localList.value.list.splice(item.index, 1);
  145. });
  146. };
  147. const openurl = url => window.open(url);
  148. const showCopy = url => ('clipboard' in navigator) && url
  149. const copyurl = url => {
  150. console.log(navigator)
  151. if (!('clipboard' in navigator)) return;
  152. auth().then(res => {
  153. if (!res) {
  154. // 未授权
  155. ElMessage({
  156. type: 'error',
  157. message: '授权未通过',
  158. });
  159. return;
  160. }
  161. navigator.clipboard.writeText(url).then(
  162. () => {
  163. ElMessage({
  164. type: 'success',
  165. message: '地址复制成功',
  166. });
  167. },
  168. () => {
  169. ElMessage({
  170. type: 'error',
  171. message: '复制失败',
  172. });
  173. }
  174. );
  175. }).catch(() => {
  176. ElMessage({
  177. type: 'error',
  178. message: '授权未通过',
  179. })
  180. });
  181. };
  182. const auth = () => {
  183. return new Promise((resolve, reject) => {
  184. navigator.permissions.query({ name: 'clipboard-read' }).then(
  185. result => {
  186. if (result.state == 'granted' || result.state == 'prompt') {
  187. resolve(true);
  188. } else {
  189. resolve(false);
  190. }
  191. },
  192. error => {
  193. reject(error);
  194. }
  195. );
  196. });
  197. };
  198. </script>
  199. <style scoped>
  200. .H5Mall {
  201. padding: 1em;
  202. height: 100%;
  203. }
  204. .mainBody {
  205. font-weight: 500;
  206. padding: 2em 0 1em 1em;
  207. }
  208. .mainBody .item {
  209. display: inline-block;
  210. width: 184px;
  211. height: 333px;
  212. transition: all 0.3s;
  213. vertical-align: middle;
  214. margin-right: 1em;
  215. border-radius: 5px;
  216. overflow: hidden;
  217. cursor: pointer;
  218. box-shadow: var(--el-box-shadow-lighter);
  219. }
  220. .el-image {
  221. height: 280px;
  222. }
  223. .main_item {
  224. color: #666;
  225. padding: 0 5px;
  226. margin: 5px 0;
  227. font-size: 14px;
  228. overflow: hidden;
  229. white-space: nowrap;
  230. text-overflow: ellipsis;
  231. }
  232. .mainBody .item:hover {
  233. box-shadow: var(--el-box-shadow);
  234. margin-top: -15px;
  235. }
  236. .mainBody img {
  237. vertical-align: middle;
  238. }
  239. .createPageList {
  240. position: absolute;
  241. top: 1em;
  242. right: 1em;
  243. }
  244. </style>