From 462a54c0f4c34958657eb5eda2dff07b2990c11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=B9=8F?= Date: Fri, 10 Jul 2026 16:12:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=90=BA=E5=B8=A6=E8=8F=9C=E5=8D=95=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/user.store.ts | 2 +- src/utils/navigation/index.ts | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/store/modules/user.store.ts b/src/store/modules/user.store.ts index 6b8a9ff..02059da 100644 --- a/src/store/modules/user.store.ts +++ b/src/store/modules/user.store.ts @@ -238,7 +238,7 @@ export const useUserStore = defineStore( const response = await UserAPI.getCurrentUserInfo(); const data = response.data.data; const menus: MenuTable[] = data?.menus || []; - delete data?.menus; + // delete data?.menus; info.value = { ...info.value, ...data } as Partial; setRoute(menus); } catch (error) { diff --git a/src/utils/navigation/index.ts b/src/utils/navigation/index.ts index a822146..921d5f2 100644 --- a/src/utils/navigation/index.ts +++ b/src/utils/navigation/index.ts @@ -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 = {}; + 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 }); }; /**