From 1cdd65f49cd5c804d40c2569ba3da71c4eac4518 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Tue, 15 Mar 2022 22:59:28 +0800 Subject: [PATCH] edit dashboards --- src/components/Graph.vue | 3 +- src/store/modules/dashboard.ts | 52 ++++++++++++++++++++++++++++++++-- src/views/Service.vue | 5 ++++ src/views/dashboard/List.vue | 47 +++++++++++++++++++++++------- 4 files changed, 91 insertions(+), 16 deletions(-) diff --git a/src/components/Graph.vue b/src/components/Graph.vue index dc906a99..ae62159a 100644 --- a/src/components/Graph.vue +++ b/src/components/Graph.vue @@ -20,7 +20,6 @@ import { watch, ref, Ref, onMounted, onBeforeUnmount, unref } from "vue"; import type { PropType } from "vue"; import { useECharts } from "@/hooks/useEcharts"; import { addResizeListener, removeResizeListener } from "@/utils/event"; -import { useTimeoutFn } from "@/hooks/useTimeout"; /*global Nullable, defineProps, defineEmits*/ const emits = defineEmits(["select"]); @@ -40,7 +39,7 @@ const props = defineProps({ onMounted(async () => { await setOptions(props.option); addResizeListener(unref(chartRef), resize); - useTimeoutFn(() => { + setTimeout(() => { const instance = getInstance(); instance.on("click", (params: any) => { diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 7b5b5cce..be2cd255 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -349,15 +349,61 @@ export const dashboardStore = defineStore({ sessionStorage.getItem("dashboards") || "[]" ); }, + async updateDashboard(param: { name: string }) { + const key = [ + this.currentDashboard.layer, + this.currentDashboard.entity, + this.currentDashboard.name.split(" ").join("-"), + ].join("_"); + const layout = sessionStorage.getItem(key); + const c = { + isRoot: false, + children: layout, + ...this.currentDashboard, + name: param.name, + }; + const setting = { + id: this.currentDashboard.id, + configuration: JSON.stringify(c), + }; + const res: AxiosResponse = await graphql.query("updateTemplate").params({ + setting, + }); + if (res.data.errors) { + ElMessage.error(res.data.errors); + return res.data; + } + const json = res.data.data.changeTemplate; + if (!json.status) { + ElMessage.error(json.message); + return; + } + ElMessage.success("Saved successfully"); + this.currentDashboard.name = param.name; + this.dashboards = this.dashboards.map((d: any) => { + if (d.id === this.currentDashboard.id) { + d = this.currentDashboard; + } + return d; + }); + sessionStorage.setItem("dashboards", JSON.stringify(this.dashboards)); + sessionStorage.removeItem(key); + const str = [ + this.currentDashboard.layer, + this.currentDashboard.entity, + param.name.split(" ").join("-"), + ].join("_"); + sessionStorage.setItem(str, JSON.stringify(setting)); + }, async saveDashboard() { if (!this.currentDashboard.name) { ElMessage.error("The dashboard name is needed."); return; } const c = { - ...this.currentDashboard, isRoot: false, children: this.layout, + ...this.currentDashboard, }; let res: AxiosResponse; let json; @@ -399,7 +445,7 @@ export const dashboardStore = defineStore({ this.dashboards.push({ id: json.id, - name, + name: this.currentDashboard.name, layer: this.layerId, entity: this.entity, isRoot: true, @@ -413,7 +459,7 @@ export const dashboardStore = defineStore({ sessionStorage.setItem(key, JSON.stringify(l)); sessionStorage.setItem("dashboards", JSON.stringify(this.dashboards)); }, - async deleteDashbaord() { + async deleteDashboard() { const res: AxiosResponse = await graphql .query("removeTemplate") .params({ id: this.currentDashboard.id }); diff --git a/src/views/Service.vue b/src/views/Service.vue index a82c0969..67365b77 100644 --- a/src/views/Service.vue +++ b/src/views/Service.vue @@ -34,6 +34,7 @@ limitations under the License. --> :span-method="objectSpanMethod" :border="true" :style="{ fontSize: '14px' }" + v-loading="loading" > (false); const layer = ref("GENERAL"); const searchText = ref(""); const services = ref([]); @@ -91,12 +93,14 @@ dashboardStore.setDashboards(); async function getServices() { setLayer(String(route.name)); + loading.value = true; const res = await selectorStore.fetchServices(layer.value); if (res.errors) { ElMessage.error(res.errors); services.value = []; return; } + loading.value = false; const map: { [key: string]: any[] } = selectorStore.services.reduce( (result: { [key: string]: any[] }, item: any) => { item.group = item.group || ""; @@ -150,6 +154,7 @@ function visitLayout(row: { id: string }) { (d: { name: string; isRoot: boolean; layer: string; entity: string }) => d.layer === layer.value && d.entity === EntityType[0].value && d.isRoot )[0] || {}; + dashboardStore.setCurrentDashboard(l); router.push( `/dashboard/${layer.value}/${EntityType[0].value}/${row.id}/${(l.name || "") .split(" ") diff --git a/src/views/dashboard/List.vue b/src/views/dashboard/List.vue index 8d48de8e..eede0f39 100644 --- a/src/views/dashboard/List.vue +++ b/src/views/dashboard/List.vue @@ -40,18 +40,22 @@ limitations under the License. --> :data="dashboards" :style="{ width: '100%' }" max-height="550" + v-loading="loading" >