perf:菜单遍历逻辑优化,不固定索引获取菜单

master
黄伟杰 2 weeks ago
parent 08fe076728
commit aff935a30d

@ -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 || '我的'
]
}

Loading…
Cancel
Save