Commit 3cc9cb18 authored by 曾婧's avatar 曾婧

fix: hn主题菜单保持只展开一个子菜单

parent b259eef9
...@@ -5,6 +5,7 @@ import { ReactSVG } from 'react-svg'; ...@@ -5,6 +5,7 @@ import { ReactSVG } from 'react-svg';
import useMergedState from 'rc-util/lib/hooks/useMergedState'; import useMergedState from 'rc-util/lib/hooks/useMergedState';
import { useHistory } from '@wisdom-utils/runtime'; import { useHistory } from '@wisdom-utils/runtime';
import ProLayout, { getPageTitle } from '@ant-design/pro-layout'; import ProLayout, { getPageTitle } from '@ant-design/pro-layout';
import { findPathByWidget } from '@wisdom-utils/components/lib/AppLayout/helpers';
const LoadingSkeleton = props => { const LoadingSkeleton = props => {
const { route } = props; const { route } = props;
return ( return (
...@@ -17,9 +18,10 @@ const LoadingSkeleton = props => { ...@@ -17,9 +18,10 @@ const LoadingSkeleton = props => {
}; };
const Menu = props => { const Menu = props => {
const { prefixCls, collapsed, onCollapse, onMenuClick, menuHeaderRender, onMenuHeaderClick } = props; const { prefixCls, collapsed, onCollapse, onMenuClick, menuHeaderRender, onMenuHeaderClick } = props;
const [pathname, setPathname] = useState('');
const { route } = props; const { route } = props;
const history = useHistory(); const history = useHistory();
const [activeMenu, setActiveMenu] = useState("首页"); const [activeMenu, setActiveMenu] = useState('首页');
const [sunRoute, setsunRoute] = useState(route); const [sunRoute, setsunRoute] = useState(route);
const [selectIndex, setSelectIndex] = useMergedState(() => -1, { const [selectIndex, setSelectIndex] = useMergedState(() => -1, {
value: props.active, value: props.active,
...@@ -43,7 +45,7 @@ const Menu = props => { ...@@ -43,7 +45,7 @@ const Menu = props => {
current = item; current = item;
childrenRoutes = [item]; childrenRoutes = [item];
} }
setPathname(current.path);
setSelectIndex(index); setSelectIndex(index);
if (/iframe/.test(current.path)) { if (/iframe/.test(current.path)) {
history.push({ history.push({
...@@ -55,16 +57,13 @@ const Menu = props => { ...@@ -55,16 +57,13 @@ const Menu = props => {
} }
onMenuClick && onMenuClick(current, childrenRoutes, index); onMenuClick && onMenuClick(current, childrenRoutes, index);
}; };
useEffect(() => { useEffect(()=>{
let all=props.flatMenu; var allWidgets = window.globalConfig && window.globalConfig.allWidgets;
all.forEach((it)=>{ let homgUrl=props.config && props.config.homepage.replace(/(civ_energy\/)/g,'');
if(it.path===props.location.pathname){ let curItem = findPathByWidget(homgUrl, allWidgets, '', 'url');
setActiveMenu(it.name) curItem&&setActiveMenu(curItem.label);
return; curItem&&setPathname(curItem.path)
} },[])
})
}, [props.location.pathname]);
useEffect(() => { useEffect(() => {
if (route && route.routes) { if (route && route.routes) {
setsunRoute(route); setsunRoute(route);
...@@ -120,6 +119,9 @@ const Menu = props => { ...@@ -120,6 +119,9 @@ const Menu = props => {
defaultCollapsed={false} defaultCollapsed={false}
collapsed={false} collapsed={false}
breakpoint={'xs'} breakpoint={'xs'}
location={{
pathname,
}}
// onHeaderLogo={handlerIndustry} // onHeaderLogo={handlerIndustry}
// onPageChange={handlerPageChange} // onPageChange={handlerPageChange}
// onMenuPanelItemClick={handleUpdateCurrentIndex} // onMenuPanelItemClick={handleUpdateCurrentIndex}
...@@ -188,7 +190,7 @@ export default props => { ...@@ -188,7 +190,7 @@ export default props => {
// className={classNames(`${prefixCls}`, `${prefixCls}-fixed`, { // className={classNames(`${prefixCls}`, `${prefixCls}-fixed`, {
// [`${prefixCls}-collapsed`]: collapsed, // [`${prefixCls}-collapsed`]: collapsed,
// })} // })}
style={{paddingTop:'50px'}} style={{ paddingTop: '50px' }}
> >
<div className={`${prefixCls}-children`}> <div className={`${prefixCls}-children`}>
<div className={`${prefixCls}-wrapper`} style={{ flex: '1 1 0%', overflow: 'hidden auto' }}> <div className={`${prefixCls}-wrapper`} style={{ flex: '1 1 0%', overflow: 'hidden auto' }}>
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
} }
.hnlayout { .hnlayout {
:global { :global {
.@{ant-prefix}-menu-dark.@{ant-prefix}-menu-dark:not(.@{ant-prefix}-menu-horizontal) .@{ant-prefix}-menu-item-selected{
background: transparent!important;
}
.@{ant-prefix}-global-page-header-header { .@{ant-prefix}-global-page-header-header {
padding-left: 0; padding-left: 0;
} }
......
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