2026-06-25 a26b31cc9f3ee9b21b1a754e80fa7359e8a7a8f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<script lang="ts" setup>
import ${simpleClassName}Modal from './${simpleClassName}Modal.vue'
import { columns, searchFormSchema } from './${classNameVar}.data'
import { ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, TableAction, useTable } from '@/components/Table'
import {
  delete${simpleClassName},
  export${simpleClassName},
  get${simpleClassName}Page,
#if ($importEnable)
  import${simpleClassName},
  import${simpleClassName}Template,
#end
} from '@/api/${table.moduleName}/${table.businessName}'
 
defineOptions({ name: '${table.className}' })
 
const { t } = useI18n()
const { createConfirm, createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
#if ($importEnable)
const importFileRef = ref<HTMLInputElement>()
const importLoading = ref(false)
#end
 
const [registerTable, { getForm, reload }] = useTable({
  title: '${table.classComment}列表',
  api: get${simpleClassName}Page,
    columns,
    formConfig: { labelWidth: 120, schemas: searchFormSchema },
    useSearchForm: true,
    showTableSetting: true,
    actionColumn: {
      width: 140,
      title: t('common.action'),
      dataIndex: 'action',
      fixed: 'right',
    },
})
 
function handleCreate() {
  openModal(true, { isUpdate: false })
}
 
function handleEdit(record: Recordable) {
  openModal(true, { record, isUpdate: true })
}
 
async function handleExport() {
  createConfirm({
    title: t('common.exportTitle'),
    iconType: 'warning',
    content: t('common.exportMessage'),
    async onOk() {
      await export${simpleClassName}(getForm().getFieldsValue())
      createMessage.success(t('common.exportSuccessText'))
    },
  })
}
#if ($importEnable)
 
function handleImport() {
  importFileRef.value?.click()
}
 
async function handleImportTemplateDownload() {
  await import${simpleClassName}Template()
  createMessage.success('模板下载已开始')
}
 
async function handleImportFileChange(event: Event) {
  const target = event.target as HTMLInputElement
  const file = target.files?.[0]
  if (!file) {
    return
  }
  importLoading.value = true
  try {
    const formData = new FormData()
    formData.append('file', file)
    const response: any = await import${simpleClassName}(formData)
    const data = response?.data ?? response
    let text =
      '导入成功数量:' + (data?.successCount || 0) + ';导入失败数量:' + (data?.failureCount || 0) + ';'
    if (data?.failureRows) {
      Object.keys(data.failureRows).forEach((rowNo) => {
        text += '< 第' + rowNo + '行: ' + data.failureRows[rowNo] + ' >'
      })
    }
    createMessage.success(text)
    await reload()
  } finally {
    target.value = ''
    importLoading.value = false
  }
}
#end
 
async function handleDelete(record: Recordable) {
  await delete${simpleClassName}(record.id)
  createMessage.success(t('common.delSuccessText'))
  reload()
}
</script>
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" v-auth="['${permissionPrefix}:create']" :preIcon="IconEnum.ADD" @click="handleCreate">
          {{ t('action.create') }}
        </a-button>
#if ($importEnable)
        <a-button v-auth="['${permissionPrefix}:import']" :loading="importLoading" @click="handleImport">
          导入
        </a-button>
        <a-button v-auth="['${permissionPrefix}:import']" @click="handleImportTemplateDownload">
          导入模板
        </a-button>
#end
        <a-button v-auth="['${permissionPrefix}:export']" :preIcon="IconEnum.EXPORT" @click="handleExport">
          {{ t('action.export') }}
        </a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              { icon: IconEnum.EDIT, label: t('action.edit'), auth: '${permissionPrefix}:update', onClick: handleEdit.bind(null, record) },
              {
                icon: IconEnum.DELETE,
                danger: true,
                label: t('action.delete'),
                auth: '${permissionPrefix}:delete',
                popConfirm: {
                  title: t('common.delMessage'),
                  placement: 'left',
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
#if ($importEnable)
    <input ref="importFileRef" type="file" accept=".xls,.xlsx" class="hidden" @change="handleImportFileChange" />
#end
    <${simpleClassName}Modal @register="registerModal" @success="reload()" />
  </div>
</template>