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)