Commit 7b002171 authored by 何远江's avatar 何远江

修改excel解析结果字段显示顺序

parent e260bef9
...@@ -134,6 +134,7 @@ ...@@ -134,6 +134,7 @@
ref="runDataTable" ref="runDataTable"
size="mini" size="mini"
show-overflow="tooltip" show-overflow="tooltip"
show-header-overflow="tooltip"
:data="runResultData" :data="runResultData"
border border
:expand-config="expandConfig" :expand-config="expandConfig"
...@@ -144,19 +145,40 @@ ...@@ -144,19 +145,40 @@
<template #content="{ row, rowIndex }"> <template #content="{ row, rowIndex }">
<div style="padding: 10px"> <div style="padding: 10px">
<template v-for="attchName of filterObjKeys(row.expendData)"> <template v-for="attchName of filterObjKeys(row.expendData)">
<el-descriptions <p>{{ attchName }}</p>
direction="vertical" <vxe-table
:data="row.expendData[attchName]"
header-row-class-name="expandTableHeader"
min-height="72"
height="72"
size="mini"
show-overflow="tooltip"
show-header-overflow="tooltip"
style="width: 70vw;"
border border
:column="filterObjKeys(row.expendData[attchName]).length"
size="small"
:title="attchName"
> >
<el-descriptions-item <vxe-column
v-for="pro in filterObjKeys(row.expendData[attchName])" v-for="key in filterObjKeys(row.expendData[attchName][0])"
:label="pro" :title="key"
>{{ row.expendData[attchName][pro] }}</el-descriptions-item :field="key"
width="140"
></vxe-column>
</vxe-table>
<!-- <el-scrollbar>
<el-descriptions
direction="vertical"
border
:column="filterObjKeys(row.expendData[attchName]).length"
size="small"
:title="attchName"
> >
</el-descriptions> <el-descriptions-item
v-for="pro in filterObjKeys(row.expendData[attchName])"
:label="pro"
>{{ row.expendData[attchName][pro] }}</el-descriptions-item
>
</el-descriptions>
</el-scrollbar> -->
</template> </template>
</div> </div>
</template> </template>
...@@ -618,8 +640,8 @@ const setSheetAreaMark = (sheet: any) => { ...@@ -618,8 +640,8 @@ const setSheetAreaMark = (sheet: any) => {
} }
} }
const runResultData = ref([]) const runResultData = ref<any[]>([])
const runResultTitle = ref([]) const runResultTitle = ref<any[]>([])
const runResultVisible = ref(false) const runResultVisible = ref(false)
const toRun = async () => { const toRun = async () => {
const loadingInstance = ElLoading.service({ const loadingInstance = ElLoading.service({
...@@ -639,19 +661,14 @@ const toRun = async () => { ...@@ -639,19 +661,14 @@ const toRun = async () => {
if (!data.result.length) return if (!data.result.length) return
const tableData: any[] = [] const { res, titles } = filterTableData(data.result)
data.result.forEach((item: any) => {
tableData.push(filterTableData(item))
})
runResultData.value = tableData runResultData.value = res
runResultTitle.value = filterRunDataTitle(tableData).filter((field) => { runResultTitle.value = titles.filter((field) => {
return field != 'sortNum' && field != '数据区' && field != 'expendData' return field != 'sortNum' && field != '数据区' && field != 'expendData'
}) })
// const idx = runResultTitle.value.findIndex((v) => v == 'sortNum')
// runResultTitle.value.splice(idx, 1)
runResultVisible.value = true runResultVisible.value = true
console.log('runResultData.value', runResultData.value)
} catch { } catch {
nextTick(() => { nextTick(() => {
// Loading should be closed asynchronously // Loading should be closed asynchronously
...@@ -660,39 +677,44 @@ const toRun = async () => { ...@@ -660,39 +677,44 @@ const toRun = async () => {
} }
} }
const filterTableData = (row: any) => { const filterTableData = (data: any[]) => {
const res: Recordable = {} const res: Recordable[] = []
row.order.forEach((itm) => { const titles: string[] = []
res[itm.title] = itm.value data.forEach((row) => {
}) const rw = {}
// 是否有附加信息 row.order.forEach((itm) => {
if (row?.groups?.length) { Reflect.set(rw, itm.title, itm.value)
res['expendData'] = {} if (!titles.includes(itm.title)) {
row.groups.forEach((itm) => { titles.push(itm.title)
res['expendData'][itm.title] = {} }
itm.item.forEach((v) => {
res['expendData'][itm.title][v.title] = v.value
})
}) })
} // 是否有附加信息
if (row?.groups?.length) {
Reflect.set(rw, 'expendData', {})
row.groups.forEach((itm) => {
rw['expendData'][itm.title] = []
const r = {}
itm.item.forEach((v) => {
r[v.title] = v.value
})
rw['expendData'][itm.title].push(r)
})
}
return res res.push(rw)
} })
const filterRunDataTitle = (data: any) => { return {
const titles = [] res,
for (const row of data) { titles
titles.push(...Object.keys(row))
} }
return Array.from(new Set(titles))
} }
const filterObjKeys = (data: any) => { const filterObjKeys = (data: any) => {
return Object.keys(data) return Object.keys(data).filter((v) => v !== '_X_ROW_KEY')
} }
const expandConfig = reactive({ const expandConfig = reactive({
visibleMethod({ row }) { visibleMethod({ row }) {
console.log('row', row)
if (typeof row.expendData === 'object') { if (typeof row.expendData === 'object') {
return true return true
} }
...@@ -721,4 +743,7 @@ onUnmounted(() => { ...@@ -721,4 +743,7 @@ onUnmounted(() => {
width: 8em; width: 8em;
} }
} }
.expandTableHeader {
background: #ccc;
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment