一维表转二维表完成

This commit is contained in:
aixianling
2023-10-09 19:11:01 +08:00
parent 1b2348ef73
commit e129575479
3 changed files with 33 additions and 7 deletions

View File

@@ -126,12 +126,33 @@ export default {
},
methods: {
formatTable(data, isShowIndex, rowNum) {
const tableStyle = {
headerBGC: 'transparent',
evenRowBGC: 'transparent',
oddRowBGC: 'rgba(0, 133, 255, 0.2)',
headerHeight: 42,
align: 'center'
}
if (!data.length) {
return {
header: [],
data: []
}
}
if (this.data.tableConfig) {
const {x, y} = this.data.tableConfig, dataMap = {}
const header = [...new Set(Object.entries(data.find(e => e.row == x) || null)?.filter(e => e[0] != 'row').map(e => e[1]) || [])],
rows = [...new Set(Object.entries(data.find(e => e.row == y) || null)?.filter(e => e[0] != 'row').map(e => e[1]) || [])]
data.map(e => Object.keys(e).map(k => k != 'row' && (dataMap[k] = (dataMap[k] || "") + "#" + e[k])))
const tableData = Object.values(dataMap).map(e => e.split("#"))
return {
...tableStyle,
header: ["", ...header],
data: rows.map(y => [y, ...header.map(x => {
return tableData.find(m => m.includes(x) && m.includes(y)).at(-1)
})])
}
}
let rows = []
const header = data.map(v => {
return v[Object.keys(v)[0]]
@@ -148,10 +169,7 @@ export default {
return v[item]
})
}),
headerBGC: 'transparent',
evenRowBGC: 'transparent',
oddRowBGC: 'rgba(0, 133, 255, 0.2)',
headerHeight: 42,
...tableStyle,
rowNum: rowNum || 7,
index: isShowIndex === '1',
waitTime: 8000,