From edda37078af7b6517670ab6afac4c43a418e5f12 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Fri, 7 Jan 2022 11:34:41 +0800 Subject: [PATCH] feat: apply dashboard config --- src/store/modules/dashboard.ts | 9 ++- src/store/modules/data.ts | 4 +- .../dashboard/configuration/ConfigEdit.vue | 60 ++++++++++++++----- .../dashboard/configuration/WidgetOptions.vue | 4 +- src/views/dashboard/data.ts | 2 +- src/views/dashboard/panel/Widget.vue | 19 +++++- 6 files changed, 75 insertions(+), 23 deletions(-) diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index bc1abdc8..180b5b85 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -63,7 +63,7 @@ export const dashboardStore = defineStore({ this.showConfig = show; }, selectWidget(widget: Nullable) { - this.selectedWidget = ConfigData || widget; + this.selectedWidget = ConfigData || widget; //todo }, setLayer(id: string) { this.layerId = id; @@ -71,6 +71,13 @@ export const dashboardStore = defineStore({ setEntity(type: string) { this.entity = type; }, + setConfigs(param: { [key: string]: unknown }) { + const index = this.layout.findIndex((d: LayoutConfig) => d.i === param.i); + this.layout[index] = { + ...this.layout[index], + ...param, + }; + }, async fetchMetricType(item: string) { const res: AxiosResponse = await graph .query("queryTypeOfMetrics") diff --git a/src/store/modules/data.ts b/src/store/modules/data.ts index 1cf8bdec..5b1a9892 100644 --- a/src/store/modules/data.ts +++ b/src/store/modules/data.ts @@ -25,8 +25,8 @@ export const ConfigData: LayoutConfig = { queryMetricType: "readMetricsValues", chart: "Line", widget: { - title: "Title", - tips: "Tooltip", + title: "Title123", + tips: "Tooltip123", }, graph: { showBackground: true, diff --git a/src/views/dashboard/configuration/ConfigEdit.vue b/src/views/dashboard/configuration/ConfigEdit.vue index 288096b3..980f9a2e 100644 --- a/src/views/dashboard/configuration/ConfigEdit.vue +++ b/src/views/dashboard/configuration/ConfigEdit.vue @@ -82,7 +82,7 @@ limitations under the License. --> {{ t("cancel") }} - + {{ t("apply") }} @@ -120,6 +120,7 @@ export default defineComponent({ const dashboardStore = useDashboardStore(); const appStoreWithOut = useAppStoreWithOut(); const { loading } = Loading(); + const { selectedWidget } = dashboardStore; const states = reactive<{ metrics: string[]; valueTypes: Option[]; @@ -127,19 +128,27 @@ export default defineComponent({ metricQueryType: string; chartType: string; activeNames: string; - tips: string; source: any; - title: string; + index: string; }>({ - metrics: dashboardStore.selectedWidget.metrics || [], + metrics: selectedWidget.metrics || [], valueTypes: [], valueType: "", metricQueryType: "", - chartType: dashboardStore.selectedWidget.chart, + chartType: selectedWidget.chart, activeNames: "1", source: {}, - tips: "", - title: "", + index: selectedWidget.i, + }); + const widgetOpt = reactive< + | { + title: string; + tips: string; + } + | any + >({ + tips: selectedWidget.widget.tips, + title: selectedWidget.widget.title, }); queryMetricType(states.metrics[0]); @@ -164,7 +173,6 @@ export default defineComponent({ const { typeOfMetrics } = resp.data; states.valueTypes = ValuesTypes[typeOfMetrics]; states.valueType = ValuesTypes[typeOfMetrics][0].value; - console.log(states.valueType); } function changeValueType(val: Option[]) { @@ -190,13 +198,11 @@ export default defineComponent({ ]; const configHeight = document.documentElement.clientHeight - 520; - function updateWidgetOptions(param: any) { - if (param.title !== undefined) { - states.title = param.title; - } - if (param.tips !== undefined) { - states.tips = param.tips; + function updateWidgetOptions(param: { label: string; value: string }) { + if (widgetOpt[param.label] === undefined) { + return; } + widgetOpt[param.label] = param.value; } async function queryMetrics() { @@ -208,7 +214,7 @@ export default defineComponent({ return; } const metricVal = json.data.readMetricsValues.values.values.map( - (d: any) => d.value + (d: { value: number }, index: number) => d.value + index // todo ); const m = dashboardStore.selectedWidget.metrics && @@ -223,7 +229,30 @@ export default defineComponent({ queryMetrics(); + function applyConfig() { + const opts = { + ...dashboardStore.selectedWidget, + metrics: states.metrics, + queryMetricType: states.valueType, + chart: states.chartType, + widget: { + ...dashboardStore.selectedWidget.widget, + title: widgetOpt.title, + tips: widgetOpt.tips, + }, + graph: { + ...dashboardStore.selectedWidget.graph, + }, + standard: { + ...dashboardStore.selectedWidget.standard, + }, + }; + dashboardStore.setConfigs(opts); + dashboardStore.setConfigPanel(false); + } + return { + ...toRefs(widgetOpt), ...toRefs(states), changeChartType, changeValueType, @@ -235,6 +264,7 @@ export default defineComponent({ updateWidgetOptions, configHeight, dashboardStore, + applyConfig, }; }, }); diff --git a/src/views/dashboard/configuration/WidgetOptions.vue b/src/views/dashboard/configuration/WidgetOptions.vue index c121aba5..8b956d00 100644 --- a/src/views/dashboard/configuration/WidgetOptions.vue +++ b/src/views/dashboard/configuration/WidgetOptions.vue @@ -45,10 +45,10 @@ const title = ref(""); const tooltip = ref(""); function updateTitle(value: string) { - emits("update", { title: value }); + emits("update", { value, label: "title" }); } function updateTips(value: string) { - emits("update", { tips: value }); + emits("update", { value, label: "tips" }); }