"use client"; import { ServerCrash, Home, RefreshCw } from "lucide-react"; import Link from "next/link"; import { useTranslation } from "react-i18next"; import { useErrorStore, ERROR_COLORS } from "@/stores/error-store"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; /** * 服务器错误 (500) 全屏错误页面组件 * 当 API 返回 500 错误时显示 * 消息:"服务器暂时不可用,请稍后重试" * 包含 "返回首页" 按钮 */ export function ServerError(): React.ReactElement | null { const { isServerError, serverErrorMessage, clearServerError } = useErrorStore(); const { t } = useTranslation("player"); const handleRetry = (): void => { clearServerError(); // 刷新页面尝试重新加载 if (typeof window !== "undefined") { window.location.reload(); } }; // 没有服务器错误时不显示 if (!isServerError) { return null; } return (
{/* 错误图标 */}
{/* 错误标题 */}

{t("serverError.title")}

{/* 错误消息 */}

{serverErrorMessage}

{/* 操作按钮 */}
{t("serverError.home")}
{/* 状态码提示 */}

{t("serverError.code")}

); } /** * 服务器错误弹窗/遮罩组件(适用于在现有页面中显示) */ export function ServerErrorModal(): React.ReactElement | null { const { isServerError, serverErrorMessage, clearServerError } = useErrorStore(); const { t } = useTranslation("player"); const handleRetry = (): void => { clearServerError(); window.location.reload(); }; if (!isServerError) { return null; } return (
{/* 错误图标 */}
{/* 错误消息 */}

{t("serverError.unavailable")}

{serverErrorMessage}

{/* 按钮 */}
{t("serverError.home")}
); }