对比数据导出
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user