diff --git a/src/components/ServerCard.tsx b/src/components/ServerCard.tsx index 73c108c..26f3fb2 100644 --- a/src/components/ServerCard.tsx +++ b/src/components/ServerCard.tsx @@ -62,7 +62,7 @@ export default function ServerCard({ now, serverInfo }: { now: number; serverInf const parsedData = parsePublicNote(public_note) // 格式化运行时间 - const formatUptime = (seconds: number) => { + const formatUptime = (seconds: number, t: any) => { if (seconds >= 86400) { return `${Math.floor(seconds / 86400)} ${t("serverCard.days")}` } else { @@ -163,64 +163,72 @@ export default function ServerCard({ now, serverInfo }: { now: number; serverInf {/* 服务器详细信息标签和 PlanInfo */} -
+
{showServerDetails && ( <> - {cpu_info && cpu_info.length > 0 && ( - - - -

- {cpu_info[0].includes("Physical") ? "物理CPU: " : "vCPU: "} - {cpu_info[0].match(/(\d+)\s+(?:Physical|Virtual)\s+Core/)?.[1] || "?"} -

-
- - {cpu_info.join(", ")} - -
-
- )} - - {mem_total > 0 && ( -

- {t("serverCard.mem")}: {formatBytes(mem_total)} -

- )} - - {disk_total > 0 && ( -

- {t("serverCard.stg")}: {formatBytes(disk_total)} -

- )} - - {tcp > 0 && ( -

- TCP: {tcp} -

- )} - - {udp > 0 && ( -

- UDP: {udp} -

- )} - - {process > 0 && ( -

- {t("serverDetailChart.process")}: {process} -

- )} - - {uptime > 0 && ( -

- {t("serverCard.uptime")}: {formatUptime(uptime)} -

- )} + {/* 第一行:运行时间、CPU、内存、硬盘 */} +
+ {uptime > 0 && ( +

+ {t("serverCard.uptime")}: {formatUptime(uptime, t)} +

+ )} + + {cpu_info && cpu_info.length > 0 && ( + + + +

+ {cpu_info[0].includes("Physical") ? "物理CPU: " : "vCPU: "} + {cpu_info[0].match(/(\d+)\s+(?:Physical|Virtual)\s+Core/)?.[1] || "?"} +

+
+ + {cpu_info.join(", ")} + +
+
+ )} + + {mem_total > 0 && ( +

+ {t("serverCard.mem")}: {formatBytes(mem_total)} +

+ )} + + {disk_total > 0 && ( +

+ {t("serverCard.stg")}: {formatBytes(disk_total)} +

+ )} +
+ + {/* 第二行:TCP、UDP、进程数,以及 PlanInfo */} +
+
+ {tcp > 0 && ( +

+ TCP: {tcp} +

+ )} + + {udp > 0 && ( +

+ UDP: {udp} +

+ )} + + {process > 0 && ( +

+ {t("serverDetailChart.process")}: {process} +

+ )} +
+ + {parsedData?.planDataMod && } +
)} - - {parsedData?.planDataMod && }
{showNetTransfer && ( diff --git a/src/components/ServerCardInline.tsx b/src/components/ServerCardInline.tsx index d00fb80..3d721ef 100644 --- a/src/components/ServerCardInline.tsx +++ b/src/components/ServerCardInline.tsx @@ -1,6 +1,6 @@ import ServerFlag from "@/components/ServerFlag" import ServerUsageBar from "@/components/ServerUsageBar" -import { formatBytes } from "@/lib/format" +import { formatBytes, formatUptime } from "@/lib/format" import { GetFontLogoClass, GetOsName, MageMicrosoftWindows } from "@/lib/logo-class" import { cn, formatNezhaInfo, parsePublicNote } from "@/lib/utils" import { NezhaServer } from "@/types/nezha-api" @@ -138,58 +138,72 @@ export default function ServerCardInline({ now, serverInfo }: { now: number; ser
{/* 服务器详细信息标签和 PlanInfo */} -
+
{showServerDetails && ( <> - {cpu_info && cpu_info.length > 0 && ( - - - -

- {cpu_info[0].includes("Physical") ? "物理CPU: " : "vCPU: "} - {cpu_info[0].match(/(\d+)\s+(?:Physical|Virtual)\s+Core/)?.[1] || "?"} -

-
- - {cpu_info.join(", ")} - -
-
- )} - - {mem_total > 0 && ( -

- {t("serverCard.mem")}: {formatBytes(mem_total)} -

- )} - - {disk_total > 0 && ( -

- {t("serverCard.stg")}: {formatBytes(disk_total)} -

- )} - - {tcp > 0 && ( -

- TCP: {tcp} -

- )} - - {udp > 0 && ( -

- UDP: {udp} -

- )} - - {process > 0 && ( -

- {t("serverDetailChart.process")}: {process} -

- )} + {/* 第一行:运行时间、CPU、内存、硬盘 */} +
+ {uptime > 0 && ( +

+ {t("serverCard.uptime")}: {formatUptime(uptime, t)} +

+ )} + + {cpu_info && cpu_info.length > 0 && ( + + + +

+ {cpu_info[0].includes("Physical") ? "物理CPU: " : "vCPU: "} + {cpu_info[0].match(/(\d+)\s+(?:Physical|Virtual)\s+Core/)?.[1] || "?"} +

+
+ + {cpu_info.join(", ")} + +
+
+ )} + + {mem_total > 0 && ( +

+ {t("serverCard.mem")}: {formatBytes(mem_total)} +

+ )} + + {disk_total > 0 && ( +

+ {t("serverCard.stg")}: {formatBytes(disk_total)} +

+ )} +
+ + {/* 第二行:TCP、UDP、进程数,以及 PlanInfo */} +
+
+ {tcp > 0 && ( +

+ TCP: {tcp} +

+ )} + + {udp > 0 && ( +

+ UDP: {udp} +

+ )} + + {process > 0 && ( +

+ {t("serverDetailChart.process")}: {process} +

+ )} +
+ + {parsedData?.planDataMod && } +
)} - - {parsedData?.planDataMod && }
diff --git a/src/lib/format.ts b/src/lib/format.ts index 4781fc3..acedc1e 100644 --- a/src/lib/format.ts +++ b/src/lib/format.ts @@ -9,3 +9,11 @@ export function formatBytes(bytes: number, decimals: number = 2) { return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}` } + +export function formatUptime(seconds: number, t: (key: string) => string) { + if (seconds >= 86400) { + return `${Math.floor(seconds / 86400)} ${t("serverCard.days")}` + } else { + return `${Math.floor(seconds / 3600)} ${t("serverCard.hours")}` + } +}