diff --git a/src/components/dashboard/Map.vue b/src/components/dashboard/Map.vue index eba24df..602ebf9 100644 --- a/src/components/dashboard/Map.vue +++ b/src/components/dashboard/Map.vue @@ -1,6 +1,6 @@ @@ -53,17 +53,34 @@ const updateTheme = (e: MediaQueryListEvent | boolean) => { }; onMounted(() => { - const chart = echarts.getInstanceByDom(document.querySelector('.chart') as HTMLElement); + const chartElement = document.querySelector('.chart') as HTMLElement; + if (!chartElement) return; + + const chart = echarts.getInstanceByDom(chartElement); + if (!chart) return; + + // 立即设置一次大小 + chart.resize(); + + // 监听窗口大小变化 + const handleResize = () => { + chart.resize(); + }; + + window.addEventListener('resize', handleResize); + + // 使用 ResizeObserver 监听容器大小变化 const resizeObserver = new ResizeObserver(() => { - chart?.resize(); + chart.resize(); }); - resizeObserver.observe(document.querySelector('.chart') as HTMLElement); + resizeObserver.observe(chartElement); const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); updateTheme(mediaQuery.matches); mediaQuery.addEventListener('change', updateTheme); return () => { + window.removeEventListener('resize', handleResize); resizeObserver.disconnect(); mediaQuery.removeEventListener('change', updateTheme); }; diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index a0c16ef..0fd1503 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -1,47 +1,132 @@ + +// 定义节点数据接口 +interface NodeStat { + title: string; + value: string; + subtitle: string; + iconPath: string; + colorClass: string; + bgColorClass: string; +} + +// 节点统计数据 +const nodeStats = computed(() => { + const totalLoad = 75; // 总负载值 + + // 根据负载值确定颜色 + let loadColorClass = 'text-success'; + let loadBgColorClass = 'bg-success/10'; + let loadIconPath = 'M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z'; + + if (totalLoad > 100) { + loadColorClass = 'text-error'; + loadBgColorClass = 'bg-error/10'; + loadIconPath = 'M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z'; + } else if (totalLoad > 75) { + loadColorClass = 'text-warning'; + loadBgColorClass = 'bg-warning/10'; + loadIconPath = 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z'; + } + + return [ + { + title: '总节点数', + value: '211', + subtitle: '全球部署', + iconPath: 'M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01', + colorClass: 'text-primary', + bgColorClass: 'bg-primary/10' + }, + { + title: '在线节点数', + value: '205', + subtitle: '正常运行', + iconPath: 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z', + colorClass: 'text-success', + bgColorClass: 'bg-success/10' + }, + { + title: '调配节点数', + value: '42', + subtitle: '负载均衡', + iconPath: 'M13 10V3L4 14h7v7l9-11h-7z', + colorClass: 'text-warning', + bgColorClass: 'bg-warning/10' + }, + { + title: '连接状态', + value: '211/114', + subtitle: '活跃连接', + iconPath: 'M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z', + colorClass: 'text-info', + bgColorClass: 'bg-info/10' + }, + { + title: '总负载', + value: `${totalLoad}%`, + subtitle: '系统负载', + iconPath: loadIconPath, + colorClass: loadColorClass, + bgColorClass: loadBgColorClass + } + ]; +}); + \ No newline at end of file