fix metrics

This commit is contained in:
Qiuxia Fan 2022-03-26 21:12:45 +08:00
parent cdb776866a
commit e95a4d6c41
2 changed files with 12 additions and 15 deletions

View File

@ -117,7 +117,7 @@ function changeMetric(val: string) {
currentMetric.value = val; currentMetric.value = val;
const index = metrics.value.findIndex((d: Option) => d.value === val); const index = metrics.value.findIndex((d: Option) => d.value === val);
currentIndex.value = index || 0; currentIndex.value = index || 0;
const config = getMetricConfig.value; const config = getMetricConfig.value || [];
currentConfig.value = { currentConfig.value = {
unit: "", unit: "",
@ -125,6 +125,7 @@ function changeMetric(val: string) {
calculation: "", calculation: "",
...config[index], ...config[index],
}; };
console.log(currentConfig.value);
} }
watch( watch(
() => props.type, () => props.type,
@ -134,14 +135,15 @@ watch(
}); });
metrics.value = m.length ? m : [{ label: "", value: "" }]; metrics.value = m.length ? m : [{ label: "", value: "" }];
currentMetric.value = metrics.value[0].value; currentMetric.value = metrics.value[0].value;
const config = getMetricConfig.value; const config = getMetricConfig.value || [];
currentIndex.value = 0; currentIndex.value = 0;
currentConfig.value = config[0] || { currentConfig.value = {
unit: "", unit: "",
label: "", label: "",
calculation: "", calculation: "",
...config[0],
}; };
console.log(currentConfig.value); console.log(config);
} }
); );
</script> </script>

View File

@ -416,7 +416,6 @@ function updateSettings(config?: { [key: string]: MetricConfigOpt[] }) {
dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, ...param }); dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, ...param });
dashboardStore.setConfigs({ ...dashboardStore.selectedGrid, ...param }); dashboardStore.setConfigs({ ...dashboardStore.selectedGrid, ...param });
emit("update", param); emit("update", param);
console.log(dashboardStore.selectedGrid);
} }
function updateLinkServerMetrics(options: Option[] | any) { function updateLinkServerMetrics(options: Option[] | any) {
const opt = options.map((d: Option) => d.value); const opt = options.map((d: Option) => d.value);
@ -428,9 +427,8 @@ function updateLinkServerMetrics(options: Option[] | any) {
changeLinkServerMetrics(); changeLinkServerMetrics();
return; return;
} }
const config = ( const origin = dashboardStore.selectedGrid.linkServerMetricConfig || [];
dashboardStore.selectedGrid.linkServerMetricConfig || [] const config = origin.length === 1 ? [] : origin.splice(index, 1);
).splice(index, 1);
changeLinkServerMetrics({ linkServerMetricConfig: config }); changeLinkServerMetrics({ linkServerMetricConfig: config });
} }
async function changeLinkServerMetrics(config?: { async function changeLinkServerMetrics(config?: {
@ -453,9 +451,8 @@ function updateLinkClientMetrics(options: Option[] | any) {
changeLinkClientMetrics(); changeLinkClientMetrics();
return; return;
} }
const config = ( const origin = dashboardStore.selectedGrid.linkClientMetricConfig || [];
dashboardStore.selectedGrid.linkClientMetricConfig || [] const config = origin.length === 1 ? [] : origin.splice(index, 1);
).splice(index, 1);
changeLinkClientMetrics({ linkClientMetricConfig: config }); changeLinkClientMetrics({ linkClientMetricConfig: config });
} }
async function changeLinkClientMetrics(config?: { async function changeLinkClientMetrics(config?: {
@ -476,10 +473,8 @@ function updateNodeMetrics(options: Option[] | any) {
changeNodeMetrics(); changeNodeMetrics();
return; return;
} }
const config = (dashboardStore.selectedGrid.nodeMetricConfig || []).splice( const origin = dashboardStore.selectedGrid.nodeMetricConfig || [];
index, const config = origin.length === 1 ? [] : origin.splice(index, 1);
1
);
changeNodeMetrics({ nodeMetricConfig: config }); changeNodeMetrics({ nodeMetricConfig: config });
} }
async function changeNodeMetrics(config?: { async function changeNodeMetrics(config?: {