From cba01c0b6033630212243bd82e7bb7cc7478f5b6 Mon Sep 17 00:00:00 2001 From: Fine Date: Thu, 28 Dec 2023 16:50:52 +0800 Subject: [PATCH] feat: update --- src/locales/lang/en.ts | 4 +-- src/types/dashboard.d.ts | 1 + src/views/dashboard/List.vue | 66 ++++++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/locales/lang/en.ts b/src/locales/lang/en.ts index 797b463f..30622ea0 100644 --- a/src/locales/lang/en.ts +++ b/src/locales/lang/en.ts @@ -94,8 +94,8 @@ const msg = { editTab: "Enable editing tab names", label: "Service Name", id: "Service ID", - setRoot: "Set this to root", - setNormal: "Set this to normal", + setRoot: "Set Normal to Root", + setNormal: "Set Root to Normal", export: "Export Dashboard Templates", import: "Import Dashboard Templates", yes: "Yes", diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts index 400ccd0b..9183194e 100644 --- a/src/types/dashboard.d.ts +++ b/src/types/dashboard.d.ts @@ -21,6 +21,7 @@ export type DashboardItem = { layer: string; isRoot: boolean; name: string; + topLevel: boolean; }; export interface LayoutConfig { x: number; diff --git a/src/views/dashboard/List.vue b/src/views/dashboard/List.vue index 4096291c..3a3495cc 100644 --- a/src/views/dashboard/List.vue +++ b/src/views/dashboard/List.vue @@ -191,6 +191,7 @@ limitations under the License. --> layer: layer, entity: entity, isRoot: false, + topLevel: false, }; if (index > -1) { p.id = item.id; @@ -382,8 +383,69 @@ limitations under the License. --> searchDashboards(1); loading.value = false; } - function handleTopLevel(row: any) { - console.log(row); + async function handleTopLevel(row: DashboardItem) { + const items: DashboardItem[] = []; + loading.value = true; + for (const d of dashboardStore.dashboards) { + if (d.id === row.id) { + d.isRoot = row.topLevel; + const key = [d.layer, d.entity, d.name].join("_"); + const layout = sessionStorage.getItem(key) || "{}"; + const c = { + ...JSON.parse(layout).configuration, + ...d, + }; + delete c.id; + + const setting = { + id: d.id, + configuration: JSON.stringify(c), + }; + const res = await dashboardStore.updateDashboard(setting); + if (res.data.changeTemplate.id) { + sessionStorage.setItem( + key, + JSON.stringify({ + id: d.id, + configuration: c, + }), + ); + } + } else { + if ( + d.layer === row.layer && + [EntityType[0].value].includes(d.entity) && + row.topLevel === false && + d.topLevel === true + ) { + d.topLevel = false; + const key = [d.layer, d.entity, d.name].join("_"); + const layout = sessionStorage.getItem(key) || "{}"; + const c = { + ...JSON.parse(layout).configuration, + ...d, + }; + const setting = { + id: d.id, + configuration: JSON.stringify(c), + }; + const res = await dashboardStore.updateDashboard(setting); + if (res.data.changeTemplate.id) { + sessionStorage.setItem( + key, + JSON.stringify({ + id: d.id, + configuration: c, + }), + ); + } + } + } + items.push(d); + } + dashboardStore.resetDashboards(items); + searchDashboards(1); + loading.value = false; } function handleRename(row: DashboardItem) { ElMessageBox.prompt("Please input dashboard name", "Edit", {