"use client" import { useState, useEffect } from "react" import Link from "next/link" import { usePathname, useRouter } from "next/navigation" import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { logout } from "@/lib/api/auth" import { hasPermission, getUserRole, type PermissionModule } from "@/lib/permissions" import { Brain, Music, Shirt, Gift, Home, Utensils, User, Settings, BarChart, LogOut, Lock, Sparkles, Heart, Footprints, Trophy, type LucideIcon, } from "lucide-react" interface MenuItem { label: string href: string icon: LucideIcon module: PermissionModule } // AI 管理 const aiMenuItems: MenuItem[] = [ { label: "大模型管理", href: "/ai-model", icon: Brain, module: "ai-model" }, ] // 内容管理 const contentMenuItems: MenuItem[] = [ { label: "服装管理", href: "/outfits", icon: Shirt, module: "outfits" }, { label: "道具管理", href: "/props", icon: Gift, module: "props" }, { label: "家居装饰管理", href: "/home-decor", icon: Home, module: "home-decor" }, { label: "歌曲管理", href: "/songs", icon: Music, module: "songs" }, { label: "舞蹈管理", href: "/dances", icon: Footprints, module: "dances" }, { label: "食物管理", href: "/food", icon: Utensils, module: "food" }, { label: "成就管理", href: "/achievements", icon: Trophy, module: "achievements" }, { label: "好感度系统", href: "/affinity", icon: Heart, module: "affinity" }, ] // 系统管理 const systemMenuItems: MenuItem[] = [ { label: "用户管理", href: "/users", icon: User, module: "users" }, { label: "权限管理", href: "/permissions", icon: Lock, module: "permissions" }, { label: "系统设置", href: "/settings", icon: Settings, module: "settings" }, ] function NavButton({ item, pathname }: { item: MenuItem; pathname: string }) { const isActive = pathname === item.href const Icon = item.icon return ( ) } export function Sidebar() { const pathname = usePathname() const router = useRouter() const [mounted, setMounted] = useState(false) useEffect(() => { setMounted(true) }, []) const handleLogout = async () => { try { await logout() router.push("/login") } catch (error) { console.error("退出登录失败:", error) } } // 根据权限过滤菜单项(挂载后才读 localStorage) const visibleAiItems = mounted ? aiMenuItems.filter((item) => hasPermission(item.module)) : [] const visibleContentItems = mounted ? contentMenuItems.filter((item) => hasPermission(item.module)) : [] const visibleSystemItems = mounted ? systemMenuItems.filter((item) => hasPermission(item.module)) : [] const role = mounted ? getUserRole() : "" return (
{role}
AI 管理
内容管理
系统管理