/* * 开源代码,仅供学习和交流研究使用,商用请联系三丙 * 微信:mohan_88888 * 抖音:程序员三丙 * 付费课程知识星球:https://t.zsxq.com/aKtXo */ import React, {useState} from 'react'; import {Avatar, Button, Dropdown, Layout as AntLayout, Menu, message} from 'antd'; import { AimOutlined, DashboardOutlined, DownOutlined, EnvironmentOutlined, LogoutOutlined, MenuFoldOutlined, MenuUnfoldOutlined, ThunderboltOutlined, UserOutlined } from '@ant-design/icons'; import {useLocation, useNavigate} from 'react-router-dom'; import {useAuth} from '../contexts/AuthContext'; const { Header, Sider, Content } = AntLayout; interface LayoutProps { children: React.ReactNode; } const Layout: React.FC = ({ children }) => { const [collapsed, setCollapsed] = useState(false); const navigate = useNavigate(); const location = useLocation(); const { user, logout } = useAuth(); // 菜单项配置 const menuItems = [ { key: '/page/dashboard', icon: , label: '仪表盘', }, { key: '/page/stations', icon: , label: '充电站管理', }, { key: '/page/piles', icon: , label: '充电桩管理', }, { key: '/page/guns', icon: , label: '充电枪管理', }, ]; // 处理菜单点击 const handleMenuClick = ({ key }: { key: string }) => { navigate(key); }; // 处理退出登录 const handleLogout = () => { logout(); message.success('已退出登录'); navigate('/login'); }; // 用户下拉菜单 const userMenuItems = [ { key: 'logout', icon: , label: '退出登录', onClick: handleLogout, }, ]; // 获取当前选中的菜单项 const getSelectedKeys = () => { return [location.pathname]; }; return (
{collapsed ? 'JCPP' : 'JCPP管理系统'}
{children}
); }; export default Layout;