'use client' import { useState, useEffect } from 'react' import Link from 'next/link' import { usePathname } from 'next/navigation' import { LayoutDashboard, FileText, Settings, Users, Shield, Key, Clock, CheckCircle, PlusSquare, Upload, List, Mail } from 'lucide-react' const navItems = [ { href: '/dashboard', label: '仪表盘', icon: LayoutDashboard, perm: null }, { href: '/tickets/pending', label: '待办工单', icon: Clock, perm: 'tickets:read' }, { href: '/tickets/completed', label: '已办工单', icon: CheckCircle, perm: 'tickets:read' }, { href: '/tickets/create', label: '手动建单', icon: PlusSquare, perm: 'tickets:create' }, { href: '/tickets/import', label: '导入工单', icon: Upload, perm: 'tickets:import' }, { href: '/reports', label: '报告管理', icon: FileText, perm: 'reports:read' }, ] const settingsItems = [ { href: '/settings/users', label: '用户管理', icon: Users, perm: 'users:read' }, { href: '/settings/roles', label: '角色权限', icon: Shield, perm: 'roles:read' }, { href: '/settings/api-keys', label: 'API Key', icon: Key, perm: 'api-keys:read' }, { href: '/settings/audit-logs', label: '审计日志', icon: FileText, perm: 'audit-logs:read' }, { href: '/settings/monitor', label: '邮件监控', icon: Mail, perm: 'monitor:read' }, ] function hasAnyAdminPerm(permissions: string[]): boolean { return permissions.includes('*') || permissions.some(p => p.startsWith('users:') || p.startsWith('roles:') || p.startsWith('api-keys:')) } export default function Sidebar() { const pathname = usePathname() const [permissions, setPermissions] = useState([]) useEffect(() => { fetch('/api/auth/me') .then(r => r.json()) .then(u => { if (u.user?.permissions) setPermissions(u.user.permissions) }) .catch(() => {}) }, []) const canSee = (perm: string | null) => { if (perm === null) return true if (permissions.includes('*')) return true return permissions.includes(perm) } return ( ) }