'use client'; import { useState } from 'react'; import Link from 'next/link'; import { usePathname, useRouter } from 'next/navigation'; import { useAuth } from './auth-context'; import { LayoutDashboard, FileText, Briefcase, Box, Layers, Image, BarChart3, Newspaper, LogOut, Menu, X, ChevronDown, Settings, Users, Phone, Shield, UserCog, Bell, } from 'lucide-react'; const menuItems = [ { label: '内容管理', icon: FileText, children: [ { label: '新闻资讯', href: '/admin/content/news', icon: Newspaper }, { label: '案例研究', href: '/admin/content/case-study', icon: Briefcase }, { label: '服务管理', href: '/admin/content/service', icon: Settings }, { label: '产品管理', href: '/admin/content/product', icon: Box }, { label: '解决方案', href: '/admin/content/solution', icon: Layers }, { label: 'Hero Banner', href: '/admin/content/hero-banner', icon: Image }, { label: '数据指标', href: '/admin/content/stat-item', icon: BarChart3 }, ], }, { label: '页面管理', icon: FileText, children: [ { label: '关于我们', href: '/admin/content/about-page', icon: Users }, { label: '团队介绍', href: '/admin/content/team-page', icon: Users }, { label: '联系我们', href: '/admin/content/contact-page', icon: Phone }, { label: '法律页面', href: '/admin/content/legal-page', icon: Shield }, ], }, { label: '页面配置', icon: Layers, children: [ { label: '首页区域', href: '/admin/zones', icon: LayoutDashboard }, ], }, { label: '资源管理', icon: Image, children: [ { label: '媒体库', href: '/admin/media', icon: Image }, ], }, { label: '系统管理', icon: Shield, children: [ { label: '用户管理', href: '/admin/users', icon: Users }, { label: '角色权限', href: '/admin/roles', icon: UserCog }, ], }, { label: '通知', icon: Bell, children: [ { label: '通知中心', href: '/admin/notifications', icon: Bell }, ], }, ]; export function AdminLayout({ children }: { children: React.ReactNode }) { const [sidebarOpen, setSidebarOpen] = useState(false); const [expandedMenus, setExpandedMenus] = useState>(new Set(['内容管理'])); const { user, logout } = useAuth(); const pathname = usePathname(); const router = useRouter(); const toggleMenu = (label: string) => { setExpandedMenus((prev) => { const next = new Set(prev); if (next.has(label)) next.delete(label); else next.add(label); return next; }); }; const handleLogout = () => { logout(); router.push('/admin/login'); }; const isActive = (href: string) => pathname === href || pathname?.startsWith(href + '/'); return (
{/* Mobile overlay */} {sidebarOpen && (
setSidebarOpen(false)} /> )} {/* Sidebar */} {/* Main content */}
{/* Top bar */}
查看网站
{/* Page content */}
{children}
); }