diff --git a/yudao-module-infra/src/main/resources/codegen/vue/api/api.js.vm b/yudao-module-infra/src/main/resources/codegen/vue/api/api.js.vm index 0d9b66f..80be3f4 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue/api/api.js.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue/api/api.js.vm @@ -73,6 +73,24 @@ export function export${simpleClassName}Excel(params) { responseType: 'blob' }) } + +// 下载${table.classComment}导入模板 +export function import${simpleClassName}Template() { + return request({ + url: '${baseURL}/get-import-template', + method: 'get', + responseType: 'blob' + }) +} + +// 导入${table.classComment} +export function import${simpleClassName}(data) { + return request({ + url: '${baseURL}/import', + method: 'post', + data + }) +} ## 特殊:主子表专属逻辑 #foreach ($subTable in $subTables) #set ($index = $foreach.count - 1) @@ -157,4 +175,4 @@ export function export${simpleClassName}Excel(params) { }) } #end -#end \ No newline at end of file +#end diff --git a/yudao-module-infra/src/main/resources/codegen/vue/views/index.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue/views/index.vue.vm index bbc9131..0f0cd9a 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue/views/index.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue/views/index.vue.vm @@ -50,6 +50,14 @@ v-hasPermi="['${permissionPrefix}:create']">新增 + 导入 + + + 导入模板 + + 导出 @@ -78,6 +86,7 @@ #end + ## 特殊:主子表专属逻辑 #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) @@ -244,6 +253,8 @@ export default { loading: true, // 导出遮罩层 exportLoading: false, + // 导入遮罩层 + importLoading: false, // 显示搜索条件 showSearch: true, ## 特殊:树表专属逻辑(树不需要分页接口) @@ -322,6 +333,42 @@ export default { openForm(id) { this.#[[$]]#refs["formRef"].open(id); }, + /** 导入按钮操作 */ + handleImport() { + this.$refs.importFileRef && this.$refs.importFileRef.click(); + }, + /** 导入模板下载 */ + async handleImportTemplate() { + const data = await ${simpleClassName}Api.import${simpleClassName}Template(); + this.#[[$]]#download.excel(data, '${table.classComment}导入模板.xls'); + }, + /** 导入文件变更 */ + async handleImportFileChange(event) { + const target = event.target; + const file = target.files && target.files[0]; + if (!file) { + return; + } + this.importLoading = true; + try { + const formData = new FormData(); + formData.append('file', file); + const res = await ${simpleClassName}Api.import${simpleClassName}(formData); + const data = res.data || res; + let text = '导入成功数量:' + (data.successCount || 0) + ';导入失败数量:' + (data.failureCount || 0) + ';'; + if (data.failureRows) { + Object.keys(data.failureRows).forEach((rowNo) => { + text += '< 第' + rowNo + '行: ' + data.failureRows[rowNo] + ' >'; + }); + } + await this.$alert(text, '${table.classComment}导入结果', { dangerouslyUseHTMLString: true }); + await this.getList(); + } catch { + } finally { + target.value = ''; + this.importLoading = false; + } + }, /** 删除按钮操作 */ async handleDelete(row) { const ${primaryColumn.javaField} = row.${primaryColumn.javaField}; diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben/api/api.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben/api/api.ts.vm index b7f2651..3a46bcb 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben/api/api.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben/api/api.ts.vm @@ -30,3 +30,13 @@ export function delete${simpleClassName}(id: number) { export function export${simpleClassName}(params) { return defHttp.download({ url: '${baseURL}/export-excel', params }, '${table.classComment}.xls') } + +// 下载${table.classComment}导入模板 +export function import${simpleClassName}Template() { + return defHttp.download({ url: '${baseURL}/get-import-template' }, '${table.classComment}导入模板.xls') +} + +// 导入${table.classComment} +export function import${simpleClassName}(data: FormData) { + return defHttp.post({ url: '${baseURL}/import', data }) +} diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben/views/index.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben/views/index.vue.vm index 9e59b12..6fa5c7c 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben/views/index.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben/views/index.vue.vm @@ -1,18 +1,27 @@