diff --git a/web-vue/packages/core/layouts/views/desktop/analysis/components/HostInfo.vue b/web-vue/packages/core/layouts/views/desktop/analysis/components/HostInfo.vue index 7c0071b..2125645 100644 --- a/web-vue/packages/core/layouts/views/desktop/analysis/components/HostInfo.vue +++ b/web-vue/packages/core/layouts/views/desktop/analysis/components/HostInfo.vue @@ -16,7 +16,7 @@
-
{{ item.value }}%
+
{{ item.label }}
@@ -33,6 +33,7 @@ const hostCardRef = ref(); const chartRef = ref(); + const miniChartRefs = new Map(); const cpuData = ref([]); const loading = ref(false); @@ -46,8 +47,17 @@ }); let chartInstance: echarts.ECharts | null = null; + const miniChartInstances = new Map(); let resizeObserver: ResizeObserver | null = null; + function setMiniChartRef(el: Element | null, key: string) { + if (el instanceof HTMLDivElement) { + miniChartRefs.set(key, el); + } else { + miniChartRefs.delete(key); + } + } + async function getList() { loading.value = true; try { @@ -60,6 +70,7 @@ loading.value = false; nextTick(() => { renderChart(); + renderMiniCharts(); }); } } @@ -173,6 +184,63 @@ function resizeCharts() { chartInstance?.resize(); + miniChartInstances.forEach((chart) => chart.resize()); + } + + function renderMiniCharts() { + sideMetrics.value.forEach((item) => { + const el = miniChartRefs.get(item.key); + if (!el) return; + + let chart = miniChartInstances.get(item.key); + if (!chart) { + chart = echarts.init(el); + miniChartInstances.set(item.key, chart); + } + + chart.setOption({ + animation: true, + series: [ + { + type: 'pie', + radius: ['66%', '82%'], + center: ['50%', '50%'], + silent: true, + label: { show: false }, + labelLine: { show: false }, + data: [ + { + value: item.value, + itemStyle: { + color: item.color, + borderRadius: 10, + }, + }, + { + value: Math.max(100 - Number(item.value || 0), 0), + itemStyle: { + color: 'rgba(148, 163, 184, 0.18)', + }, + }, + ], + }, + ], + graphic: [ + { + type: 'text', + left: 'center', + top: 'center', + style: { + text: `${item.value}%`, + textAlign: 'center', + fill: item.color, + fontSize: 12, + fontWeight: 700, + }, + }, + ], + }); + }); } onMounted(() => { @@ -191,6 +259,8 @@ resizeObserver?.disconnect(); window.removeEventListener('resize', resizeCharts); chartInstance?.dispose(); + miniChartInstances.forEach((chart) => chart.dispose()); + miniChartInstances.clear(); chartInstance = null; }); @@ -302,7 +372,7 @@ background 0.2s ease; &__label { - margin-top: 8px; + margin-top: 6px; color: rgb(71 85 105); font-size: 12px; line-height: 16px; @@ -310,11 +380,10 @@ word-break: break-word; } - &__value { - font-size: 20px; - font-weight: 700; - line-height: 1; - white-space: nowrap; + &__chart { + width: 100%; + height: 72px; + min-height: 72px; } &:hover { diff --git a/web-vue/packages/core/layouts/views/desktop/analysis/index.vue b/web-vue/packages/core/layouts/views/desktop/analysis/index.vue index a00e0fd..39853af 100644 --- a/web-vue/packages/core/layouts/views/desktop/analysis/index.vue +++ b/web-vue/packages/core/layouts/views/desktop/analysis/index.vue @@ -1,9 +1,5 @@