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

fix: 清除事件重复注册

parent a6e5d230
...@@ -318,21 +318,43 @@ const BasicLayout = props => { ...@@ -318,21 +318,43 @@ const BasicLayout = props => {
useEffect(() => { useEffect(() => {
console.log(props.route.routes); console.log(props.route.routes);
}, [props.currentMenuIndex]); }, [props.currentMenuIndex]);
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]); useEffect(() => {
setSelectIndex(selectedIndex); window.share && window.share.event && window.share.event.on('event:updateCurrentChildrenRoutes', ({currentPath, currentRoute, selectedIndex}) => {
setTabActiveKey(currentPath) currentRoute && currentRoute.parent && currentRoute.parent.routes ? setChildrenRoutes(currentRoute.parent.routes): !currentRoute.parent ? setChildrenRoutes(currentRoute.routes): setChildrenRoutes([currentRoute]);
}); setSelectIndex(selectedIndex);
setTabActiveKey(currentPath)
window.share && window.share.event && window.share.event.on('event:favitor', ({icon, name, path}) => { });
setChildrenRoutes([
{ window.share && window.share.event && window.share.event.on('event:favitor', ({icon, name, path}) => {
icon: <HomeIcon/>, setChildrenRoutes([
path: path, {
name: name icon: <HomeIcon/>,
} path: path,
]) 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