import { NavLink, Outlet, useNavigate, useLocation } from "react-router-dom" import { LayoutDashboard, Key, ShieldCheck, ClipboardList, LogOut, ChevronDown, User, Palette, Check, } from "lucide-react" import { useAuth } from "@/hooks/use-auth" import { useDashboardTheme } from "@/components/theme/theme-context" import { LogoMark } from "@/components/shared/LogoMark" import { buttonVariants } from "@/components/ui/button-variants" import { cn } from "@/lib/utils" import { useState, useRef, useEffect, type SVGProps } from "react" const GITHUB_REPO_URL = "https://github.com/chopper1026/kimi2api" const navItems = [ { to: "/admin/dashboard", label: "概览", icon: LayoutDashboard }, { to: "/admin/token", label: "账号管理", icon: ShieldCheck }, { to: "/admin/keys", label: "API Keys", icon: Key }, { to: "/admin/logs", label: "请求日志", icon: ClipboardList }, ] const pageTitles: Record = { "/admin/dashboard": "概览", "/admin/token": "账号管理", "/admin/keys": "API Keys", "/admin/logs": "请求日志", } function GitHubMark(props: SVGProps) { return ( ) } function UserMenu({ onLogout }: { onLogout: () => void }) { const [open, setOpen] = useState(false) const ref = useRef(null) const { mode, theme, options, setMode } = useDashboardTheme() useEffect(() => { if (!open) return const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false) } } document.addEventListener("mousedown", handler) return () => document.removeEventListener("mousedown", handler) }, [open]) return (
{open && (
主题
{options.map((option) => { const selected = option.mode === mode const description = option.mode === "system" ? `当前:${theme.appearance === "dark" ? "深色" : "浅色"}` : option.description return ( ) })}
)}
) } export default function AppLayout() { const { isAuthenticated, isLoading, logout } = useAuth() const navigate = useNavigate() const location = useLocation() if (isLoading) { return (
加载中...
) } if (!isAuthenticated) { navigate("/admin/login", { replace: true }) return null } const handleLogout = async () => { await logout() navigate("/admin/login", { replace: true }) } const title = pageTitles[location.pathname] || (location.pathname.startsWith("/admin/logs/") ? "日志详情" : "Kimi2API") return (
{/* Sidebar */} {/* Main area */}
{/* Top bar */}

{title}

{/* Content */}
) }