调整导出及表头

This commit is contained in:
庞东林
2021-12-20 15:22:11 +08:00
parent 8f933c841b
commit feedbe3031
9 changed files with 125 additions and 122 deletions

View File

@@ -147,34 +147,34 @@ export default {
// 筛选出年份
if(Array.isArray(item.data)){
item.data.forEach((single,i)=>{
filterData[index]['comprehensiveNutrition'+i] = single.comprehensiveNutrition;
filterData[index]['level'+i] = single.level;
filterData[index]['overflow'+i] = single.overflow;
filterData[index]['waterType'+i] = single.waterType;
filterData[index]['year'+i] = single.year;
item.data.forEach((single)=>{
// 生成格式化数据
filterData[index]['comprehensiveNutrition'+single.year] = single.comprehensiveNutrition;
filterData[index]['level'+single.year] = single.level;
filterData[index]['overflow'+single.year] = single.overflow;
filterData[index]['waterType'+single.year] = single.waterType;
filterData[index]['year'+single.year] = single.year;
if(i==0 && index==0){
addCloumns[index] = {}
addCloumns[index].title = single.year
addCloumns[index].align = 'center'
// 只拿第一条数据的年份做循环生成表头
if(index==0){
// 生成导出用的扁平化表头
addSCloumns = [...addSCloumns, {dataIndex: `waterType${single.year}`},
{ dataIndex: `comprehensiveNutrition${single.year}`},
{dataIndex: `level${single.year}`},
{dataIndex: `overflow${single.year}`}]
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' },
{ title: "级别", dataIndex: `level${i}`, sorter: true,align:'center' },
// 页面展示所需表头
addCloumns[single.year] = {}
addCloumns[single.year].title = single.year
addCloumns[single.year].align = 'center'
addCloumns[single.year].children = [
{ title: "水质类别", dataIndex: `waterType${single.year}`, sorter: true,align:'center' },
{ title: "综合营养状态指数", dataIndex: `comprehensiveNutrition${single.year}`, sorter: true,align:'center' },
{ title: "级别", dataIndex: `level${single.year}`, sorter: true,align:'center' },
{
title: "超标项目(超标倍数)",
align:'center',
dataIndex: `overflow${i}`,
dataIndex: `overflow${single.year}`,
sorter: true,
},
]
@@ -186,13 +186,13 @@ export default {
})
}
this.columns = [
{
key: 'index',
dataIndex: 'index',
width: 48,
align: 'center',
customRender: ({index}) => index + 1
},
// {
// key: 'index',
// dataIndex: 'index',
// width: 48,
// align: 'center',
// customRender: ({index}) => index + 1
// },
{ title: "类别", dataIndex: "type", sorter: true },
{ title: "点位名称", dataIndex: "pointName", sorter: true},
...addCloumns
@@ -229,14 +229,15 @@ export default {
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('')
th1.push(item.title)
th2.push(single.title)
})
}else{
th1.push(item.title)
th2.push('')
}
})
@@ -249,7 +250,7 @@ export default {
});
let sheet = XLSX.utils.aoa_to_sheet(arr);
this.$util.exportSheet(XLSX, sheet, new Date().getTime().toString());
},
}
},
};
</script>