潘志宝
2024-11-12 1337f249608bcbd7ad6cf244870e560a95821727
提交 | 用户 | 时间
e7c126 1 <script lang="ts" setup>
H 2 import ${simpleClassName}Modal from './${simpleClassName}Modal.vue'
3 import { columns, searchFormSchema } from './${classNameVar}.data'
4 import { useI18n } from '@/hooks/web/useI18n'
5 import { useMessage } from '@/hooks/web/useMessage'
6 import { useModal } from '@/components/Modal'
7 import { useTable } from '@/components/Table'
8 import { delete${simpleClassName}, export${simpleClassName}, get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
9
10 defineOptions({ name: '${table.className}' })
11
12 const { t } = useI18n()
13 const { createConfirm, createMessage } = useMessage()
14 const [registerModal, { openModal }] = useModal()
15
16 const [registerTable, { getForm, reload }] = useTable({
17   title: '${table.classComment}列表',
18   api: get${simpleClassName}Page,
19     columns,
20     formConfig: { labelWidth: 120, schemas: searchFormSchema },
21     useSearchForm: true,
22     showTableSetting: true,
23     actionColumn: {
24       width: 140,
25       title: t('common.action'),
26       dataIndex: 'action',
27       fixed: 'right',
28     },
29 })
30
31 function handleCreate() {
32   openModal(true, { isUpdate: false })
33 }
34
35 function handleEdit(record: Recordable) {
36   openModal(true, { record, isUpdate: true })
37 }
38
39 async function handleExport() {
40   createConfirm({
41     title: t('common.exportTitle'),
42     iconType: 'warning',
43     content: t('common.exportMessage'),
44     async onOk() {
45       await export${simpleClassName}(getForm().getFieldsValue())
46       createMessage.success(t('common.exportSuccessText'))
47     },
48   })
49 }
50
51 async function handleDelete(record: Recordable) {
52   await delete${simpleClassName}(record.id)
53   createMessage.success(t('common.delSuccessText'))
54   reload()
55 }
56 </script>
57 <template>
58   <div>
59     <BasicTable @register="registerTable">
60       <template #toolbar>
61         <a-button type="primary" v-auth="['${permissionPrefix}:create']" :preIcon="IconEnum.ADD" @click="handleCreate">
62           {{ t('action.create') }}
63         </a-button>
64         <a-button v-auth="['${permissionPrefix}:export']" :preIcon="IconEnum.EXPORT" @click="handleExport">
65           {{ t('action.export') }}
66         </a-button>
67       </template>
68       <template #bodyCell="{ column, record }">
69         <template v-if="column.key === 'action'">
70           <TableAction
71             :actions="[
72               { icon: IconEnum.EDIT, label: t('action.edit'), auth: '${permissionPrefix}:update', onClick: handleEdit.bind(null, record) },
73               {
74                 icon: IconEnum.DELETE,
75                 danger: true,
76                 label: t('action.delete'),
77                 auth: '${permissionPrefix}:delete',
78                 popConfirm: {
79                   title: t('common.delMessage'),
80                   placement: 'left',
81                   confirm: handleDelete.bind(null, record),
82                 },
83               },
84             ]"
85           />
86         </template>
87       </template>
88     </BasicTable>
89     <${simpleClassName}Modal @register="registerModal" @success="reload()" />
90   </div>
91 </template>