Commit 2431d2f8 authored by 崔佳豪's avatar 崔佳豪

fix: 添加跳转菜单事件

parent ab768c93
Pipeline #55460 waiting for manual action with stages
......@@ -351,6 +351,37 @@ const Layout = (props) => {
props.global.transformDevAssetsBaseURL(props.global.get('bannerLogo'))
: defaultSetting.logo;
// 添加一个路由跳转事件
useEffect(() => {
const { share, history } = window;
const findMenuPath = (flatMenu, url) => {
const [path, param = ''] = url.split('|');
let params = param.split('&').reduce((pre, item) => {
if (!item) return pre;
const [key, value] = item.split('=');
pre[key] = value;
return pre;
}, {});
let menu = null;
if (params.widget) {
menu = flatMenu.find(item => item.params && item.params.widget === params.widget); // 根据widget匹配菜单
} else {
menu = flatMenu.find(item => item.path.indexOf(path) > -1); // 根据路径匹配菜单
}
return menu ? menu.path.replace(/^\//, '') : '';
};
const skipHandler = (data, title, url) => {
const targetMenuPath = findMenuPath(props.flatMenu, url);
if (targetMenuPath) {
history.pushState(data, title, `/civbase/${targetMenuPath}`);
}
}
share && share.event && share.event.on('route:pushState', skipHandler);
return () => {
share && share.event && share.event.removeListener('route:pushState', skipHandler);
}
}, []);
return (
<SecurityLayout {...props}>
<BasicLayout
......
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