|
|
|
|
@ -67,13 +67,38 @@ export const getFirstMenuPath = (menuList: AppRouteRecordFromTypes[]): string =>
|
|
|
|
|
return "";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** 在菜单树中递归查找 route_name 匹配的菜单项 */
|
|
|
|
|
const findMenuByRouteName = (menus: any[], routeName: string): any | null => {
|
|
|
|
|
for (const menu of menus) {
|
|
|
|
|
if (menu.route_name === routeName) return menu;
|
|
|
|
|
if (menu.children?.length) {
|
|
|
|
|
const found = findMenuByRouteName(menu.children, routeName);
|
|
|
|
|
if (found) return found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const openExternalLink = (link: string) => window.open(link, "_blank");
|
|
|
|
|
|
|
|
|
|
export const handleMenuJump = (item: AppRouteRecord, jumpToFirst: boolean = false) => {
|
|
|
|
|
export const handleMenuJump = async (item: AppRouteRecord, jumpToFirst: boolean = false) => {
|
|
|
|
|
// 在其他函数内部动态获取,避免模块加载时的循环依赖
|
|
|
|
|
const { useUserStoreHook } = await import("@stores");
|
|
|
|
|
const userStore = useUserStoreHook();
|
|
|
|
|
|
|
|
|
|
// 从菜单树中查找当前 item.name(对应 route_name)的菜单项,提取 params 转为 query 参数
|
|
|
|
|
const targetMenu = findMenuByRouteName(userStore.info.menus || [], item.name as string);
|
|
|
|
|
const query: Record<string, string> = {};
|
|
|
|
|
if (targetMenu?.params) {
|
|
|
|
|
for (const p of targetMenu.params) {
|
|
|
|
|
query[p.key] = p.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { link, isIframe: menuIsIframe } = item.meta;
|
|
|
|
|
if (link && !menuIsIframe) return openExternalLink(link);
|
|
|
|
|
|
|
|
|
|
if (!jumpToFirst || !item.children?.length) return router.push(item.path);
|
|
|
|
|
if (!jumpToFirst || !item.children?.length) return router.push({ path: item.path, query });
|
|
|
|
|
|
|
|
|
|
const findFirstLeafMenu = (items: AppRouteRecord[]): AppRouteRecord | undefined => {
|
|
|
|
|
for (const child of items) {
|
|
|
|
|
@ -85,9 +110,9 @@ export const handleMenuJump = (item: AppRouteRecord, jumpToFirst: boolean = fals
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const firstChild = findFirstLeafMenu(item.children);
|
|
|
|
|
if (!firstChild) return router.push(item.path);
|
|
|
|
|
if (!firstChild) return router.push({ path: item.path, query });
|
|
|
|
|
if (firstChild.meta?.link) return openExternalLink(firstChild.meta.link);
|
|
|
|
|
return router.push(firstChild.path);
|
|
|
|
|
return router.push({ path: firstChild.path, query });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|