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

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

parent 6db8af2d
Pipeline #46834 passed with stages
in 9 minutes 2 seconds
...@@ -19,6 +19,7 @@ import { ...@@ -19,6 +19,7 @@ import {
Menu, Menu,
Tooltip, Tooltip,
ConfigProvider, ConfigProvider,
Skeleton
} from 'antd'; } from 'antd';
// import { RouteWithSubRoutes, renderRoutes } from '../utils/routes'; // import { RouteWithSubRoutes, renderRoutes } from '../utils/routes';
// import { renderRoutes } from 'react-router-config'; // import { renderRoutes } from 'react-router-config';
...@@ -258,7 +259,7 @@ const BasicLayout = props => { ...@@ -258,7 +259,7 @@ const BasicLayout = props => {
const [childrenRoutes, setChildrenRoutes] = useState([]); const [childrenRoutes, setChildrenRoutes] = useState([]);
const [selectedKeys, setSelectedKeys] = useState([]); const [selectedKeys, setSelectedKeys] = useState([]);
const [tabActiveKey, setTabActiveKey] = useState("1"); const [tabActiveKey, setTabActiveKey] = useState("1");
// const [currentRoutes, setCurrentRoutes] = useState([]); const [currentRoutes, setCurrentRoutes] = useState({});
const [siteAction, setSiteAction] = useState( const [siteAction, setSiteAction] = useState(
() => new Site(props, setSiteLoading), () => new Site(props, setSiteLoading),
); );
...@@ -267,9 +268,21 @@ const BasicLayout = props => { ...@@ -267,9 +268,21 @@ const BasicLayout = props => {
const history = useHistory(); 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 //props.currentMenuIndex
useEffect(() => { useEffect(() => {
const initSelectRoute = findPathByLeafId( const initSelectRoute = findPathByLeafId(
`${props.location && props.location.pathname || ''}`, `${props.location && props.location.pathname || ''}`,
[currentRoutes], [currentRoutes],
...@@ -304,6 +317,7 @@ const BasicLayout = props => { ...@@ -304,6 +317,7 @@ const BasicLayout = props => {
if(!props.global.get('home')) { if(!props.global.get('home')) {
url = `civweb4/${url.replace(/^\//, '').replace(/^civweb4\//, '')}` url = `civweb4/${url.replace(/^\//, '').replace(/^civweb4\//, '')}`
} }
setSelectIndex(-1)
setChildrenRoutes([ setChildrenRoutes([
{ {
icon: <HomeIcon/>, icon: <HomeIcon/>,
...@@ -383,7 +397,7 @@ const BasicLayout = props => { ...@@ -383,7 +397,7 @@ const BasicLayout = props => {
* web4全屏退出,切换三级菜单高亮 * web4全屏退出,切换三级菜单高亮
*/ */
useEffect(() => { useEffect(() => {
if (selectIndex !== -1) { if (selectIndex !== -1 && currentRoutes && currentRoutes.hasOwnProperty('routes')) {
const routes = currentRoutes.routes[selectIndex]; const routes = currentRoutes.routes[selectIndex];
if (routes) { if (routes) {
if (routes && routes.routes) { if (routes && routes.routes) {
...@@ -471,7 +485,7 @@ const BasicLayout = props => { ...@@ -471,7 +485,7 @@ const BasicLayout = props => {
} }
const handlerSelectMenu = ({ item, key, keyPath, domEvent }) => { const handlerSelectMenu = ({ item, key, keyPath, domEvent }) => {
debugger
setSelectedKeys([key]); setSelectedKeys([key]);
window.history.pushState(null, '', `/civbase${key}`); window.history.pushState(null, '', `/civbase${key}`);
} }
...@@ -549,6 +563,12 @@ const BasicLayout = props => { ...@@ -549,6 +563,12 @@ const BasicLayout = props => {
})}> })}>
<div className={layoutStyles['layout-slider-childern']}> <div className={layoutStyles['layout-slider-childern']}>
<div className={layoutStyles.sliderMenu} style={{ flex: '1 1 0%', overflow: 'hidden auto' }}> <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' }}> <ul className={classNames(layoutStyles.menu)} style={{ minHeight: '0px', marginBottom: '0px' }}>
<li className={classNames(layoutStyles['menu-item'])} onClick={handleToggleSystem}> <li className={classNames(layoutStyles['menu-item'])} onClick={handleToggleSystem}>
<Tooltip placement="right" title={collapse ? currentRoutes.name : ''}> <Tooltip placement="right" title={collapse ? currentRoutes.name : ''}>
...@@ -587,6 +607,13 @@ const BasicLayout = props => { ...@@ -587,6 +607,13 @@ const BasicLayout = props => {
}) })
} }
</ul> </ul>
</React.Fragment>
}
</div>
}
</div> </div>
<div className="ant-pro-sider-links" > <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" > <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 = () => { ...@@ -139,7 +139,7 @@ export const initMicroApps = () => {
loose: true, loose: true,
}, },
singular: false, singular: false,
scopedCSS: false, scopedCSS: true,
prefetch: 'all', prefetch: 'all',
// eslint-disable-next-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle
// getPublicPath: window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__, // 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