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, SettingOutlined, LogoutOutlined } from '@ant-design/icons' import { getPageQuery } from '@/utils/utils' import menuTitle from '@/assets/img/memuTitle.png' import menuTitle1 from '@/assets/img/memuTitle1.png' import { CustomBreadcrumb } from '@/components/GlobalComponent' const SystemContentList = (props) => { const dynamicRoute = window.dynamicRoute console.log(dynamicRoute) const location = useLocation() const pathName = location.pathname const [openKey, setOpenKey] = useState([]) const [selectedKey, setSelectedKey] = useState([]) const [menuItems, setMenuItems] = useState([]) const [systemType, setSystemType] = useState('安全管理系统') let defaultKey = '' useEffect(() => { 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) }, [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 { 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