import { AppstoreOutlined, LogoutOutlined, MenuFoldOutlined, MenuUnfoldOutlined, UserOutlined, } from '@ant-design/icons'; import { Avatar, Button, Dropdown, Layout, Menu, message } from 'antd'; import React, { useEffect, useState } from 'react'; import { history, Outlet, useLocation } from 'umi'; import { ConfigProvider } from 'antd'; import zhCN from 'antd/lib/locale/zh_CN'; import './index.less'; const { Header, Sider, Content } = Layout; const MainLayout: React.FC = () => { const [collapsed, setCollapsed] = useState(false); const [username, setUsername] = useState(''); const location = useLocation(); useEffect(() => { // 检查登录状态 const isLoggedIn = localStorage.getItem('isLoggedIn'); const currentUsername = localStorage.getItem('username'); if (!isLoggedIn) { message.error('请先登录!'); history.push('/login'); return; } setUsername(currentUsername || ''); }, []); const handleMenuClick = (key: string) => { // 使用路由导航 history.push(`/${key}`); }; const handleLogout = () => { localStorage.removeItem('isLoggedIn'); localStorage.removeItem('username'); message.success('已退出登录'); history.push('/login'); }; const userMenu = (
); // 根据当前路径确定选中的菜单项 const getSelectedKey = () => { const path = location.pathname; if (path === '/images') return 'images'; if (path === '/profile') return 'profile'; return 'images'; // 默认选中镜像列表 }; return (