diff --git a/src/utils/permissionMenu.js b/src/utils/permissionMenu.js index f561a8b..c720c13 100644 --- a/src/utils/permissionMenu.js +++ b/src/utils/permissionMenu.js @@ -190,15 +190,19 @@ export function getDynamicTabMenus(menus) { return getTopLevelMenus(menus).filter((menu) => !looksLikeHomeMenu(menu)) } +function normalizePagePath(value) { + const path = String(value || '').trim().replace(/^\/+/, '') + return path ? `/${path}` : '' +} + export function findTabMenuByPage(menus, pagePath) { const dynamicMenus = getDynamicTabMenus(menus) - if (pagePath === 'pages/report') { - return dynamicMenus[0] || null - } - if (pagePath === 'pages/work') { - return dynamicMenus[1] || dynamicMenus[0] || null + const targetPath = normalizePagePath(pagePath) + if (!targetPath) { + return null } - return null + + return dynamicMenus.find((menu) => normalizePagePath(resolveMenuUrl(menu)) === targetPath) || null } export function buildPageModules(tabMenu) { @@ -254,11 +258,12 @@ export function getMenuSymbol(name, index) { } export function syncTabBarMenus(menus, options = {}) { - const dynamicMenus = getDynamicTabMenus(menus) + const reportMenu = findTabMenuByPage(menus, 'pages/report') + const workMenu = findTabMenuByPage(menus, 'pages/work') return [ options.homeText || '首页', - dynamicMenus[0]?.name || options.reportFallback || '报表', - dynamicMenus[1]?.name || dynamicMenus[0]?.name || options.workFallback || '管理', + reportMenu?.name || options.reportFallback || '报表', + workMenu?.name || reportMenu?.name || options.workFallback || '管理', options.mineText || '我的' ] }