From 552bc4795c6bd43bd1c234e9769e6b41d2f6de4d Mon Sep 17 00:00:00 2001 From: dushixiang Date: Mon, 1 Dec 2025 21:47:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E9=95=BF=E4=B8=BA=E6=99=BA=E8=83=BD=E6=98=BE=E7=A4=BA=EF=BC=9A?= =?UTF-8?q?=E5=8F=AA=E6=98=BE=E7=A4=BA=E6=9C=80=E9=87=8D=E8=A6=81=E7=9A=84?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E5=8D=95=E4=BD=8D=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E8=BF=87=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Public/ServerDetail.tsx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/web/src/pages/Public/ServerDetail.tsx b/web/src/pages/Public/ServerDetail.tsx index ae6c4c6..5745bcd 100644 --- a/web/src/pages/Public/ServerDetail.tsx +++ b/web/src/pages/Public/ServerDetail.tsx @@ -44,6 +44,7 @@ import type { AggregatedTemperatureMetric, LatestMetrics } from '@/types'; +import dayjs from "dayjs"; const formatBytes = (bytes: number | undefined | null): string => { if (!bytes || bytes <= 0) return '0 B'; @@ -67,9 +68,17 @@ const formatUptime = (seconds: number | undefined | null): string => { const minutes = Math.floor((seconds % 3600) / 60); const parts: string[] = []; - if (days > 0) parts.push(`${days} 天`); - if (hours > 0) parts.push(`${hours} 小时`); - if (minutes > 0) parts.push(`${minutes} 分钟`); + + // 智能显示:只显示最重要的两个单位,避免文本过长 + if (days > 0) { + parts.push(`${days} 天`); + if (hours > 0) parts.push(`${hours} 小时`); + } else if (hours > 0) { + parts.push(`${hours} 小时`); + if (minutes > 0) parts.push(`${minutes} 分钟`); + } else if (minutes > 0) { + parts.push(`${minutes} 分钟`); + } return parts.length > 0 ? parts.join(' ') : '不到 1 分钟'; }; @@ -79,13 +88,7 @@ const formatDateTime = (value: string | number | undefined | null): string => { return '-'; } - const date = typeof value === 'number' ? new Date(value) : new Date(value); - - if (Number.isNaN(date.getTime())) { - return '-'; - } - - return date.toLocaleString('zh-CN'); + return dayjs(value).format('YYYY-MM-DD HH:mm:ss') }; // 网卡颜色配置(上行和下行使用不同的色调) @@ -801,8 +804,8 @@ const ServerDetail = () => { ]; const statusInfo = [ - {label: '运行时间', value: uptimeDisplay}, {label: '启动时间', value: bootTimeDisplay}, + {label: '运行时间', value: uptimeDisplay}, {label: '最近心跳', value: lastSeenDisplay}, {label: '进程数', value: latestMetrics?.host?.procs ?? '-'}, {label: '网络累计', value: networkSummary},