"use client"; import { useEffect, useState } from "react"; import { useRouter, usePathname } from "next/navigation"; import { useAuthStore } from "@/stores/auth"; import { Header } from "@/components/layout/header"; import Link from "next/link"; import { cn } from "@/lib/utils"; import { BarChart3, TrendingUp, AppWindow, CheckCircle, Users, Bot, ClipboardList, ShieldCheck, Menu, X, } from "lucide-react"; import type { LucideIcon } from "lucide-react"; const adminNavItems: { href: string; label: string; icon: LucideIcon }[] = [ { href: "/dashboard", label: "数据总览", icon: BarChart3 }, { href: "/analytics", label: "使用分析", icon: TrendingUp }, { href: "/apps", label: "应用管理", icon: AppWindow }, { href: "/reviews", label: "审核队列", icon: CheckCircle }, { href: "/users", label: "人员管理", icon: Users }, { href: "/models", label: "模型管理", icon: Bot }, { href: "/audit", label: "审计日志", icon: ClipboardList }, { href: "/security", label: "安全管理", icon: ShieldCheck }, ]; export default function AdminLayout({ children }: { children: React.ReactNode }) { const user = useAuthStore((s) => s.user); const isAuthenticated = useAuthStore((s) => s.isAuthenticated); const isLoading = useAuthStore((s) => s.isLoading); const router = useRouter(); const pathname = usePathname(); const [sidebarOpen, setSidebarOpen] = useState(false); useEffect(() => { if (!isLoading && (!isAuthenticated || !["admin", "super_admin"].includes(user?.role || ""))) { router.replace("/store"); } }, [isAuthenticated, isLoading, user, router]); if (isLoading) { return (
); } if (!isAuthenticated) return null; return (
{/* 手机端侧边栏切换按钮 */} {/* 手机端遮罩层 */} {sidebarOpen && (
setSidebarOpen(false)} /> )}
{children}
); }