import React, { useState, useEffect } from 'react' import { history, Outlet, useLocation, matchRoutes, useModel } from '@umijs/max' import { Menu, Tabs, Select } from 'antd' import './SystemContentList.less' import { formatRoute, getDefaultRoute } from '@/utils/routeUtils' import styles from './TopNavBar.less' import { Row, Col, Avatar, Dropdown, Button } from 'antd' import { userInfo } from '@/utils/globalCommon' import { HomeOutlined, LogoutOutlined, AppstoreOutlined, UserOutlined, SettingOutlined, DatabaseOutlined, FileTextOutlined, LockOutlined, AreaChartOutlined, CaretDownOutlined, BellOutlined, SearchOutlined, QuestionCircleOutlined } from '@ant-design/icons' import { getPageQuery } from '@/utils/utils' import menuTitle from '@/assets/img/智能管控平台.svg' import menuTitle1 from '@/assets/img/智能管控平台-1.svg' import fireHydrant from '@/assets/img/fireHydrant.svg' import fireHydrant1 from '@/assets/img/fireHydrant1.svg' import fireKeynoteArea from '@/assets/img/fire_keynote_area.svg' import firewarning from '@/assets/img/icon_firewarning.svg' import trouble from '@/assets/img/trouble.svg' import book from '@/assets/img/book.svg' import danger from '@/assets/img/danger.svg' import danger1 from '@/assets/img/danger1.svg' import license from '@/assets/img/license.svg' import people from '@/assets/img/people.svg' import risk from '@/assets/img/risk.svg' import icon1 from '@/assets/img/icon1.svg' import { CustomBreadcrumb } from '@/components/GlobalComponent' // 自定义菜单项渲染组件,支持根据激活状态显示不同图片 const CustomMenuItem = ({ item, selectedKeys }) => { const isActive = selectedKeys.includes(item.key); // 为每个菜单项定义激活状态的图片 // 如果没有专门的激活状态图片,则使用默认图片 const getActiveIcon = (baseIcon) => { // 这里可以根据需要为每个图标定义对应的激活状态图片 // 目前暂时使用相同的图片,用户可以根据实际情况替换 return baseIcon; }; const renderIcon = () => { if (item.icon && typeof item.icon === 'object' && item.icon.props && item.icon.props.src) { const iconSrc = isActive ? getActiveIcon(item.icon.props.src) : item.icon.props.src; return {item.icon.props.alt } return item.icon; }; const renderMenuItem = (menuItem) => ({ ...menuItem, icon: renderIcon(), children: menuItem.children?.map(child => renderMenuItem(child)) }); return renderMenuItem(item); }; const SystemContentList = (props) => { const dynamicRoute = window.dynamicRoute const location = useLocation() const pathName = location.pathname const [openKey, setOpenKey] = useState([]) const [selectedKey, setSelectedKey] = useState([]) const [menuItems, setMenuItems] = useState([]) const [isMenuCollapsed, setIsMenuCollapsed] = useState(false); // 添加菜单收缩状态 let defaultKey = '' useEffect(() => { console.log('dynamicRoute structure:', dynamicRoute) if (!dynamicRoute || dynamicRoute?.length === 0) return let newList = [] let routes = [] if (dynamicRoute?.length) { let tempRoute = dynamicRoute?.filter(item => pathName.indexOf(item.key) !== -1) ?? [] newList = formatRoute(tempRoute[0]?.children) routes = formatRoute(tempRoute[0]?.children, true) defaultKey = getDefaultRoute(routes) const mathRoute = matchRoutes(routes, pathName) setRouteActive({ key: mathRoute?.length ? pathName : defaultKey }, routes) } setMenuItems(newList) const fixedMenuItems = [ { path: '/topnavbar00/business/homepage', icon: 首页, key: "/topnavbar00/business/homepage", "label": "首页" }, { path: '/topnavbar00/business/assetmanagement', icon: 资产管理, key: "/topnavbar00/business/assetmanagement", "label": "资产管理", children: [ { path: '/topnavbar00/business/assetmanagement/assetlist', key: "/topnavbar00/business/assetmanagement/assetlist", "label": "资产列表" }, { path: '/topnavbar00/business/assetmanagement/assetgrouping', key: "/topnavbar00/business/assetmanagement/assetgrouping", "label": "资产分组" }, // 资产属性定义 { path: '/topnavbar00/business/assetmanagement/assetdefined', key: "/topnavbar00/business/assetmanagement/assetdefined", "label": "资产属性定义" }, { path: '/topnavbar00/business/assetmanagement/maintenance', key: "/topnavbar00/business/assetmanagement/maintenance", "label": "维保管理" }, ] }, // 设备监控 { path: '/topnavbar00/business/devicemonitoring', icon: 设备监控, key: "/topnavbar00/business/devicemonitoring", "label": "设备监控", children: [ { path: '/topnavbar00/business/devicemonitoring/statemanagement', key: "/topnavbar00/business/devicemonitoring/statemanagement", "label": "状态管理" }, // 设备地图 { path: '/topnavbar00/business/devicemonitoring/devicemap', key: "/topnavbar00/business/devicemonitoring/devicemap", "label": "设备地图" }, // 视频监控 { path: '/topnavbar00/business/devicemonitoring/video', key: "/topnavbar00/business/devicemonitoring/video", "label": "视频监控" }, ] }, // 运维工单 { path: '/topnavbar00/business/serviceticket', icon: 运维工单, key: "/topnavbar00/business/serviceticket", "label": "运维工单", children: [ { path: '/topnavbar00/business/serviceticket/list', key: "/topnavbar00/business/serviceticket/list", "label": "工单列表" }, { path: '/topnavbar00/business/serviceticket/todo', key: "/topnavbar00/business/serviceticket/todo", "label": "代办工单" }, { path: '/topnavbar00/business/serviceticket/history', key: "/topnavbar00/business/serviceticket/history", "label": "已办工单" }, { path: '/topnavbar00/business/serviceticket/my', key: "/topnavbar00/business/serviceticket/my", "label": "我的工单" }, { path: '/topnavbar00/business/serviceticket/analysis', key: "/topnavbar00/business/serviceticket/analysis", "label": "统计分析" }, ] }, { path: '/topnavbar00/business/inspection', icon: 智能巡检, key: "/topnavbar00/business/inspection", "label": "智能巡检", children: [ { path: '/topnavbar00/business/inspection/inspectionTemplate', key: "/topnavbar00/business/inspection/inspectionTemplate", "label": "巡检模板" }, // 巡检任务 { path: '/topnavbar00/business/inspection/inspectionTasks', key: "/topnavbar00/business/inspection/inspectionTasks", "label": "巡检任务" }, // 巡检记录 { path: '/topnavbar00/business/inspection/inspectionRecords', key: "/topnavbar00/business/inspection/inspectionRecords", "label": "巡检记录" }, ] } ] setMenuItems(fixedMenuItems) // 初始化默认路由 const defaultRoute = fixedMenuItems[0]?.key || '' const mathRoute = matchRoutes(fixedMenuItems, pathName) setRouteActive({ key: mathRoute?.length ? pathName : defaultRoute }, fixedMenuItems) }, [pathName]) const setRouteActive = (value, menu) => { const curKey = value.key const tempMenu = menu ?? menuItems ?? [] const mathRoute = matchRoutes(tempMenu, curKey) let openKeys = [] let selectedKeys = [] mathRoute?.map((item, index) => { mathRoute?.length !== index + 1 && (openKeys = [...openKeys, item.pathname]) mathRoute?.length === index + 1 && (selectedKeys = [...selectedKeys, item.pathname]) }) setOpenKey(openKeys) setSelectedKey(selectedKeys) history.replace(curKey) } const selectChange = (value) => { console.log(value) window.location.href = 'http://localhost:8888/' } // 切换菜单收缩状态 const toggleMenu = () => { setIsMenuCollapsed(!isMenuCollapsed); }; const { initialState: { menu }, setInitialState } = useModel('@@initialState') const loginOut = async () => { // await outLogin() const { redirect } = getPageQuery() if (window.location.pathname !== '/login/login' && !redirect) { history.replace({ pathname: '/login', // search: stringify({ // redirect: window.location.href, // }), }) setInitialState({ currentUser: null, menu: null, menuMap: null }) window.dynamicRoute = null localStorage.clear() } } const handleMenuClick = (e) => { switch (e.key) { case 'logout': loginOut() break default: break } } const dropDownMenuItems = [ { label: <>退出登录, key: 'logout' } ] const dropDownMenu = () => ( ) return (
menuTitle menuTitle1
{/* 菜单收缩按钮 */} { const isActive = selectedKey.includes(item.key); // 处理当前项的图标 let icon = item.icon; if (icon && typeof icon === 'object' && icon.props && icon.props.src) { let iconSrc = icon.props.src; // 根据激活状态切换不同的图片 if (isActive) { // 工时仪表盘:激活态使用fireHydrant1 if (item.key === '/topnavbar00/business/timesheet' && typeof fireHydrant !== 'undefined') { iconSrc = fireHydrant; } // 隐患排查:激活态使用danger1 else if (item.key === '/topnavbar00/business/hiddentrouble' && typeof danger1 !== 'undefined') { iconSrc = danger1; } // 激活态使用danger1 else if (item.key === '/topnavbar00/business/staffsheet' && typeof danger1 !== 'undefined') { iconSrc = danger1; } } icon = {icon.props.alt}; } // 递归处理子项 const children = item.children?.map(child => { const childIsActive = selectedKey.includes(child.key); return { ...child }; }); return { ...item, icon, children, // 根据菜单收缩状态决定是否显示标签文本 label: isMenuCollapsed ? null : item.label }; })} onClick={value => setRouteActive(value)} onOpenChange={value => setOpenKey(value)} mode={isMenuCollapsed ? 'vertical' : 'inline'} />
{/*
*/}
{/* logo setRouteActive(value)} /> */} {userInfo?.user_name_cn ? userInfo.user_name_cn : (userInfo?.user_name || '')}
{/*
*/}
) } export default SystemContentList