Commit f7688fa3 authored by 崔佳豪's avatar 崔佳豪

fix: 清除事件重复注册

parent a6e5d230
...@@ -318,6 +318,8 @@ const BasicLayout = props => { ...@@ -318,6 +318,8 @@ const BasicLayout = props => {
useEffect(() => { useEffect(() => {
console.log(props.route.routes); console.log(props.route.routes);
}, [props.currentMenuIndex]); }, [props.currentMenuIndex]);
useEffect(() => {
window.share && window.share.event && window.share.event.on('event:updateCurrentChildrenRoutes', ({currentPath, currentRoute, selectedIndex}) => { window.share && window.share.event && window.share.event.on('event:updateCurrentChildrenRoutes', ({currentPath, currentRoute, selectedIndex}) => {
currentRoute && currentRoute.parent && currentRoute.parent.routes ? setChildrenRoutes(currentRoute.parent.routes): !currentRoute.parent ? setChildrenRoutes(currentRoute.routes): setChildrenRoutes([currentRoute]); currentRoute && currentRoute.parent && currentRoute.parent.routes ? setChildrenRoutes(currentRoute.parent.routes): !currentRoute.parent ? setChildrenRoutes(currentRoute.routes): setChildrenRoutes([currentRoute]);
setSelectIndex(selectedIndex); setSelectIndex(selectedIndex);
...@@ -332,7 +334,27 @@ const BasicLayout = props => { ...@@ -332,7 +334,27 @@ const BasicLayout = props => {
name: name name: name
} }
]) ])
}) });
window.share && window.share.event && window.share.event.on('goHome', url => {
setChildrenRoutes([
{
icon: <HomeIcon/>,
path: url,
name: '首页'
}
]);
setTabActiveKey(url);
window.history.pushState(null, '', `/civbase${url}`);
});
return () => {
window.share && window.share.event && window.share.event.removeAllListeners('event:updateCurrentChildrenRoutes');
window.share && window.share.event && window.share.event.removeAllListeners('event:favitor');
window.share && window.share.event && window.share.event.removeAllListeners('goHome');
};
}, []);
useEffect(() => { useEffect(() => {
siteAction.setGlobalConfig(props.global); siteAction.setGlobalConfig(props.global);
if (!Cookies.get('token')) { if (!Cookies.get('token')) {
...@@ -358,21 +380,6 @@ const BasicLayout = props => { ...@@ -358,21 +380,6 @@ const BasicLayout = props => {
}, [props.global]); }, [props.global]);
// setChildrenRoutes(currentChildrenRoute) // setChildrenRoutes(currentChildrenRoute)
window.share.event.on('goHome', url => {
setChildrenRoutes([
{
icon: <HomeIcon/>,
path: url,
name: '首页'
}
]);
setTabActiveKey(url);
window.history.pushState(null, '', `/civbase${url}`);
});
/** /**
* web4全屏退出,切换三级菜单高亮 * web4全屏退出,切换三级菜单高亮
*/ */
......
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