import { useState } from 'react'; import { Layout, Menu, Avatar, Dropdown, Typography, Badge } from 'antd'; import { DashboardOutlined, MonitorOutlined, BarChartOutlined, AlertOutlined, FileTextOutlined, CloudOutlined, SettingOutlined, UserOutlined, MenuFoldOutlined, MenuUnfoldOutlined, LogoutOutlined, BellOutlined, ThunderboltOutlined, AppstoreOutlined, } from '@ant-design/icons'; import { Outlet, useNavigate, useLocation } from 'react-router-dom'; import { getUser, removeToken } from '../utils/auth'; const { Header, Sider, Content } = Layout; const { Text } = Typography; const menuItems = [ { key: '/', icon: , label: '能源总览' }, { key: '/monitoring', icon: , label: '实时监控' }, { key: '/devices', icon: , label: '设备管理' }, { key: '/analysis', icon: , label: '能耗分析' }, { key: '/alarms', icon: , label: '告警管理' }, { key: '/carbon', icon: , label: '碳排放管理' }, { key: '/reports', icon: , label: '报表管理' }, { key: '/system', icon: , label: '系统管理', children: [ { key: '/system/users', label: '用户管理' }, { key: '/system/roles', label: '角色权限' }, { key: '/system/settings', label: '系统设置' }, ], }, ]; export default function MainLayout() { const [collapsed, setCollapsed] = useState(false); const navigate = useNavigate(); const location = useLocation(); const user = getUser(); const handleLogout = () => { removeToken(); localStorage.removeItem('user'); navigate('/login'); }; const userMenu = { items: [ { key: 'profile', icon: , label: '个人信息' }, { type: 'divider' as const }, { key: 'logout', icon: , label: '退出登录', onClick: handleLogout }, ], }; return ( {!collapsed && 天普EMS} navigate(key)} /> setCollapsed(!collapsed)}> {collapsed ? : } {/* TODO: fetch notification count from API */} } style={{ background: '#1890ff' }} /> {user?.full_name || user?.username || '用户'} ); }