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')}

+
+ )}
);