import React, { useState, useEffect } from 'react'; import { Outlet, useNavigate, useLocation } from 'react-router-dom'; import { Layout, Menu, Button, Space, ConfigProvider, theme, Breadcrumb, Badge, message } from 'antd'; // 先引入中文语言包 import zhCN from 'antd/locale/zh_CN'; import { DashboardOutlined, ExperimentOutlined, VideoCameraOutlined, BellOutlined, DownloadOutlined, UserOutlined, LogoutOutlined, MenuUnfoldOutlined, MenuFoldOutlined, TeamOutlined, MenuOutlined } from '@ant-design/icons'; import logo from '../assets/logo.png'; import { useSelector } from 'react-redux'; import { RootState, useAppDispatch } from '../store'; import { logout } from '../store/userSlice'; import { getMenuList } from '../api/mune'; const { Header, Sider, Content } = Layout; export default function AppLayout() { const [collapsed, setCollapsed] = useState(false); const [time, setTime] = useState(new Date().toLocaleString()); const [menuList, setMenuList] = useState([]); const navigate = useNavigate(); const location = useLocation(); const { userInfo } = useSelector((state: RootState) => state.user); const dispatch = useAppDispatch(); const getMenu = () => { getMenuList().then(res => { if (res.code == 200) { setMenuList(res.data); } else { message.error("获取菜单失败:" + res.msg) } }) } useEffect(() => { const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000); getMenu(); return () => clearInterval(timer); }, []); const handleLogout = async () => { await dispatch(logout()); navigate('/login', { replace: true }); }; const menuItems = [ { key: '/', icon: , label: '总览首页', roles: ['admin', 'operator', 'viewer'] }, { key: '/devices', icon: , label: '设备管理', roles: ['admin', 'operator'] }, { key: '/video', icon: , label: '在线视频', roles: ['admin', 'operator', 'viewer'] }, { key: '/alerts', icon: , label: '告警中心', roles: ['admin', 'operator'] }, { key: '/downloads', icon: , label: '视频下载', roles: ['admin', 'operator'] }, { key: '/serialNumGenerate', icon: , label: '序列号生成', roles: ['admin'] }, { key: '/users', icon: , label: '用户管理', roles: ['admin'] }, { key: '/roles', icon: , label: '角色管理', roles: ['admin'] }, { key: '/menuList', icon: , label: '菜单管理', roles: ['admin'] }, { key: '/organization', icon: , label: '组织管理', roles: ['admin'] }, { key: '/station', icon: , label: '场站管理', roles: ['admin'] } ]; const filteredMenu = menuItems; const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '总览首页'; return ( {/* 顶部通栏 */}
Logo {!collapsed && ( 光伏电站智能监控与运维系统 )}
{time} {userInfo?.username}
{/* 左侧:菜单 + 下部区域 */} navigate(key)} /> {/* 左侧下方固定区域(你可以放任何内容) */}
{!collapsed && '快捷操作面板'}
{/* 右侧:主内容 */} ); }