From c1cc6b48d8a2fff9ec3c4e0e6602e17004644b39 Mon Sep 17 00:00:00 2001 From: Bujidao <3317431882@qq.com> Date: Thu, 5 Mar 2026 18:20:06 +0800 Subject: [PATCH] feat(codegen-vue3): add excel import flow to generated list template --- yudao-module-infra/src/main/resources/codegen/vue3/api/api.ts.vm | 10 ++++++++++ yudao-module-infra/src/main/resources/codegen/vue3/views/index.vue.vm | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/yudao-module-infra/src/main/resources/codegen/vue3/api/api.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3/api/api.ts.vm index c9f7361..aeade85 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3/api/api.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3/api/api.ts.vm @@ -98,6 +98,16 @@ export const ${simpleClassName}Api = { export${simpleClassName}: async (params) => { return await request.download({ url: `${baseURL}/export-excel`, params }) }, + + // 下载${table.classComment}导入模板 + import${simpleClassName}Template: async () => { + return await request.download({ url: `${baseURL}/get-import-template` }) + }, + + // 导入${table.classComment} + import${simpleClassName}: async (data: FormData) => { + return await request.upload({ url: `${baseURL}/import`, data }) + }, ## 特殊:主子表专属逻辑 #foreach ($subTable in $subTables) #set ($index = $foreach.count - 1) diff --git a/yudao-module-infra/src/main/resources/codegen/vue3/views/index.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue3/views/index.vue.vm index 857972a..c722f4c 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3/views/index.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3/views/index.vue.vm @@ -93,6 +93,14 @@ 新增 + 导入 + + + + + + + 将文件拖到此处,或点击上传 + + + 仅允许导入 xls、xlsx 格式文件。 + + 下载模板 + + + + + + + 确 定 + + 取 消 + + + <${simpleClassName}Form ref="formRef" @success="getList" /> ## 特殊:主子表专属逻辑 @@ -263,6 +308,7 @@ import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' import { isEmpty } from '@/utils/is' import { dateFormatter } from '@/utils/formatTime' +import type { UploadUserFile } from 'element-plus' ## 特殊:树表专属逻辑 #if ( $table.templateType == 2 ) import { handleTree } from '@/utils/tree' @@ -308,6 +354,10 @@ const queryParams = reactive({ }) const queryFormRef = ref() // 搜索的表单 const exportLoading = ref(false) // 导出的加载中 +const importDialogVisible = ref(false) // 导入弹窗 +const importFormLoading = ref(false) // 导入的加载中 +const uploadRef = ref() +const fileList = ref([]) /** 查询列表 */ const getList = async () => { @@ -345,6 +395,58 @@ const openForm = (type: string, id?: number) => { formRef.value.open(type, id) } +/** 导入按钮操作 */ +const handleImport = async () => { + importDialogVisible.value = true + await resetImportForm() +} + +/** 提交导入 */ +const submitImportForm = async () => { + if (fileList.value.length === 0) { + message.error('请上传文件') + return + } + importFormLoading.value = true + try { + const formData = new FormData() + formData.append('file', fileList.value[0].raw as Blob) + const res = await ${simpleClassName}Api.import${simpleClassName}(formData) + const data = res.data + let text = '导入成功数量:' + data.successCount + ';导入失败数量:' + data.failureCount + ';' + if (data.failureCount > 0) { + for (const rowNo in data.failureRows) { + text += '< 第' + rowNo + '行: ' + data.failureRows[rowNo] + ' >' + } + } + message.alert(text) + importDialogVisible.value = false + await getList() + } catch { + } finally { + importFormLoading.value = false + await resetImportForm() + } +} + +/** 下载导入模板 */ +const handleImportTemplate = async () => { + const data = await ${simpleClassName}Api.import${simpleClassName}Template() + download.excel(data, '${table.classComment}导入模板.xls') +} + +/** 导入文件超限 */ +const handleImportExceed = (): void => { + message.error('最多只能上传一个文件!') +} + +/** 重置导入表单 */ +const resetImportForm = async () => { + fileList.value = [] + await nextTick() + uploadRef.value?.clearFiles() +} + /** 删除按钮操作 */ const handleDelete = async (id: number) => { try { @@ -421,4 +523,4 @@ const toggleExpandAll = async () => { onMounted(() => { getList() }) - \ No newline at end of file + -- libgit2 0.21.4