import React from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { LayoutDashboard, FileEdit, FileText, Layout, Users, Settings, LogOut, ShieldCheck, } from 'lucide-react'; import { User } from '../types'; import { storage } from '../utils/storage'; import { useOptionalAuth } from '../auth/AuthContext'; export default function Sidebar() { const location = useLocation(); const navigate = useNavigate(); const auth = useOptionalAuth(); const authUser = auth?.user ?? null; const currentUser = authUser ?? storage.get('currentUser', {} as User); const logout = async () => { if (auth) { await auth.logout(); } else { storage.remove('currentUser'); } navigate('/'); }; const navItems = [ { path: '/dashboard', icon: , title: '工作台', roles: ['super', 'admin', 'user'] }, { path: '/report-editor', icon: , title: '图文报告生成', roles: ['super', 'admin', 'user'] }, { path: '/report-manage', icon: , title: '报告管理', roles: ['super', 'admin', 'user'] }, { path: '/template-manage', icon: , title: '模板管理', roles: ['super', 'admin'] }, { path: '/user-manage', icon: , title: '用户管理', roles: ['super', 'admin'] }, { path: '/audit-logs', icon: , title: '审计日志', roles: ['super', 'admin'] }, { path: '/system-settings', icon: , title: '系统设置', roles: ['super', 'admin', 'user'] }, ]; const filteredNavItems = navItems.filter(item => item.roles.includes(currentUser.role)); const isCollapsed = location.pathname === '/report-editor' || location.pathname === '/template-manage'; return ( ); }