From 50a9aae3d56d0e6de70541b6be414f170501802b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=9E=E4=B8=9C=E6=9E=97?= Date: Thu, 9 Dec 2021 09:57:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=AF=94=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- .../statistic/inner/component/comparison.vue | 42 ++++++++++++++++--- .../special/component/comparison.vue | 42 ++++++++++++++++--- 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/.env b/.env index b7bd75e..89cca9a 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ VUE_APP_VERSION=1.0.0 VUE_APP_NAME=生态环境监测数据综合分析平台 -VUE_APP_API_BASE_URL=http://1.14.132.108:10002/api +VUE_APP_API_BASE_URL=http://101.132.173.65:10001/api diff --git a/src/views/water/lake/statistic/inner/component/comparison.vue b/src/views/water/lake/statistic/inner/component/comparison.vue index 56e87b9..b328004 100644 --- a/src/views/water/lake/statistic/inner/component/comparison.vue +++ b/src/views/water/lake/statistic/inner/component/comparison.vue @@ -90,6 +90,8 @@ export default { // ], // }, ], + //扁平化表头,用于导出的数据组装 + sColumns:[], palceOptions: [], areaOptions: [], regionLevelOptions: [], @@ -136,7 +138,7 @@ export default { filterData(data){ let filterData = [] let addCloumns = [] - + let addSCloumns = [] if(Array.isArray(data)){ data.forEach((item,index)=>{ @@ -155,10 +157,17 @@ export default { if(i==0 && index==0){ - addCloumns[index] = {} + addCloumns[index] = {} addCloumns[index].title = single.year addCloumns[index].align = 'center' + addSCloumns = [ + {dataIndex: `waterType${i}`}, + { dataIndex: `comprehensiveNutrition${i}`}, + {dataIndex: `level${i}`}, + {dataIndex: `overflow${i}`} + ] + addCloumns[index].children = [ { title: "水质类别", dataIndex: `waterType${i}`, sorter: true,align:'center' }, { title: "综合营养状态指数", dataIndex: `comprehensiveNutrition${i}`, sorter: true,align:'center' }, @@ -182,6 +191,11 @@ export default { { title: "点位名称", dataIndex: "pointName", sorter: true}, ...addCloumns ] + this.sColumns = [ + {dataIndex: "type"}, + {dataIndex: "pointName"}, + ...addSCloumns + ] this.datasource = filterData; }, @@ -203,10 +217,28 @@ export default { exportFile() { const columns = this.columns; const arr = []; - const th = columns.map((item) => item.title); - arr.push(th); + // const th = columns.map((item) => item.title); + // arr.push(th); + + let th1 = [] + let th2 = [] + columns.forEach(item=>{ + th1.push(item.title) + + if(Array.isArray(item.children) && item.children.length>0){ + item.children.forEach(single=>{ + th1.push('') + th2.push(single.title) + }) + }else{ + th2.push('') + } + }) + + arr.push(th1) + arr.push(th2) this.data.forEach((d) => { - const td = columns.map((item) => d[item.dataIndex]); + const td = this.sColumns.map((item) => d[item.dataIndex]); arr.push(td); }); let sheet = XLSX.utils.aoa_to_sheet(arr); diff --git a/src/views/water/lake/statistic/special/component/comparison.vue b/src/views/water/lake/statistic/special/component/comparison.vue index 0cb7680..b336b93 100644 --- a/src/views/water/lake/statistic/special/component/comparison.vue +++ b/src/views/water/lake/statistic/special/component/comparison.vue @@ -90,6 +90,8 @@ export default { // ], // }, ], + //扁平化表头,用于导出的数据组装 + sColumns:[], palceOptions: [], areaOptions: [], regionLevelOptions: [], @@ -136,7 +138,7 @@ export default { filterData(data){ let filterData = [] let addCloumns = [] - + let addSCloumns = [] if(Array.isArray(data)){ data.forEach((item,index)=>{ @@ -155,10 +157,17 @@ export default { if(i==0 && index==0){ - addCloumns[index] = {} + addCloumns[index] = {} addCloumns[index].title = single.year addCloumns[index].align = 'center' + addSCloumns = [ + {dataIndex: `waterType${i}`}, + { dataIndex: `comprehensiveNutrition${i}`}, + {dataIndex: `level${i}`}, + {dataIndex: `overflow${i}`} + ] + addCloumns[index].children = [ { title: "水质类别", dataIndex: `waterType${i}`, sorter: true,align:'center' }, { title: "综合营养状态指数", dataIndex: `comprehensiveNutrition${i}`, sorter: true,align:'center' }, @@ -182,6 +191,11 @@ export default { { title: "点位名称", dataIndex: "pointName", sorter: true}, ...addCloumns ] + this.sColumns = [ + {dataIndex: "type"}, + {dataIndex: "pointName"}, + ...addSCloumns + ] this.datasource = filterData; }, @@ -203,10 +217,28 @@ export default { exportFile() { const columns = this.columns; const arr = []; - const th = columns.map((item) => item.title); - arr.push(th); + // const th = columns.map((item) => item.title); + // arr.push(th); + + let th1 = [] + let th2 = [] + columns.forEach(item=>{ + th1.push(item.title) + + if(Array.isArray(item.children) && item.children.length>0){ + item.children.forEach(single=>{ + th1.push('') + th2.push(single.title) + }) + }else{ + th2.push('') + } + }) + + arr.push(th1) + arr.push(th2) this.data.forEach((d) => { - const td = columns.map((item) => d[item.dataIndex]); + const td = this.sColumns.map((item) => d[item.dataIndex]); arr.push(td); }); let sheet = XLSX.utils.aoa_to_sheet(arr);