From 129ffa98535f2fd32775d9250362e00de7289a65 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Fri, 11 Oct 2024 12:57:49 +0800 Subject: [PATCH] feat: net transfer badge --- components/ServerCard.tsx | 96 ++++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/components/ServerCard.tsx b/components/ServerCard.tsx index c03890d..2517e3d 100644 --- a/components/ServerCard.tsx +++ b/components/ServerCard.tsx @@ -2,13 +2,14 @@ import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api"; import ServerCardPopover from "@/components/ServerCardPopover"; import ServerFlag from "@/components/ServerFlag"; import ServerUsageBar from "@/components/ServerUsageBar"; +import { Badge } from "@/components/ui/badge"; import { Card } from "@/components/ui/card"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; -import { cn, formatNezhaInfo } from "@/lib/utils"; +import { cn, formatBytes, formatNezhaInfo } from "@/lib/utils"; import { useLocale, useTranslations } from "next-intl"; import { env } from "next-runtime-env"; import { useRouter } from "next/navigation"; @@ -25,6 +26,8 @@ export default function ServerCard({ const showFlag = env("NEXT_PUBLIC_ShowFlag") === "true"; + const showNetTransfer = env("NEXT_PUBLIC_ShowNetTransfer") === "true"; + const locale = useLocale(); return online ? ( @@ -52,46 +55,75 @@ export default function ServerCard({ -
{ router.push(`/${locale}/${id}`); }} - className={"grid cursor-pointer grid-cols-5 items-center gap-3"} + className="flex flex-col gap-2 cursor-pointer" > -
-

{t("CPU")}

-
- {cpu.toFixed(2)}% +
+
+

{t("CPU")}

+
+ {cpu.toFixed(2)}% +
+
- -
-
-

{t("Mem")}

-
- {mem.toFixed(2)}% +
+

{t("Mem")}

+
+ {mem.toFixed(2)}% +
+
- -
-
-

{t("STG")}

-
- {stg.toFixed(2)}% +
+

{t("STG")}

+
+ {stg.toFixed(2)}% +
+
- -
-
-

{t("Upload")}

-
- {up.toFixed(2)}M/s +
+

{t("Upload")}

+
+ {up.toFixed(2)}M/s +
-
-
-

{t("Download")}

-
- {down.toFixed(2)}M/s +
+

{t("Download")}

+
+ {down.toFixed(2)}M/s +
-
-
+ + {showNetTransfer && ( +
{ + router.push(`/${locale}/${id}`); + }} + className={"flex items-center justify-between gap-1"} + > + + {t("Upload")}:{formatBytes(serverInfo.status.NetInTransfer)} + + + {t("Download")}:{formatBytes(serverInfo.status.NetOutTransfer)} + +
+ )} + ) : (