From 13b779ff3e49d3598484702d780b56afbbf02ab8 Mon Sep 17 00:00:00 2001 From: aixianling Date: Wed, 28 Feb 2024 15:08:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=97=B6,=E6=95=B0=E6=8D=AE=E7=9A=84=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=95=B0=E6=8D=AE=E4=B8=8D=E6=9B=B4=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/components/datasourcePicker.vue | 74 +++++++++---------- .../designer/components/tableEditor.vue | 9 +-- packages/bigscreen/designer/viewport.vue | 4 +- 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/packages/bigscreen/designer/components/datasourcePicker.vue b/packages/bigscreen/designer/components/datasourcePicker.vue index 07700da9..6c7d88ba 100644 --- a/packages/bigscreen/designer/components/datasourcePicker.vue +++ b/packages/bigscreen/designer/components/datasourcePicker.vue @@ -11,7 +11,7 @@ ({id: e[0], label: e[1]})), content: "", loading: false, - tableData: [], - colConfigs: [] } }, computed: { @@ -64,6 +62,40 @@ export default { get() { return this.options } + }, + staticDataOps() { + const columnProp = "name", ops = {colConfigs: [], tableData: []} + if (Array.isArray(this.options.staticData)) { + const columns = [] + ops.colConfigs = [] + this.options.staticData.map((row, i) => { + const prop = `c${i || ""}` + ops.colConfigs.push({label: row[columnProp] || row.key, prop}) + Object.entries(row).map(([k, v]) => { + console.log("梳理数据单元:", k, v) + if (/^v/.test(k) && k != "value") { + const item = ops.tableData[k.substring(1) || 0] || {} + item[prop] = v + ops.tableData[k.substring(1) || 0] = item + } else if (![columnProp, 'key'].includes(k)) { + const index = columns.findIndex(e => k == e) + if (index > -1) { + const item = ops.tableData[index] || {} + item[prop] = v + ops.tableData[index] = item + } else { + columns.push(k) + const newIndex = columns.length - 1 + const item = ops.tableData[newIndex] || {} + item[prop] = v + ops.tableData[newIndex] = item + } + } + }) + }) + ops.tableData = ops.tableData.map(e => ({...e, $cellEdit: false})) + } + return ops } }, methods: { @@ -72,43 +104,7 @@ export default { new DvCompData(this.source.dataType, this.source, this.instance).getData().then(data => { this.source[this.source.dataType] = data }) - }, - initStaticDataProps() { - const columnProp = "name" - if (Array.isArray(this.options.staticData)) { - const columns = [] - this.options.staticData.map((row, i) => { - const prop = `c${i || ""}` - this.colConfigs.push({label: row[columnProp] || row.key, prop}) - Object.entries(row).map(([k, v]) => { - if (/^v/.test(k)) { - const item = this.tableData[k.substring(1) || 0] || {} - item[prop] = v - this.tableData[k.substring(1) || 0] = item - } else if (![columnProp, 'key'].includes(k)) { - const index = columns.findIndex(e => k == e) - console.log(index) - if (index > -1) { - const item = this.tableData[index] || {} - item[prop] = v - this.tableData[index] = item - } else { - columns.push(k) - const newIndex = columns.length - 1 - const item = this.tableData[newIndex] || {} - item[prop] = v - this.tableData[newIndex] = item - } - } - }) - }) - this.tableData = this.tableData.map(e => ({...e, $cellEdit: false})) - } } - }, - created() { - //新版静态数据 - this.initStaticDataProps() } } diff --git a/packages/bigscreen/designer/components/tableEditor.vue b/packages/bigscreen/designer/components/tableEditor.vue index 4404616d..02df2374 100644 --- a/packages/bigscreen/designer/components/tableEditor.vue +++ b/packages/bigscreen/designer/components/tableEditor.vue @@ -15,7 +15,6 @@ export default { }, data() { return { - records: [], form: {} } }, @@ -44,7 +43,8 @@ export default { }) } }, - columns: v => v.configs + columns: v => v.configs, + records: v => v.tableData.map(e => ({$cellEdit: true, ...e})) }, methods: { rowSave(form, done) { @@ -74,16 +74,13 @@ export default { }) } }, - created() { - this.records = this.tableData.map(e => ({$cellEdit: true, ...e})) - } }