import React, { useState, useEffect } from 'react'; import { Outlet, Link, useLocation, useNavigate } from 'react-router-dom'; import { Layout as AntLayout, Menu, Button, Dropdown, Avatar } from 'antd'; import { HomeOutlined, CheckSquareOutlined, ScheduleOutlined, RobotOutlined, BarChartOutlined, UserOutlined, LogoutOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons'; import { useAuth } from '../context/AuthContext'; const { Header, Sider, Content } = AntLayout; const Layout = () => { const { user, logout } = useAuth(); const location = useLocation(); const navigate = useNavigate(); const [collapsed, setCollapsed] = useState(false); const [isMobile, setIsMobile] = useState(window.innerWidth < 768); // 监听窗口大小变化 useEffect(() => { const handleResize = () => { setIsMobile(window.innerWidth < 768); if (window.innerWidth < 768) { setCollapsed(true); } }; window.addEventListener('resize', handleResize); handleResize(); return () => window.removeEventListener('resize', handleResize); }, []); const toggleCollapsed = () => { setCollapsed(!collapsed); }; // 当前选中的菜单项 const selectedKey = (() => { const path = location.pathname; if (path === '/') return '1'; if (path === '/tasks') return '2'; if (path === '/schedule') return '3'; if (path === '/ai-chat') return '4'; if (path === '/stats') return '5'; return '1'; })(); // 用户菜单 const userMenu = { items: [ { key: '1', label: (