import type { MenuItem } from '../types.uts' export function findActiveByCurrentPage(menuList: MenuItem[], currentPage: string) { // currentPage 既可能是顶级菜单 id,也可能是子页面 id(如 user-list) // 返回:activeMenuId / activeSubId / activeGroupTitle for (const m of menuList) { if (m.id === currentPage) { return { activeMenuId: m.id, activeSubId: '', activeGroupTitle: '' } } const groups = m.groups || [] for (const g of groups) { for (const c of g.children) { if (c.id === currentPage) { return { activeMenuId: m.id, activeSubId: c.id, activeGroupTitle: g.title } } } } } return { activeMenuId: menuList[0]?.id || 'home', activeSubId: '', activeGroupTitle: '' } } export function getCurrentRoutePath(): string { // 使用页面栈获取当前路由(uni-app标准能力) // getCurrentPages 用于获取当前页面栈实例 :contentReference[oaicite:2]{index=2} const pages = getCurrentPages() const last: any = pages[pages.length - 1] // #ifdef H5 return last?.route ? `/${last.route}` : '' // #endif // #ifndef H5 // 小程序/App 可能是 route / $page?.fullPath 形式,按你项目实际字段微调 return last?.route ? `/${last.route}` : (last?.$page?.fullPath || '') // #endif }