import React, { useState } from 'react'; import { Outlet, useNavigate, useLocation } from 'react-router-dom'; import { Layout, Menu, Avatar, Dropdown, theme, Button, Space, } from 'antd'; import { DashboardOutlined, AppstoreOutlined, InboxOutlined, MobileOutlined, UserOutlined, TeamOutlined, LogoutOutlined, MenuFoldOutlined, MenuUnfoldOutlined, } from '@ant-design/icons'; import { useAuthStore } from '../../store/useAuthStore'; const { Header, Sider, Content } = Layout; const menuItems = [ { key: '/dashboard', icon: , label: '仪表盘', }, { key: '/device-types', icon: , label: '设备类型', }, { key: '/batches', icon: , label: '批次管理', }, { key: '/devices', icon: , label: '设备列表', }, { key: '/users', icon: , label: '用户管理', }, { key: '/admins', icon: , label: '管理员', }, ]; const MainLayout: React.FC = () => { const [collapsed, setCollapsed] = useState(false); const navigate = useNavigate(); const location = useLocation(); const { adminInfo, logout } = useAuthStore(); const { token: themeToken } = theme.useToken(); const handleMenuClick = ({ key }: { key: string }) => { navigate(key); }; const handleLogout = () => { logout(); navigate('/login'); }; const userMenuItems = [ { key: 'profile', icon: , label: '个人信息', }, { type: 'divider' as const, }, { key: 'logout', icon: , label: '退出登录', danger: true, onClick: handleLogout, }, ]; const getRoleLabel = (role?: string) => { const roleMap: Record = { super_admin: '超级管理员', admin: '管理员', operator: '操作员', }; return roleMap[role || ''] || role; }; return ( {collapsed ? 'RTC' : 'RTC 管理后台'} : } onClick={() => setCollapsed(!collapsed)} style={{ fontSize: 16 }} /> } style={{ backgroundColor: themeToken.colorPrimary }} /> {adminInfo?.name || adminInfo?.username} ({getRoleLabel(adminInfo?.role)}) ); }; export default MainLayout;