From c8bd8fa2c4e7e1d1431e3273f7a20e90367f36c5 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sun, 2 Nov 2025 00:51:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20scTable=E4=BC=98=E5=8C=96=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/scTable/index.vue | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/components/scTable/index.vue b/src/components/scTable/index.vue index 00a5816f..2bb2462b 100644 --- a/src/components/scTable/index.vue +++ b/src/components/scTable/index.vue @@ -50,8 +50,8 @@
1导出本页数据
-
2导出本页数据
-
3导出全部数据
+
2导出本页数据
+
3导出全部数据
@@ -90,7 +90,7 @@ import config from "@/config/table"; import columnSetting from "./columnSetting"; import { genTree } from "@/utils/verificate"; -import { domToExcel } from "@/utils/exportExcel"; +import { domToExcel, dataToExcel } from "@/utils/exportExcel"; export default { name: "scTable", components: { @@ -124,7 +124,8 @@ export default { hideRefresh: { type: Boolean, default: false }, hideSetting: { type: Boolean, default: false }, hideExport: { type: Boolean, default: false }, - hExportExcel: { type: Function, default: null }, + hExportCols: { type: Array, default: null }, + hExportName: { type: String, default: null }, paginationLayout: { type: String, default: config.paginationLayout }, }, watch: { @@ -320,9 +321,20 @@ export default { } } else if (type === 1) { - this.hExportExcel(this.tableData); + dataToExcel(this.hExportCols, this.tableData, this.hExportName?this.hExportName:'表格数据') }else if (type === 2) { - var c = Object.assign({}, this.query, this.tableParams, {[this.orderStr]: this.order}, {page: 0}) + const extractHeaderKeys = (columns) =>{ + const keys = columns.map(item => { + // 如果key中包含点号,只取点号前面的部分 + return item.key.split('.')[0]; + }); + + // 去重并转回字符串 + return [...new Set(keys)].join(','); + } + var c = Object.assign({}, this.query, this.tableParams, {[this.orderStr]: this.order}, {page: 0}, + {query: "{" + extractHeaderKeys(this.hExportCols) + "}"} + ) let ElLoading = this.$loading({ lock: true, text: '数据请求中,请稍后...', @@ -330,7 +342,7 @@ export default { }) this.apiObj.req(c).then(res=>{ ElLoading.close(); - this.hExportExcel(res); + dataToExcel(this.hExportCols, res, this.hExportName?this.hExportName:'表格数据') }).catch(err=>{ ElLoading.close(); console.log(err)