一维表转二维表完成

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,

View File

@@ -54,7 +54,13 @@
</div>
<div class="layout-config__group" v-else>
<h2>基础设置</h2>
<datasource-picker :options="options" :instance="instance" @input="v=>$emit('change',v)"/>
<datasource-picker :options="options" :instance="instance" @input="$emit('change',options)"/>
</div>
<div class="layout-config__group" v-if="isTable">
<h2>表格设置</h2>
<code-editor v-model="json" theme="github" width="100%" height="440"
placeholder="参照dvScrollBoard设置表格"
@change="v=>options.tableConfig=JSON.parse(v)"/>
</div>
<div v-if="options.dataType!='staticData'&&options.type=='monitor'&&['cmcc','slw'].includes(options.monitorType)"
class="layout-config__group">
@@ -154,11 +160,12 @@ export default {
list: [],
showMapEditor: false,
form: {},
datasource:{}
datasource: {}
}
},
computed: {
markers: v => v.options.staticData?.markers || [],
isTable: v => v.options.type == 'table'
},
components: {
DatasourcePicker,
@@ -173,6 +180,8 @@ export default {
const values = this.$copy(this.options)
values.staticData = {markers: this.$copy(this.options.staticData)}
this.$emit("change", values)
} else if (this.isTable) {
this.json = JSON.stringify(this.options.tableConfig)
}
},
mounted() {

View File

@@ -53,7 +53,6 @@ export default {
dataLang: v => v.options.dataType == 'htmlData' ? 'html' : 'json',
source: {
set(v) {
console.log(v)
this.$emit("input", v)
},
get() {