From e0cc547c8b1d5a6016f2f9a8283f3812662666d1 Mon Sep 17 00:00:00 2001 From: "Logan.Li" Date: Mon, 14 Sep 2026 15:27:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=20=E8=B5=84=E6=BA=90=E8=B6=8B?= =?UTF-8?q?=E5=8A=BF=E5=9B=BE=E7=A7=BB=E9=99=A4=E9=9A=8F=E6=9C=BA=E6=A8=A1?= =?UTF-8?q?=E6=8B=9F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 无主机/无指标时不再用 Math.random 生成假曲线,改为空状态提示 - 移除随之不再使用的 avgCpu/avgMemory props,新增中英文 noData 文案 --- .../src/components/dashboard/Dashboard.tsx | 2 -- .../components/dashboard/DashboardCharts.tsx | 27 +++++++------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/frontend/src/components/dashboard/Dashboard.tsx b/frontend/src/components/dashboard/Dashboard.tsx index 1ae1265..d89a60d 100644 --- a/frontend/src/components/dashboard/Dashboard.tsx +++ b/frontend/src/components/dashboard/Dashboard.tsx @@ -148,8 +148,6 @@ export function Dashboard() { {/* 资源使用率趋势 — 第一行 */}
= 0; i--) { - const d = new Date(Date.now() - i * 60 * 60 * 1000); - data.push({ - time: `${d.getHours().toString().padStart(2, '0')}:00`, - cpu: Number(Math.max(0, Math.min(100, avgCpu + (Math.random() - 0.5) * 15)).toFixed(1)), - memory: Number(Math.max(0, Math.min(100, avgMemory + (Math.random() - 0.5) * 10)).toFixed(1)), - disk: Number(Math.max(0, Math.min(100, avgDisk + (Math.random() - 0.5) * 5)).toFixed(1)), - }); - } - return data; -} +// 无真实指标时不再生成模拟曲线,避免“没有主机却有波动”的误导展示 // Logan.Li function buildMetricsFromReal( metrics: JsonData[], avgDisk: number) { if (!metrics || metrics.length === 0) return []; @@ -291,8 +279,6 @@ export function TopResourceUsageCard({ topUsage }: { topUsage: JsonData}) { } export function ResourceUsageCard({ - avgCpu, - avgMemory, avgDisk, totalCpu, totalMemory, @@ -301,8 +287,6 @@ export function ResourceUsageCard({ usedDisk, metrics, }: { - avgCpu: number; - avgMemory: number; avgDisk: number; totalCpu: number; totalMemory: number; @@ -312,7 +296,6 @@ export function ResourceUsageCard({ metrics?: JsonData[]; }) { const realData = buildMetricsFromReal(metrics ?? [], avgDisk); - const data = realData.length > 0 ? realData : generateMetricsData(avgCpu, avgMemory, avgDisk, 24); const { t } = useTranslation(); return ( @@ -358,6 +341,7 @@ export function ResourceUsageCard({
+ {realData.length > 0 ? (
@@ -385,6 +369,13 @@ export function ResourceUsageCard({
+ ) : ( + /* 空状态:无主机/无指标时明确提示,不再展示模拟波动 // Logan.Li */ +
+ +

{t('dashboard.resourceUsage.noData')}

+
+ )}
);