diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 2ce3a815..2f2b44f2 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -24,7 +24,7 @@ import { useAppStoreWithOut } from "@/store/modules/app"; interface DashboardState { showConfig: boolean; layout: LayoutConfig[]; - selectedGrid: Nullable; + selectedGrid: Nullable; // edit widgets entity: string; layerId: string; activedGridItem: string; @@ -61,13 +61,14 @@ export const dashboardStore = defineStore({ return d; }); this.layout.push(newWidget); + this.activedGridItem = newWidget.i; }, addTab() { const newWidget: LayoutConfig = { x: 0, y: 0, w: 24, - h: 12, + h: 20, i: String(this.layout.length), type: "Tab", children: [ @@ -89,6 +90,7 @@ export const dashboardStore = defineStore({ return d; }); this.layout.push(newWidget); + this.activedGridItem = newWidget.i; }, addTabItem(item: LayoutConfig) { const idx = this.layout.findIndex((d: LayoutConfig) => d.i === item.i); @@ -102,6 +104,25 @@ export const dashboardStore = defineStore({ }; this.layout[idx].children?.push(i); }, + addTabWidget(tabIndex: number) { + const idx = this.layout.findIndex( + (d: LayoutConfig) => d.i === this.activedGridItem + ); + const newWidget = { + x: 0, + y: 0, + w: 24, + h: 12, + i: String(this.layout[idx].children[tabIndex].children.length), + type: "Widget", + widget: {}, + graph: {}, + standard: {}, + }; + if (this.layout[idx].children) { + this.layout[idx].children[tabIndex].children.push(newWidget); + } + }, activeGridItem(index: string) { this.activedGridItem = index; }, diff --git a/src/store/modules/data.ts b/src/store/modules/data.ts index 676a9bd9..f56c16cf 100644 --- a/src/store/modules/data.ts +++ b/src/store/modules/data.ts @@ -36,4 +36,5 @@ export const ConfigData = { sortOrder: "DEC", unit: "s", }, + children: [], }; diff --git a/src/types/dashboard.ts b/src/types/dashboard.ts index 35fe7bcc..c6a99b76 100644 --- a/src/types/dashboard.ts +++ b/src/types/dashboard.ts @@ -26,7 +26,7 @@ export interface LayoutConfig { metrics?: string[]; type?: string; queryMetricType?: string; - children?: any[]; + children?: any; } export interface WidgetConfig { diff --git a/src/views/dashboard/controls/Tab.vue b/src/views/dashboard/controls/Tab.vue index 5cb0b43a..33a397dd 100644 --- a/src/views/dashboard/controls/Tab.vue +++ b/src/views/dashboard/controls/Tab.vue @@ -16,22 +16,33 @@ limitations under the License. -->
- {{ item.name }} + - - - + + + + + + +
@@ -55,12 +66,15 @@ limitations under the License. --> :i="item.i" :key="item.i" > - +