caseList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <PageWrapper contentBackground>
  3. <template #footer>
  4. <a-tabs v-model:activeKey="language" @change="changeTable">
  5. <a-tab-pane key="cn" tab="Chinese" />
  6. <a-tab-pane key="en" tab="English" />
  7. </a-tabs>
  8. </template>
  9. <div class="desc-wrap-BasicTable">
  10. <BasicTable @register="registerTable">
  11. <template #toolbar>
  12. <a-button
  13. type="primary"
  14. @click="openModal(true, { language })"
  15. v-if="getCheckPerm('case-add')"
  16. >
  17. 新增案例</a-button
  18. >
  19. </template>
  20. <template #action="{ record }">
  21. <TableAction
  22. stopButtonPropagation
  23. :actions="[
  24. {
  25. label: '撤回',
  26. //icon: 'icon-park-outline:folder-withdrawal-one',
  27. ifShow: getCheckPerm('case-withdraw') && record.isPublic == 1,
  28. onClick: handleWithdraw.bind(null, record),
  29. },
  30. {
  31. label: '发布',
  32. //icon: 'arcticons:efa-publish',
  33. ifShow: getCheckPerm('case-publish') && record.isPublic == 0,
  34. onClick: handlePublish.bind(null, record),
  35. },
  36. {
  37. label: '预览',
  38. //icon: 'ep:edit',
  39. ifShow: getCheckPerm('case-preview'),
  40. onClick: handlePreview.bind(null, record),
  41. },
  42. {
  43. label: '编辑',
  44. //icon: 'ep:edit',
  45. ifShow: getCheckPerm('case-edit') && record.isPublic == 0,
  46. onClick: handleEdit.bind(null, record),
  47. },
  48. {
  49. label: '删除',
  50. //icon: 'ic:outline-delete-outline',
  51. ifShow: getCheckPerm('case-delete'),
  52. popConfirm: {
  53. title: '是否确认删除',
  54. confirm: handleDelete.bind(null, record),
  55. },
  56. },
  57. ]"
  58. />
  59. </template>
  60. </BasicTable>
  61. </div>
  62. <addNewModal @register="register" @update="reload" />
  63. </PageWrapper>
  64. </template>
  65. <script lang="ts">
  66. import { defineComponent, h, ref } from 'vue';
  67. import {
  68. BasicTable,
  69. useTable,
  70. TableAction,
  71. BasicColumn,
  72. TableImg,
  73. FormProps,
  74. } from '/@/components/Table';
  75. import { PageWrapper } from '/@/components/Page';
  76. import { Time } from '/@/components/Time';
  77. import { caseListApi, caseReleaseApi, casePublicApi, caseDelApi } from '/@/api/operate';
  78. import { Descriptions, Switch, Tabs } from 'ant-design-vue';
  79. import { useModal } from '/@/components/Modal';
  80. import { useI18n } from '/@/hooks/web/useI18n';
  81. import { useMessage } from '/@/hooks/web/useMessage';
  82. import addNewModal from './components/case/addModal.vue';
  83. import { usePermissionStore } from '/@/store/modules/permission';
  84. import { useUserStore } from '/@/store/modules/user';
  85. export default defineComponent({
  86. components: {
  87. BasicTable,
  88. TableAction,
  89. PageWrapper,
  90. TableImg,
  91. addNewModal,
  92. [Descriptions.name]: Descriptions,
  93. [Descriptions.Item.name]: Descriptions.Item,
  94. [Tabs.name]: Tabs,
  95. [Tabs.TabPane.name]: Tabs.TabPane,
  96. },
  97. setup() {
  98. const { t } = useI18n();
  99. const { createMessage } = useMessage();
  100. const permissionStore = usePermissionStore();
  101. const { getCheckPerm } = permissionStore;
  102. const userStore = useUserStore();
  103. const [register, { openModal }] = useModal();
  104. const language = ref<string>('cn'); //未处理,0已处理(默认1)
  105. const columns: BasicColumn[] = [
  106. {
  107. title: '案例标题',
  108. dataIndex: 'title',
  109. ellipsis: true,
  110. width: 250,
  111. },
  112. // {
  113. // title: '来源',
  114. // dataIndex: 'source',
  115. // ellipsis: true,
  116. // width: 120,
  117. // },
  118. {
  119. title: '类型',
  120. dataIndex: 'typeId',
  121. ellipsis: true,
  122. width: 80,
  123. customRender: ({ record }) => {
  124. let obj = {
  125. smartCity: '智慧城市',
  126. museum: '博物馆',
  127. government: '刑侦消防',
  128. property: '房产营销',
  129. };
  130. return obj[record.typeId] || '智慧城市';
  131. },
  132. },
  133. {
  134. title: '创建人',
  135. ellipsis: true,
  136. dataIndex: 'sysUserName',
  137. width: 120,
  138. },
  139. {
  140. title: '创建时间',
  141. dataIndex: 'createTime',
  142. width: 150,
  143. customRender: ({ record }) => {
  144. return (
  145. record.createTime &&
  146. h(Time, {
  147. value: record.createTime,
  148. mode: 'datetime',
  149. })
  150. );
  151. },
  152. },
  153. {
  154. title: '发布时间',
  155. dataIndex: 'publicTime',
  156. width: 150,
  157. customRender: ({ record }) => {
  158. return (
  159. record.publicTime &&
  160. h(Time, {
  161. value: record.publicTime,
  162. mode: 'datetime',
  163. })
  164. );
  165. },
  166. },
  167. {
  168. title: '排序',
  169. ellipsis: true,
  170. dataIndex: 'sort',
  171. width: 80,
  172. },
  173. // {
  174. // title: '是否显示',
  175. // dataIndex: 'isShow',
  176. // ifShow: getCheckPerm('case-display'),
  177. // width: 80,
  178. // customRender: ({ record }) => {
  179. // if (!Reflect.has(record, 'pendingStatus')) {
  180. // record.pendingStatus = false;
  181. // }
  182. // return h(Switch, {
  183. // checked: record.isShow === 1,
  184. // checkedChildren: '是',
  185. // unCheckedChildren: '否',
  186. // loading: false,
  187. // onChange: async (checked: boolean) => {
  188. // record.pendingStatus = true;
  189. // const id: string = record.id || '';
  190. // const newStatus = checked ? 1 : 0;
  191. // Reflect.set(record, 'isShow', newStatus);
  192. // await caseReleaseApi({ id: id, isShow: newStatus });
  193. // createMessage.success(t('common.optSuccess'));
  194. // // reload()
  195. // },
  196. // });
  197. // },
  198. //},
  199. ];
  200. const searchForm: Partial<FormProps> = {
  201. labelWidth: 100,
  202. autoSubmitOnEnter: true,
  203. schemas: [
  204. {
  205. field: 'publicTime',
  206. label: t('routes.operate.releaseTime'),
  207. component: 'RangePicker',
  208. componentProps: {
  209. maxLength: 100,
  210. format: 'YYYY-MM-DD',
  211. valueFormat: 'YYYY-MM-DD',
  212. showTime: true,
  213. },
  214. colProps: {
  215. xl: 8,
  216. xxl: 8,
  217. },
  218. },
  219. {
  220. field: 'title',
  221. label: '案例标题',
  222. component: 'Input',
  223. colProps: {
  224. xl: 5,
  225. xxl: 5,
  226. },
  227. },
  228. {
  229. field: 'typeId',
  230. label: '类型',
  231. component: 'Select',
  232. componentProps: {
  233. placeholder: '请选择类型',
  234. options: [
  235. {
  236. label: '智慧城市',
  237. value: 'smartCity',
  238. key: 'smartCity',
  239. },
  240. {
  241. label: '博物馆',
  242. value: 'museum',
  243. key: 'museum',
  244. },
  245. {
  246. label: '刑侦消防',
  247. value: 'government',
  248. key: 'government',
  249. },
  250. {
  251. label: '房产营销',
  252. value: 'property',
  253. key: 'property',
  254. },
  255. ],
  256. },
  257. colProps: {
  258. xl: 5,
  259. xxl: 5,
  260. },
  261. },
  262. ],
  263. };
  264. const [registerTable, { reload }] = useTable({
  265. api: caseListApi,
  266. title: '案例列表',
  267. columns: columns,
  268. useSearchForm: true,
  269. formConfig: searchForm,
  270. showTableSetting: true,
  271. showIndexColumn: false,
  272. searchInfo: { language },
  273. rowKey: 'id',
  274. fetchSetting: {
  275. pageField: 'pageNum',
  276. sizeField: 'pageSize',
  277. listField: 'list',
  278. totalField: 'total',
  279. },
  280. beforeFetch: (T) => {
  281. if (T.ctivated) {
  282. T.publicTimeStart = T.ctivated[0];
  283. T.publicTimeEnd = T.ctivated[1];
  284. }
  285. return T;
  286. },
  287. actionColumn: {
  288. width: 230,
  289. title: '操作',
  290. dataIndex: 'action',
  291. slots: { customRender: 'action' },
  292. },
  293. canResize: true,
  294. });
  295. async function handleDelete(record: Recordable) {
  296. await caseDelApi({ id: record.id });
  297. createMessage.success(t('common.optSuccess'));
  298. reload();
  299. }
  300. async function handlePublish(record: Recordable) {
  301. console.log('点击了发布', record);
  302. await casePublicApi({ id: record.id, isPublic: 1 });
  303. createMessage.success(t('common.optSuccess'));
  304. reload();
  305. }
  306. function handleEdit(record: Recordable) {
  307. console.log('点击了编辑', record);
  308. openModal(true, { ...record, language });
  309. }
  310. function handlePreview(record: Recordable) {
  311. const host = userStore.isEnv;
  312. console.log('host', host);
  313. if(record.outsideLink){
  314. return window.open(record.outsideLink, '_blank');
  315. }
  316. let url =
  317. window.location.host == 'www.4dkankan.com'
  318. ? `https://www.4dkankan.com/#/cases/detail/${record.id}`
  319. : `https://test.4dkankan.com/#/cases/detail/${record.id}`;
  320. if (host) {
  321. url = window.location.host.includes('test')
  322. ? `https://testeur.4dkankan.com/#/cases/detail/${record.id}`
  323. : `https://eur.4dkankan.com/#/cases/detail/${record.id}`;
  324. }
  325. window.open(url, '_blank');
  326. }
  327. async function handleWithdraw(record: Recordable) {
  328. await casePublicApi({ id: record.id, isPublic: 0 });
  329. createMessage.success(t('common.optSuccess'));
  330. reload();
  331. }
  332. function changeTable(val: string) {
  333. language.value = val;
  334. reload();
  335. }
  336. function hendleAddNew() {
  337. console.log('新增新闻');
  338. }
  339. return {
  340. registerTable,
  341. handleDelete,
  342. handleEdit,
  343. handleWithdraw,
  344. handlePublish,
  345. hendleAddNew,
  346. changeTable,
  347. reload,
  348. language,
  349. register,
  350. openModal,
  351. getCheckPerm,
  352. handlePreview,
  353. };
  354. },
  355. });
  356. </script>