From 81041891fab2e2b21e9e0e00fa361032831b8504 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Sat, 19 Mar 2022 11:47:11 +0800 Subject: [PATCH] set root --- src/views/Layer.vue | 2 ++ src/views/dashboard/List.vue | 57 ++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/views/Layer.vue b/src/views/Layer.vue index 0189230c..7e43f14b 100644 --- a/src/views/Layer.vue +++ b/src/views/Layer.vue @@ -73,6 +73,8 @@ function setLayer(n: string) { layer.value = "GENERAL"; break; } + dashboardStore.setLayer(layer.value); + dashboardStore.setEntity(EntityType[1].value); // appStore.setPageTitle(layer.value); } watch( diff --git a/src/views/dashboard/List.vue b/src/views/dashboard/List.vue index 294ed77c..08f03777 100644 --- a/src/views/dashboard/List.vue +++ b/src/views/dashboard/List.vue @@ -122,6 +122,7 @@ import router from "@/router"; import { DashboardItem } from "@/types/dashboard"; import { saveFile, readFile } from "@/utils/file"; import { EntityType } from "./data"; +import { findLastKey } from "lodash"; /*global Nullable*/ const { t } = useI18n(); @@ -241,34 +242,34 @@ async function setRoot(row: DashboardItem) { }) ); } - } - if ( - d.layer === row.layer && - d.entity === row.entity && - d.id !== row.id && - !row.isRoot && - d.isRoot - ) { - d.isRoot = false; - const key = [d.layer, d.entity, d.name.split(" ").join("-")].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, - }) - ); + } else { + if ( + d.layer === row.layer && + d.entity === row.entity && + row.isRoot === false && + d.isRoot === true + ) { + d.isRoot = false; + const key = [d.layer, d.entity, d.name.split(" ").join("-")].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);