import React, { useState, useEffect } from 'react'; import { Outlet, useNavigate, useLocation } from 'react-router-dom'; import { Layout, Menu, Button, Space, ConfigProvider, theme, Select, Avatar, Card, Tag } from 'antd'; import zhCN from 'antd/locale/zh_CN'; import { DashboardOutlined, ExperimentOutlined, VideoCameraOutlined, BellOutlined, UserOutlined, LogoutOutlined, AppstoreOutlined, SettingOutlined, MenuUnfoldOutlined, MenuFoldOutlined } 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 { setCurrentStation, clearStation } from '../store/stationSlice'; import { getMenuList } from '../api/mune'; import { getStationList } from '../api/stationManage'; import envConfig from '../../env'; 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 [stationList, setStationList] = useState([]); const navigate = useNavigate(); const location = useLocation(); const dispatch = useAppDispatch(); const { userInfo } = useSelector((state: RootState) => state.user); const { currentStation, stationId } = useSelector((state: RootState) => state.station); const getStationData = () => { const params = { pageNum: 1, pageSize: 9999, orgId: userInfo?.orgId, }; getStationList(params).then(res => { if (res.code === 200) { const list = res.rows || []; setStationList(list); if (!currentStation && list.length > 0) { dispatch(setCurrentStation(list[0])); } } }); }; const handleStationChange = (id: number) => { const station = stationList.find(s => s.id === id); if (station) { dispatch(setCurrentStation(station)); } }; const getMenu = () => { const data = { pageNum: 1, pageSize: 10000 }; getMenuList(data).then(res => { if (res.code == 200) { const rawList = res.rows || []; const topMenus = rawList.filter(item => item.parentId === 0); setMenuList(topMenus); } }); }; const getIcon = (path) => { if (path.includes('overview')) return ; if (path.includes('device')) return ; if (path.includes('monitor')) return ; if (path.includes('alert')) return ; if (path.includes('user')) return ; if (path.includes('system')) return ; if (path.includes('menu')) return ; return ; }; const menuItems = menuList.map(item => ({ key: item.path || `/menu/${item.menuId}`, icon: getIcon(item.path), label: item.menuName, })); const handleLogout = async () => { await dispatch(logout()); dispatch(clearStation()); navigate('/login', { replace: true }); }; useEffect(() => { const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000); getMenu(); getStationData(); return () => clearInterval(timer); }, [userInfo]); return (