diff --git a/components/ServerCard.tsx b/components/ServerCard.tsx index 7eb800f..8111f24 100644 --- a/components/ServerCard.tsx +++ b/components/ServerCard.tsx @@ -9,42 +9,21 @@ import { } from "@/components/ui/popover"; import { cn, formatNezhaInfo } from "@/lib/utils"; import ServerCardPopover from "./ServerCardPopover"; -import getUnicodeFlagIcon from "country-flag-icons/unicode"; + import { env } from "next-runtime-env"; -import { useEffect, useState } from "react"; +import ServerFlag from "./ServerFlag"; export default function ServerCard({ serverInfo, }: { serverInfo: NezhaAPISafe; }) { - const [supportsEmojiFlags, setSupportsEmojiFlags] = useState(false); - - useEffect(() => { - const checkEmojiSupport = () => { - const canvas = document.createElement('canvas'); - const ctx = canvas.getContext('2d'); - const emojiFlag = "🇺🇸"; // 使用美国国旗作为测试 - if (!ctx) return; - ctx.fillStyle = "#000"; - ctx.textBaseline = 'top'; - ctx.font = '32px Arial'; - ctx.fillText(emojiFlag, 0, 0); - - const support = ctx.getImageData(16, 16, 1, 1).data[3] !== 0; - setSupportsEmojiFlags(support); - }; - - checkEmojiSupport(); - }, []); - const t = useTranslations("ServerCard"); const { name, country_code, online, cpu, up, down, mem, stg, ...props } = formatNezhaInfo(serverInfo); const showFlag = env("NEXT_PUBLIC_ShowFlag") === "true"; - return online ? (
- {showFlag ? ( - - {!supportsEmojiFlags ? ( - - ) : ( - getUnicodeFlagIcon(country_code) - )} - - ) : null} + {showFlag ? : null}

- {" "} - {/* 设置固定宽度 */}

{t("CPU")}

{cpu.toFixed(2)}% @@ -89,8 +58,6 @@ export default function ServerCard({
- {" "} - {/* 设置固定宽度 */}

{t("Mem")}

{mem.toFixed(2)}% @@ -98,8 +65,6 @@ export default function ServerCard({
- {" "} - {/* 设置固定宽度 */}

{t("STG")}

{stg.toFixed(2)}% @@ -107,8 +72,6 @@ export default function ServerCard({
- {" "} - {/* 设置固定宽度 */}

{t("Upload")}

{up.toFixed(2)} @@ -116,8 +79,6 @@ export default function ServerCard({
- {" "} - {/* 设置固定宽度 */}

{t("Download")}

{down.toFixed(2)} @@ -135,15 +96,7 @@ export default function ServerCard({
- {showFlag ? ( - - {!supportsEmojiFlags ? ( - - ) : ( - getUnicodeFlagIcon(country_code) - )} - - ) : null} + {showFlag ? : null}

{ + const checkEmojiSupport = () => { + const canvas = document.createElement("canvas"); + const ctx = canvas.getContext("2d"); + const emojiFlag = "🇺🇸"; // 使用美国国旗作为测试 + if (!ctx) return; + ctx.fillStyle = "#000"; + ctx.textBaseline = "top"; + ctx.font = "32px Arial"; + ctx.fillText(emojiFlag, 0, 0); + + const support = ctx.getImageData(16, 16, 1, 1).data[3] !== 0; + setSupportsEmojiFlags(support); + }; + + checkEmojiSupport(); + }, []); + + if (!country_code) return null; + + return ( + + {!supportsEmojiFlags ? ( + + ) : ( + getUnicodeFlagIcon(country_code) + )} + + ); +}