"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useState } from "react"; import { getMe } from "@/lib/admin"; import { PreviewNotice, StatusCard } from "@/components/ui"; type Me = { email: string; role: string; plan: string; status: string }; const nav = [ { href: "/admin", label: "概览" }, { href: "/admin/users", label: "用户" }, { href: "/admin/tts", label: "TTS 与审计" }, ]; export function AdminGate({ children }: { children: React.ReactNode }) { const pathname = usePathname(); const [me, setMe] = useState(null); const [state, setState] = useState<"loading" | "denied" | "ready">("loading"); useEffect(() => { getMe() .then((m) => { setMe(m); setState(m.role === "admin" ? "ready" : "denied"); }) .catch(() => setState("denied")); }, []); if (state === "loading") { return (
); } if (state === "denied") { return (
访问被拒绝:需要管理员身份。普通用户无法查看或操作管理后台。
前往账户
); } return ( <>
{children}
); } export function AdminPageShell({ eyebrow, title, description, children }: { eyebrow: string; title: string; description?: string; children: React.ReactNode }) { return (

{eyebrow}

{title}

{description ?

{description}

: null}
{children}
); }