import { useState, useEffect } from 'react'; import { Outlet, useLocation, useNavigate } from 'react-router-dom'; import { LayoutDashboard, Database, Server, Zap, Leaf, ClipboardList, Search, UserCog, Users, Lock, Shield, GitBranch, Bell, LogOut, Settings, Clock, Megaphone, Sun, Moon, BookOpen } from 'lucide-react'; import { menuSections } from '@/constants/menu'; import { useAuth } from '@/hooks/useAuth'; import { useTheme } from '@/hooks/useTheme'; const iconMap: Record = { LayoutDashboard, Database, Server, Zap, Leaf, ClipboardList, Search, UserCog, Users, Lock, Shield, GitBranch, Bell, Settings, Clock, Megaphone, BookOpen, }; export default function Layout() { const { user, logout, visibleMenuItems } = useAuth(); const { theme, toggleTheme } = useTheme(); const location = useLocation(); const navigate = useNavigate(); const currentPath = location.pathname.split('/')[1] || 'dashboard'; const [pendingCount, setPendingCount] = useState(0); useEffect(() => { import('@/api/request').then(m => m.default.get('/dashboard/stats')) .then((data: any) => setPendingCount(data?.ticket_pending ?? 0)) .catch(() => {}); }, [location.pathname]); const getPageTitle = () => { const item = visibleMenuItems.find(m => m.id === currentPath); return item?.label || '仪表盘'; }; return (
{/* 侧边栏 */} {/* 主内容区 */}
{/* 顶部栏 */}
{getPageTitle()}
{user.avatar}
{user.username}
{/* 页面内容 */}
); }