diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 410df5d0..a0f0147c 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -76,9 +76,10 @@ export const dashboardStore = defineStore({ this.currentDashboard = item; }, addControl(type: string) { + const arr = this.layout.map((d: any) => Number(d.i)); const newItem: LayoutConfig = { ...NewControl, - i: String(this.layout.length), + i: String(Math.max(...arr) + 1), type, metricTypes: [""], metrics: [""], @@ -146,9 +147,10 @@ export const dashboardStore = defineStore({ } const tabIndex = this.layout[idx].activedTabIndex || 0; const { children } = this.layout[idx].children[tabIndex]; + const arr = children.map((d: any) => Number(d.i)); const newItem: LayoutConfig = { ...NewControl, - i: String(children.length), + i: String(Math.max(...arr) + 1), type, metricTypes: [""], metrics: [""], diff --git a/src/views/dashboard/configuration/Widget.vue b/src/views/dashboard/configuration/Widget.vue index 67f6949e..f10981b7 100644 --- a/src/views/dashboard/configuration/Widget.vue +++ b/src/views/dashboard/configuration/Widget.vue @@ -17,9 +17,6 @@ limitations under the License. -->
{{ dashboardStore.selectedGrid.widget.title }} - - ({{ dashboardStore.selectedGrid.standard.unit }}) -
diff --git a/src/views/dashboard/configuration/widget/metric/Index.vue b/src/views/dashboard/configuration/widget/metric/Index.vue index c0d9f5e7..197a7f76 100644 --- a/src/views/dashboard/configuration/widget/metric/Index.vue +++ b/src/views/dashboard/configuration/widget/metric/Index.vue @@ -159,8 +159,8 @@ states.visTypes = setVisTypes(); setDashboards(); setMetricType(); -async function setMetricType() { - const { graph } = dashboardStore.selectedGrid; +async function setMetricType(chart?: any) { + const graph = chart || dashboardStore.selectedGrid.graph; const json = await dashboardStore.fetchMetricList(); if (json.errors) { ElMessage.error(json.errors); @@ -203,6 +203,7 @@ async function setMetricType() { ...dashboardStore.selectedGrid, metrics: states.metrics, metricTypes: states.metricTypes, + graph, }); states.metricTypeList = []; for (const metric of metrics) { @@ -266,7 +267,6 @@ function setVisTypes() { function changeChartType(item: Option) { const graph = DefaultGraphConfig[item.value]; - dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, graph }); states.isList = ListChartTypes.includes(graph.type); if (states.isList) { dashboardStore.selectWidget({ @@ -278,7 +278,7 @@ function changeChartType(item: Option) { states.metricTypes = [""]; defaultLen.value = 5; } - setMetricType(); + setMetricType(graph); setDashboards(); states.dashboardName = ""; defaultLen.value = 10; diff --git a/src/views/dashboard/configuration/widget/metric/Standard.vue b/src/views/dashboard/configuration/widget/metric/Standard.vue index d0a2ff5f..499fd59a 100644 --- a/src/views/dashboard/configuration/widget/metric/Standard.vue +++ b/src/views/dashboard/configuration/widget/metric/Standard.vue @@ -71,7 +71,7 @@ limitations under the License. -->