'use client' // src/components/Sidebar.tsx — 权限驱动侧边栏(遵循设计系统「统一管理布局」) import { usePathname } from 'next/navigation' import Link from 'next/link' import { LayoutDashboard, Server, Bell, Clock, Shield, Users, FileText, Activity } from 'lucide-react' import { hasPermission } from '@/lib/permissions' interface NavItem { label: string; href: string; icon: React.ComponentType<{ size?: number }>; permission?: string } interface NavSection { title?: string; items: NavItem[] } export default function Sidebar() { const pathname = usePathname() const isActive = (href: string) => pathname === href || (href !== '/' && pathname.startsWith(href)) // 默认显示所有导航项(客户端权限在 API 层强制验证,此处仅 UI 过滤) const userRole = 'admin' // TODO: 从 cookie 或 session 读取实际角色 const sections: NavSection[] = [ { items: [ { label: '仪表盘', href: '/', icon: LayoutDashboard }, ], }, { title: '监控', items: [ { label: '服务管理', href: '/services', icon: Server, permission: 'services:view' }, ], }, { title: '告警', items: [ { label: '告警设置', href: '/settings', icon: Bell, permission: 'alerts:manage' }, { label: '告警历史', href: '/alerts', icon: Activity, permission: 'alerts:view' }, { label: '状态历史', href: '/status-history', icon: Clock, permission: 'status_history:view' }, ], }, { title: '管理', items: [ { label: '用户管理', href: '/admin/users', icon: Users, permission: 'users:view' }, { label: '角色权限', href: '/admin/roles', icon: Shield, permission: 'roles:manage' }, { label: '审计日志', href: '/admin/audit-logs', icon: FileText, permission: 'audit:view' }, ], }, ] return ( ) }