From 53ff0d3d3f39e9e1eca840d474c8c9a478a39fda Mon Sep 17 00:00:00 2001
From: cshaptx4869 <994774638@qq.com>
Date: Mon, 17 Jun 2024 11:39:49 +0800
Subject: [PATCH] =?UTF-8?q?refactor(PageContent):=20:recycle:=20=E5=AF=BC?=
=?UTF-8?q?=E5=85=A5=E6=A8=A1=E6=9D=BF=E5=8F=82=E6=95=B0=E6=94=B9=E5=90=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/CURD/PageContent.vue | 14 +++++++-------
src/components/CURD/types.ts | 4 ++--
src/views/demo/curd/config/content.ts | 2 +-
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/components/CURD/PageContent.vue b/src/components/CURD/PageContent.vue
index 0d173cb6..90f04842 100644
--- a/src/components/CURD/PageContent.vue
+++ b/src/components/CURD/PageContent.vue
@@ -452,7 +452,7 @@
*.xlsx / *.xls
{
+ const importTemplate = props.contentConfig.importTemplate;
+ if (typeof importTemplate === "string") {
+ window.open(importTemplate);
+ } else if (typeof importTemplate === "function") {
+ importTemplate().then((response) => {
const fileData = response.data;
const fileName = decodeURI(
response.headers["content-disposition"].split(";")[1].split("=")[1]
@@ -742,7 +742,7 @@ function handleDownloadTemplate() {
saveXlsx(fileData, fileName);
});
} else {
- ElMessage.error("未配置importsTemplate");
+ ElMessage.error("未配置importTemplate");
}
}
// 导入确认
diff --git a/src/components/CURD/types.ts b/src/components/CURD/types.ts
index c2082033..af0cd7f9 100644
--- a/src/components/CURD/types.ts
+++ b/src/components/CURD/types.ts
@@ -92,10 +92,10 @@ export interface IContentConfig {
exportAction?: (queryParams: T) => Promise;
// 前端全量导出的网络请求函数(需返回promise)
exportsAction?: (queryParams: T) => Promise;
+ // 导入模板
+ importTemplate?: string | (() => Promise);
// 后端导入的网络请求函数(需返回promise)
importAction?: (file: File) => Promise;
- // 前端导入模板
- importsTemplate?: string | (() => Promise);
// 前端导入的网络请求函数(需返回promise)
importsAction?: (data: IObject[]) => Promise;
// 主键名(默认为id)
diff --git a/src/views/demo/curd/config/content.ts b/src/views/demo/curd/config/content.ts
index bda6a058..8a79fecb 100644
--- a/src/views/demo/curd/config/content.ts
+++ b/src/views/demo/curd/config/content.ts
@@ -29,7 +29,7 @@ const contentConfig: IContentConfig = {
return UserAPI.import(1, file);
},
exportAction: UserAPI.export,
- importsTemplate: UserAPI.downloadTemplate,
+ importTemplate: UserAPI.downloadTemplate,
importsAction(data) {
// 模拟导入数据
console.log("importsAction", data);