import { useState, useEffect } from 'react' import { Outlet, useNavigate, useLocation } from 'react-router-dom' import { Layout as AntLayout, Menu, Button, Drawer, Popconfirm } from 'antd' import { DashboardOutlined, UserOutlined, AppstoreOutlined, FileTextOutlined, ExportOutlined, ImportOutlined, MenuFoldOutlined, MenuUnfoldOutlined, TeamOutlined, LogoutOutlined, MenuOutlined } from '@ant-design/icons' import { useAuth } from '../contexts/AuthContext' const { Header, Sider, Content } = AntLayout const MOBILE_BREAKPOINT = 768 const menuItems = [ { key: '/dashboard', icon: , label: '仪表盘' }, { key: '/persons', icon: , label: '人员管理' }, { key: '/items', icon: , label: '物品管理' }, { key: '/work-records', icon: , label: '工作记录' }, { key: '/export', icon: , label: '导出报表' }, { key: '/import', icon: , label: '导入数据' }, { key: '/admins', icon: , label: '管理员管理' } ] function Layout() { const [collapsed, setCollapsed] = useState(false) const [isMobile, setIsMobile] = useState(window.innerWidth < MOBILE_BREAKPOINT) const [drawerVisible, setDrawerVisible] = useState(false) const navigate = useNavigate() const location = useLocation() const { logout, admin } = useAuth() // Mobile detection with resize listener useEffect(() => { const handleResize = () => { const mobile = window.innerWidth < MOBILE_BREAKPOINT setIsMobile(mobile) if (!mobile) { setDrawerVisible(false) } } window.addEventListener('resize', handleResize) return () => window.removeEventListener('resize', handleResize) }, []) const handleMenuClick = ({ key }) => { navigate(key) if (isMobile) { setDrawerVisible(false) } } const handleLogout = () => { logout() navigate('/login') } const toggleDrawer = () => { setDrawerVisible(!drawerVisible) } const menuContent = ( ) const logoContent = (
{collapsed && !isMobile ? '统计' : '工作统计系统'}
) return ( {/* Mobile Drawer */} {isMobile ? ( setDrawerVisible(false)} open={drawerVisible} width={250} bodyStyle={{ padding: 0, background: '#001529' }} headerStyle={{ display: 'none' }} > {logoContent} {menuContent} ) : ( {logoContent} {menuContent} )}
{isMobile ? (
) } export default Layout