From ec0758af0730fb95548198fef3fac3946773b7a1 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Fri, 8 Jul 2022 10:48:19 +0800 Subject: [PATCH] set config --- src/store/modules/dashboard.ts | 19 ++++++++++--------- .../configuration/widget/AssociateOptions.vue | 13 ++++++++++++- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index a57e61a2..9809221f 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -279,22 +279,23 @@ export const dashboardStore = defineStore({ this.selectedGrid = this.layout[index]; }, setWidget(param: LayoutConfig) { - for (let item of this.layout) { - if (item.type === "Tab") { - if (item.children && item.children.length) { - for (const child of item.children) { + for (let i = 0; i < this.layout.length; i++) { + if (this.layout[i].type === "Tab") { + if (this.layout[i].children && this.layout[i].children.length) { + for (const child of this.layout[i].children) { if (child.children && child.children.length) { - for (let c of child.children) { - if (c.id === param.id) { - c = param; + for (let c = 0; c < child.children.length; c++) { + if (child.children[c].id === param.id) { + child.children.splice(c, 1, param); + return; } } } } } } else { - if (item.id === param.id) { - item = param; + if (this.layout[i].id === param.id) { + this.layout.splice(i, 1, param); } } } diff --git a/src/views/dashboard/configuration/widget/AssociateOptions.vue b/src/views/dashboard/configuration/widget/AssociateOptions.vue index b9f6d690..7a5685b7 100644 --- a/src/views/dashboard/configuration/widget/AssociateOptions.vue +++ b/src/views/dashboard/configuration/widget/AssociateOptions.vue @@ -51,7 +51,7 @@ const widgets = computed(() => { const items = widgets.filter( (d: { value: string; label: string } & LayoutConfig) => { if (dashboardStore.selectedGrid.id !== d.id) { - if (isLinear && d.widget && d.id) { + if (isLinear && d.type === "Widget" && d.widget && d.id) { d.value = d.id; d.label = d.widget.name || d.id; return d; @@ -67,6 +67,7 @@ const widgets = computed(() => { return items; }); function updateWidgetConfig(options: Option[]) { + const { widgets } = getDashboard(dashboardStore.currentDashboard); const opt = options.map((d: Option) => { return { widgetId: d.value }; }); @@ -75,6 +76,16 @@ function updateWidgetConfig(options: Option[]) { associate: opt, }; dashboardStore.selectWidget({ ...widget }); + for (let i = 0; i < opt.length; i++) { + const item = JSON.parse(JSON.stringify(opt)); + item[i] = { widgetId: dashboardStore.selectedGrid.id }; + const w = widgets.find((d: { id: string }) => d.id === opt[i].widgetId); + const config = { + ...w, + associate: item, + }; + dashboardStore.setWidget(config); + } }