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})) - } }