Files
medical-mall/layouts/admin/utils/nav.uts
2026-01-27 20:02:57 +08:00

35 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}