list.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div class="p-4">
  3. <BasicTable @register="registerTable" :rowSelection="{ type: 'checkbox' }">
  4. <template #toolbar>
  5. <!-- <a-button type="primary" @click="() => {}"> 新增</a-button> -->
  6. <!-- <a-button type="primary" color="warning" @click="() => {}"> 编辑</a-button>
  7. <a-button type="primary" color="error" @click="() => {}"> 删除</a-button> -->
  8. </template>
  9. <template #cover="{ record }">
  10. <TableImg
  11. :size="120"
  12. :simpleShow="true"
  13. :imgList="[record.thumb || '/resource/img/pic_bg@2x.png']"
  14. />
  15. </template>
  16. <template #action="{ record }">
  17. <TableAction
  18. :actions="[
  19. {
  20. // icon: 'mdi:briefcase-download',
  21. label: t('routes.scenes.downloadScene'),
  22. popConfirm: {
  23. title: t('routes.scenes.downloadSceneConfirm'),
  24. confirm: handleDownloadScene.bind(null, record),
  25. },
  26. },
  27. {
  28. // icon: 'dashicons:editor-kitchensink',
  29. color: 'error',
  30. label: t('routes.scenes.editor'),
  31. onClick: openSceneEditor.bind(null, record),
  32. },
  33. // {
  34. // // icon: 'dashicons:editor-kitchensink',
  35. // color: 'error',
  36. // label: t('routes.scenes.makeLiveCover'),
  37. // onClick: openSceneEditor.bind(null, record),
  38. // },
  39. // {
  40. // // icon: 'dashicons:editor-kitchensink',
  41. // color: 'error',
  42. // label: t('routes.scenes.editor'),
  43. // onClick: openSceneEditor.bind(null, record),
  44. // },
  45. ]"
  46. />
  47. </template>
  48. </BasicTable>
  49. <DownloadModal @register="registerDownloadModal" />
  50. </div>
  51. </template>
  52. <script lang="ts">
  53. import { defineComponent, computed } from 'vue';
  54. import {
  55. BasicTable,
  56. useTable,
  57. BasicColumn,
  58. FormProps,
  59. TableAction,
  60. TableImg,
  61. } from '/@/components/Table';
  62. import { useMessage } from '/@/hooks/web/useMessage';
  63. import { useModal } from '/@/components/Modal';
  64. // import { uploadApi } from '/@/api/sys/upload';
  65. // import { Progress } from 'ant-design-vue';
  66. // import { h } from 'vue';
  67. // addDownloadNumApi,
  68. // checkDownloadApi,
  69. import {
  70. ListApi,
  71. generateSceneEditTokenApi,
  72. downloadSceneDataAPi,
  73. addDownloadNumApi,
  74. checkDownloadApi,
  75. } from '/@/api/scene/list';
  76. import { useI18n } from '/@/hooks/web/useI18n';
  77. // import {
  78. // downloadByUrl,
  79. // // downloadByData,
  80. // // downloadByBase64,
  81. // // downloadByOnlineUrl,
  82. // } from '/@/utils/file/download';
  83. import { useUserStore } from '/@/store/modules/user';
  84. import DownloadModal from './downloadModal.vue';
  85. import { useLocaleStore } from '/@/store/modules/locale';
  86. const localeStore = useLocaleStore();
  87. export default defineComponent({
  88. components: { BasicTable, TableAction, TableImg, DownloadModal },
  89. setup() {
  90. const { createMessage } = useMessage();
  91. const [registerDownloadModal, { openModal: openDownloadModal }] = useModal();
  92. const { t } = useI18n();
  93. const isJA = computed(() => localeStore.getLocale === 'ja');
  94. const columns: BasicColumn[] = [
  95. {
  96. title: 'ID',
  97. dataIndex: 'id',
  98. width: 80,
  99. defaultHidden: true,
  100. },
  101. {
  102. title: t('routes.scenes.sceneName'),
  103. dataIndex: 'sceneName',
  104. ellipsis: false,
  105. width: 120,
  106. },
  107. {
  108. title: t('routes.corporation.enterpriseName'),
  109. dataIndex: 'companyName',
  110. ellipsis: false,
  111. width: 120,
  112. },
  113. {
  114. title: t('routes.scenes.webSite'),
  115. dataIndex: 'webSite',
  116. slots: { customRender: 'link' },
  117. width: 180,
  118. },
  119. {
  120. title: t('routes.scenes.appListPicUrl'),
  121. dataIndex: 'thumb',
  122. slots: { customRender: 'cover' },
  123. width: 150,
  124. },
  125. {
  126. title: t('routes.scenes.childName'),
  127. dataIndex: 'childName',
  128. width: 120,
  129. },
  130. {
  131. title: t('routes.scenes.viewCount'),
  132. dataIndex: 'viewCount',
  133. width: 180,
  134. },
  135. {
  136. title: t('routes.scenes.createTime'),
  137. dataIndex: 'createTime',
  138. width: 180,
  139. },
  140. {
  141. title: t('routes.scenes.num'),
  142. dataIndex: 'num',
  143. width: 180,
  144. },
  145. // {
  146. // title: t('routes.scenes.process'),
  147. // dataIndex: '',
  148. // width: 180,
  149. // slots: { customRender: 'process' },
  150. // ifShow: false,
  151. // },
  152. {
  153. title: t('common.operation'),
  154. dataIndex: '',
  155. slots: { customRender: 'action' },
  156. width: isJA.value ? 300 : 180,
  157. fixed: 'right',
  158. },
  159. ];
  160. const searchForm: Partial<FormProps> = {
  161. labelWidth: 100,
  162. schemas: [
  163. {
  164. field: 'companyName',
  165. label: t('routes.corporation.enterpriseName'),
  166. component: 'Input',
  167. colProps: {
  168. lg: 6,
  169. xl: 6,
  170. xxl: 6,
  171. sm: 12,
  172. xs: 24,
  173. },
  174. },
  175. {
  176. field: 'sceneName',
  177. label: t('routes.scenes.sceneName'),
  178. component: 'Input',
  179. colProps: {
  180. lg: 6,
  181. xl: 6,
  182. xxl: 6,
  183. sm: 12,
  184. xs: 24,
  185. },
  186. },
  187. {
  188. field: 'childName',
  189. label: t('routes.scenes.childName'),
  190. component: 'Input',
  191. colProps: {
  192. lg: 6,
  193. xl: 6,
  194. xxl: 6,
  195. sm: 12,
  196. xs: 24,
  197. },
  198. },
  199. ],
  200. };
  201. // { getForm }
  202. const [registerTable] = useTable({
  203. title: t('routes.scenes.sceneList'),
  204. api: ListApi,
  205. columns: columns,
  206. useSearchForm: true,
  207. formConfig: searchForm,
  208. showTableSetting: true,
  209. tableSetting: { fullScreen: true },
  210. clickToRowSelect: false,
  211. showIndexColumn: false,
  212. rowKey: 'id',
  213. //TODO
  214. fetchSetting: {
  215. pageField: 'page',
  216. sizeField: 'limit',
  217. listField: 'list',
  218. totalField: 'total',
  219. },
  220. });
  221. async function openSceneEditor(record: Recordable) {
  222. try {
  223. const url = record.webSite.replace('smobile', 'epc') + '&menu=business&token=';
  224. const userStore = useUserStore();
  225. const data = await generateSceneEditTokenApi({
  226. sceneNum: record.num,
  227. userName: userStore.getUserInfo?.phone,
  228. });
  229. console.log('generateSceneEditTokenApi', data);
  230. window.open(url + data);
  231. } catch (error) {
  232. console.log('error', error);
  233. }
  234. }
  235. async function handleDownloadScene(record: Recordable) {
  236. await addDownloadNumApi({
  237. sceneNum: record.num,
  238. });
  239. const checker = await checkDownloadApi({
  240. sceneNum: record.num,
  241. });
  242. const res = await downloadSceneDataAPi({
  243. sceneNum: record.num,
  244. });
  245. console.log('res', res);
  246. // const downloadUrl = res as any as string;
  247. // console.log('downloadUrl', downloadUrl, res);
  248. /**
  249. * mark 2022-03-22 message return success 是要进入openDownloadModal轮询,非表面「成功」字意思。
  250. * message return url 指已下载,转mimeType download
  251. *
  252. * notice: 过往 downloadUrl 是 boolean / string
  253. * 现在 downloadUrl 是 string[success] / string[url]
  254. *
  255. * */
  256. // await openDownloadModal(true, record);
  257. // downloadByUrl({
  258. // url: downloadUrl as any as string,
  259. // target: '_self',
  260. // });
  261. if (checker.downloadStatus === 0) {
  262. await openDownloadModal(true, record);
  263. }
  264. }
  265. return {
  266. registerTable,
  267. createMessage,
  268. t,
  269. openSceneEditor,
  270. handleDownloadScene,
  271. registerDownloadModal,
  272. };
  273. },
  274. });
  275. </script>