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,44 +563,57 @@ const BasicLayout = props => { ...@@ -549,44 +563,57 @@ 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' }}>
<ul className={classNames(layoutStyles.menu)} style={{ minHeight: '0px', marginBottom: '0px' }}> {
<li className={classNames(layoutStyles['menu-item'])} onClick={handleToggleSystem}> <div style={{padding: currentRoutes && !currentRoutes.routes ? '20px 6px 6px 6px': '0px'}}><Skeleton loading={currentRoutes && !currentRoutes.routes} active title={false} paragraph={{
<Tooltip placement="right" title={collapse ? currentRoutes.name : ''}> rows: 10
<a> }}/>
{ {
(currentRoutes && currentRoutes.extData && currentRoutes.extData.icon) && <img src={currentRoutes.extData.icon} /> 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}>
collapse ? null : <span className={classNames(layoutStyles.text, layoutStyles.currentText)}>{currentRoutes && currentRoutes.name}</span> <Tooltip placement="right" title={collapse ? currentRoutes.name : ''}>
} <a>
</a> {
</Tooltip> (currentRoutes && currentRoutes.extData && currentRoutes.extData.icon) && <img src={currentRoutes.extData.icon} />
</li> }
</ul> {
<div className={layoutStyles.splitLine}></div> collapse ? null : <span className={classNames(layoutStyles.text, layoutStyles.currentText)}>{currentRoutes && currentRoutes.name}</span>
<ul className={classNames(layoutStyles.menu, 'menu-vertical')}> }
{ </a>
currentRoutes && (currentRoutes.routes || []).filter(item => !item.hideInMenu).map((item, index) => { </Tooltip>
return ( </li>
<React.Fragment key={index}> </ul>
<li key={index} className={classNames(layoutStyles['menu-item'], { [layoutStyles['active']]: index === selectIndex })} onClick={() => handlerSecond(item, index)}> <div className={layoutStyles.splitLine}></div>
<Tooltip placement="right" title={collapse ? item.name : ''}> <ul className={classNames(layoutStyles.menu, 'menu-vertical')}>
<a> {
{ currentRoutes && (currentRoutes.routes || []).filter(item => !item.hideInMenu).map((item, index) => {
item.icon ? item.icon : item.extData && /.svg/.test(item.extData.icon) ? <ReactSVG src={item.extData.icon} style={{ width: '20px', height: '20px' }} className={layoutStyles.icon} /> : item.extData && <img src={item.extData.icon} /> return (
} <React.Fragment key={index}>
{ <li key={index} className={classNames(layoutStyles['menu-item'], { [layoutStyles['active']]: index === selectIndex })} onClick={() => handlerSecond(item, index)}>
collapse ? item.extData && <span className={classNames(layoutStyles.text)}>{(item.extData.shortName || item.name).substr(0, 2)}</span> : <span className={classNames(layoutStyles.text)}>{item.name}</span> <Tooltip placement="right" title={collapse ? item.name : ''}>
} <a>
</a> {
</Tooltip> item.icon ? item.icon : item.extData && /.svg/.test(item.extData.icon) ? <ReactSVG src={item.extData.icon} style={{ width: '20px', height: '20px' }} className={layoutStyles.icon} /> : item.extData && <img src={item.extData.icon} />
</li> }
<Divider style={{ border: '1px solid rgb(49, 53, 62, 0.3)', margin: '0 auto', minWidth: '80%', width: '80%' }} /> {
</React.Fragment> collapse ? item.extData && <span className={classNames(layoutStyles.text)}>{(item.extData.shortName || item.name).substr(0, 2)}</span> : <span className={classNames(layoutStyles.text)}>{item.name}</span>
) }
}) </a>
} </Tooltip>
</ul> </li>
<Divider style={{ border: '1px solid rgb(49, 53, 62, 0.3)', margin: '0 auto', minWidth: '80%', width: '80%' }} />
</React.Fragment>
)
})
}
</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