fix: change metrics config, fix tab routes (#345)

This commit is contained in:
Fine0830 2023-11-26 13:15:43 +08:00 committed by GitHub
parent ac57b229fc
commit c1c086d999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 27 deletions

View File

@ -389,7 +389,10 @@ export function useQueryTopologyExpressionsProcessor(metrics: string[], instance
values: [], values: [],
}; };
} }
obj[metrics[index]].values.push({ value: resp[k].results[0].values[0].value, id: instances[idx].id }); obj[metrics[index]].values.push({
value: resp[k].results[0] && resp[k].results[0].values[0].value,
id: instances[idx].id,
});
} }
} }
} }

View File

@ -52,7 +52,7 @@ function layerDashboards() {
route.children.push(d); route.children.push(d);
const tab = { const tab = {
name: `${child.name}ActiveTabIndex`, name: `${child.name}ActiveTabIndex`,
path: `/${child.name}/tab/:activeTabIndex`, path: `/${child.path}/tab/:activeTabIndex`,
component: () => import("@/views/Layer.vue"), component: () => import("@/views/Layer.vue"),
meta: { meta: {
notShow: true, notShow: true,

View File

@ -189,7 +189,9 @@ limitations under the License. -->
onMounted(async () => { onMounted(async () => {
await nextTick(); await nextTick();
setTimeout(() => {
init(); init();
}, 10);
}); });
async function init() { async function init() {
const dom = document.querySelector(".topology")?.getBoundingClientRect() || { const dom = document.querySelector(".topology")?.getBoundingClientRect() || {

View File

@ -54,7 +54,6 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, computed, watch } from "vue"; import { ref, computed, watch } from "vue";
import type { PropType } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { CalculationOpts, MetricModes } from "../../../data"; import { CalculationOpts, MetricModes } from "../../../data";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
@ -63,15 +62,40 @@ limitations under the License. -->
/*global defineEmits, defineProps */ /*global defineEmits, defineProps */
const props = defineProps({ const props = defineProps({
type: { type: String, default: "" }, type: { type: String, default: "" },
metrics: { type: Array as PropType<string[]>, default: () => [] }, isExpression: { type: Boolean, default: true },
}); });
const { t } = useI18n(); const { t } = useI18n();
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const m = props.metrics.map((d: string) => { const getMetrics = computed(() => {
let metrics = [];
const {
linkServerExpressions,
linkServerMetrics,
linkClientExpressions,
linkClientMetrics,
nodeExpressions,
nodeMetrics,
} = dashboardStore.selectedGrid;
switch (props.type) {
case "linkServerMetricConfig":
metrics = props.isExpression ? linkServerExpressions : linkServerMetrics;
break;
case "linkClientMetricConfig":
metrics = props.isExpression ? linkClientExpressions : linkClientMetrics;
break;
case "nodeMetricConfig":
metrics = props.isExpression ? nodeExpressions : nodeMetrics;
break;
}
return metrics || [];
});
const metricList = computed(() => {
const m = getMetrics.value.map((d: string) => {
return { label: d, value: d }; return { label: d, value: d };
}); });
const metricList = ref<Option[]>(m.length ? m : [{ label: "", value: "" }]); return m.length ? m : [{ label: "", value: "" }];
});
const currentMetric = ref<string>(metricList.value[0].value); const currentMetric = ref<string>(metricList.value[0].value);
const currentConfig = ref<{ unit: string; calculation: string; label: string }>({ const currentConfig = ref<{ unit: string; calculation: string; label: string }>({
unit: "", unit: "",
@ -81,6 +105,7 @@ limitations under the License. -->
const currentIndex = ref<number>(0); const currentIndex = ref<number>(0);
const getMetricConfig = computed(() => { const getMetricConfig = computed(() => {
let config = []; let config = [];
switch (props.type) { switch (props.type) {
case "linkServerMetricConfig": case "linkServerMetricConfig":
config = dashboardStore.selectedGrid.linkServerMetricConfig; config = dashboardStore.selectedGrid.linkServerMetricConfig;
@ -120,10 +145,6 @@ limitations under the License. -->
watch( watch(
() => props.type, () => props.type,
() => { () => {
const m = props.metrics.map((d: string) => {
return { label: d, value: d };
});
metricList.value = m.length ? m : [{ label: "", value: "" }];
currentMetric.value = metricList.value[0].value; currentMetric.value = metricList.value[0].value;
const config = getMetricConfig.value || []; const config = getMetricConfig.value || [];
currentIndex.value = 0; currentIndex.value = 0;

View File

@ -49,11 +49,7 @@ limitations under the License. -->
<Icon class="cp ml-5" iconName="mode_edit" size="middle" /> <Icon class="cp ml-5" iconName="mode_edit" size="middle" />
</span> </span>
</template> </template>
<Metrics <Metrics :type="configType" :isExpression="isExpression" @update="updateSettings" />
:type="configType"
:metrics="isExpression ? states.linkServerExpressions : states.linkServerMetrics"
@update="updateSettings"
/>
</el-popover> </el-popover>
</div> </div>
<div v-if="isExpression"> <div v-if="isExpression">
@ -88,11 +84,7 @@ limitations under the License. -->
<Icon class="cp ml-5" iconName="mode_edit" size="middle" /> <Icon class="cp ml-5" iconName="mode_edit" size="middle" />
</span> </span>
</template> </template>
<Metrics <Metrics :type="configType" :isExpression="isExpression" @update="updateSettings" />
:type="configType"
:metrics="isExpression ? states.linkClientExpressions : states.linkClientMetrics"
@update="updateSettings"
/>
</el-popover> </el-popover>
</div> </div>
<div v-if="isExpression"> <div v-if="isExpression">
@ -168,11 +160,7 @@ limitations under the License. -->
<Icon class="cp ml-5" iconName="mode_edit" size="middle" /> <Icon class="cp ml-5" iconName="mode_edit" size="middle" />
</span> </span>
</template> </template>
<Metrics <Metrics :type="configType" :isExpression="isExpression" @update="updateSettings" />
:type="configType"
:metrics="isExpression ? states.nodeExpressions : states.nodeMetrics"
@update="updateSettings"
/>
</el-popover> </el-popover>
</div> </div>
<div v-if="isExpression"> <div v-if="isExpression">