Commit 06b476a4 authored by 邓晓峰's avatar 邓晓峰

fix: 修复菜单没有加载情况

parent 6db8af2d
Pipeline #46834 passed with stages
in 9 minutes 2 seconds
......@@ -19,6 +19,7 @@ import {
Menu,
Tooltip,
ConfigProvider,
Skeleton
} from 'antd';
// import { RouteWithSubRoutes, renderRoutes } from '../utils/routes';
// import { renderRoutes } from 'react-router-config';
......@@ -258,7 +259,7 @@ const BasicLayout = props => {
const [childrenRoutes, setChildrenRoutes] = useState([]);
const [selectedKeys, setSelectedKeys] = useState([]);
const [tabActiveKey, setTabActiveKey] = useState("1");
// const [currentRoutes, setCurrentRoutes] = useState([]);
const [currentRoutes, setCurrentRoutes] = useState({});
const [siteAction, setSiteAction] = useState(
() => new Site(props, setSiteLoading),
);
......@@ -267,9 +268,21 @@ const BasicLayout = props => {
const history = useHistory();
// 处理隐藏菜单
let currentRoutes = props.route.routes.filter(item => !item.hideInMenu)[props.currentMenuIndex];
useEffect(() => {
const newRoutes = props.route.routes.filter(item => !item.hideInMenu)[props.currentMenuIndex] || {};
if(!_.isEqual(currentRoutes, newRoutes)) {
setCurrentRoutes({})
setSelectIndex(-1);
setCurrentRoutes( newRoutes)
}
}, [props.route]);
// let currentRoutes = props.route.routes.filter(item => !item.hideInMenu)[props.currentMenuIndex];
//props.currentMenuIndex
useEffect(() => {
const initSelectRoute = findPathByLeafId(
`${props.location && props.location.pathname || ''}`,
[currentRoutes],
......@@ -304,6 +317,7 @@ const BasicLayout = props => {
if(!props.global.get('home')) {
url = `civweb4/${url.replace(/^\//, '').replace(/^civweb4\//, '')}`
}
setSelectIndex(-1)
setChildrenRoutes([
{
icon: <HomeIcon/>,
......@@ -383,7 +397,7 @@ const BasicLayout = props => {
* web4全屏退出,切换三级菜单高亮
*/
useEffect(() => {
if (selectIndex !== -1) {
if (selectIndex !== -1 && currentRoutes && currentRoutes.hasOwnProperty('routes')) {
const routes = currentRoutes.routes[selectIndex];
if (routes) {
if (routes && routes.routes) {
......@@ -471,7 +485,7 @@ const BasicLayout = props => {
}
const handlerSelectMenu = ({ item, key, keyPath, domEvent }) => {
debugger
setSelectedKeys([key]);
window.history.pushState(null, '', `/civbase${key}`);
}
......@@ -549,6 +563,12 @@ const BasicLayout = props => {
})}>
<div className={layoutStyles['layout-slider-childern']}>
<div className={layoutStyles.sliderMenu} style={{ flex: '1 1 0%', overflow: 'hidden auto' }}>
{
<div style={{padding: currentRoutes && !currentRoutes.routes ? '20px 6px 6px 6px': '0px'}}><Skeleton loading={currentRoutes && !currentRoutes.routes} active title={false} paragraph={{
rows: 10
}}/>
{
currentRoutes && currentRoutes.routes && currentRoutes.routes.length > 0 && <React.Fragment>
<ul className={classNames(layoutStyles.menu)} style={{ minHeight: '0px', marginBottom: '0px' }}>
<li className={classNames(layoutStyles['menu-item'])} onClick={handleToggleSystem}>
<Tooltip placement="right" title={collapse ? currentRoutes.name : ''}>
......@@ -587,6 +607,13 @@ const BasicLayout = props => {
})
}
</ul>
</React.Fragment>
}
</div>
}
</div>
<div className="ant-pro-sider-links" >
<ul className="ant-menu ant-menu-root ant-menu-inline ant-menu-dark ant-pro-sider-link-menu" role="menu" tabIndex="0" >
......
......@@ -139,7 +139,7 @@ export const initMicroApps = () => {
loose: true,
},
singular: false,
scopedCSS: false,
scopedCSS: true,
prefetch: 'all',
// eslint-disable-next-line no-underscore-dangle
// getPublicPath: window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment