diff --git a/src/hooks/useDashboardsSession.ts b/src/hooks/useDashboardsSession.ts index bd3e1a54..b2ae9c2e 100644 --- a/src/hooks/useDashboardsSession.ts +++ b/src/hooks/useDashboardsSession.ts @@ -27,6 +27,19 @@ export default function getDashboard(param: { d.entity === param.entity && d.layer === param.layer ); - - return dashboard; + const widgets = []; + for (const item of dashboard) { + if (item.type === "Tab") { + if (item.children && item.children.length) { + for (const child of item.children) { + if (child.children && child.children.length) { + widgets.push(...child.children); + } + } + } + } else { + widgets.push(item); + } + } + return { dashboard, widgets }; } diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts index 0601c7ad..9ef32d53 100644 --- a/src/types/dashboard.d.ts +++ b/src/types/dashboard.d.ts @@ -36,6 +36,7 @@ export interface LayoutConfig { children?: { name: string; children: LayoutConfig[] }[]; activedTabIndex?: number; metricConfig?: MetricConfigOpt[]; + id?: string; } export type MetricConfigOpt = { @@ -48,6 +49,7 @@ export type MetricConfigOpt = { }; export interface WidgetConfig { + name?: string; title?: string; tips?: string; } diff --git a/src/views/dashboard/Edit.vue b/src/views/dashboard/Edit.vue index 0cfc481e..dd006092 100644 --- a/src/views/dashboard/Edit.vue +++ b/src/views/dashboard/Edit.vue @@ -41,6 +41,7 @@ import Tool from "./panel/Tool.vue"; import { useDashboardStore } from "@/store/modules/dashboard"; import { useAppStoreWithOut } from "@/store/modules/app"; import Configuration from "./configuration"; +import { LayoutConfig } from "@/types/dashboard"; export default defineComponent({ name: "Dashboard", @@ -79,7 +80,7 @@ export default defineComponent({ }); } } - function setWidgetsID(widgets: any[]) { + function setWidgetsID(widgets: LayoutConfig[]) { for (const item of widgets) { item.id = item.i; if (item.type === "Tab") { diff --git a/src/views/dashboard/configuration/widget/AssociateOptions.vue b/src/views/dashboard/configuration/widget/AssociateOptions.vue index 925679b6..47668622 100644 --- a/src/views/dashboard/configuration/widget/AssociateOptions.vue +++ b/src/views/dashboard/configuration/widget/AssociateOptions.vue @@ -29,6 +29,8 @@ limitations under the License. --> import { ref, computed } from "vue"; import { useI18n } from "vue-i18n"; import { useDashboardStore } from "@/store/modules/dashboard"; +import getDashboard from "@/hooks/useDashboardsSession"; +import { LayoutConfig } from "@/types/dashboard"; const { t } = useI18n(); const dashboardStore = useDashboardStore(); @@ -41,45 +43,24 @@ const widgets = computed(() => { const isRank = ["TopList"].includes( dashboardStore.selectedGrid.graph && dashboardStore.selectedGrid.graph.type ); - const all = []; - for (const item of dashboardStore.layout) { - if (item.type === "Tab") { - if (item.children && item.children.length) { - for (const child of item.children) { - if (child.children && child.children.length) { - const items = child.children.filter( - (d: { i: string; index: string } | any) => { - if (isLinear) { - d.value = d.id; - d.label = (d.widget && d.widget.title) || d.type || ""; - return d; - } - if (isRank && d.type !== "Widget") { - d.value = d.id; - d.label = (d.widget && d.widget.title) || d.type || ""; - return d; - } - } - ); - all.push(...items); - } + const w = getDashboard(dashboardStore.currentDashboard).widgets; + const items = w.filter( + (d: { value: string; label: string } & LayoutConfig) => { + if (dashboardStore.selectedGrid.id !== d.id) { + if (isLinear) { + d.value = d.id || ""; + d.label = (d.widget && d.widget.title) || d.type || ""; + return d; + } + if (isRank && d.type !== "Widget") { + d.value = d.id || ""; + d.label = (d.widget && d.widget.title) || d.type || ""; + return d; } } - } else { - if (isLinear) { - item.value = item.id; - item.label = (item.widget && item.widget.title) || item.type || ""; - all.push(item); - return; - } - if (isRank && item.type !== "Widget") { - item.value = item.id; - item.label = (item.widget && item.widget.title) || item.type || ""; - all.push(item); - } } - } - return all; + ); + return items; }); function updateWidgetConfig(param: { [key: string]: string }) { const key = Object.keys(param)[0]; diff --git a/src/views/dashboard/configuration/widget/WidgetOptions.vue b/src/views/dashboard/configuration/widget/WidgetOptions.vue index 5a77ff5e..f6ef40f1 100644 --- a/src/views/dashboard/configuration/widget/WidgetOptions.vue +++ b/src/views/dashboard/configuration/widget/WidgetOptions.vue @@ -13,6 +13,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->