diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index d83f8e4..9bfb02c 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -1,6 +1,8 @@ // @auto-i18n-check. Please do not delete the line. import "@/styles/globals.css"; +import "/node_modules/flag-icons/css/flag-icons.min.css"; + import React from "react"; import { NextIntlClientProvider, useMessages } from "next-intl"; import { PublicEnvScript } from "next-runtime-env"; diff --git a/bun.lockb b/bun.lockb index 0667cb3..6139404 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/ServerCard.tsx b/components/ServerCard.tsx index 666e158..8111f24 100644 --- a/components/ServerCard.tsx +++ b/components/ServerCard.tsx @@ -9,8 +9,9 @@ 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 ServerFlag from "./ServerFlag"; export default function ServerCard({ serverInfo, @@ -32,15 +33,7 @@ export default function ServerCard({
- {showFlag ? ( - country_code ? ( - - {getUnicodeFlagIcon(country_code)} - - ) : ( - 🏁 - ) - ) : null} + {showFlag ? : null}

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

{t("CPU")}

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

{t("Mem")}

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

{t("STG")}

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

{t("Upload")}

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

{t("Download")}

{down.toFixed(2)} @@ -113,15 +96,7 @@ export default function ServerCard({
- {showFlag ? ( - country_code ? ( - - {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) + )} + + ); +} diff --git a/package.json b/package.json index 0f6a9e7..40ad458 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "clsx": "^2.1.1", "country-flag-icons": "^1.5.13", "eslint-plugin-simple-import-sort": "^12.1.1", + "flag-icons": "^7.2.3", "lucide-react": "^0.414.0", "luxon": "^3.5.0", "next": "^14.2.13", @@ -47,8 +48,8 @@ "eslint-plugin-turbo": "^2.1.2", "eslint-plugin-unused-imports": "^4.1.4", "@next/bundle-analyzer": "^14.2.13", - "@types/node": "^22.7.2", - "@types/react": "^18.3.9", + "@types/node": "^22.7.4", + "@types/react": "^18.3.10", "@types/react-dom": "^18.3.0", "autoprefixer": "^10.4.20", "eslint": "^9.11.1",