完善页面
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
:activeMenuTitle="activeMenuTitle"
|
||||
:groups="activeGroups"
|
||||
:activeSubId="activeSubId"
|
||||
:activeMenuId="activeMenuId || 'home'"
|
||||
:asideWidth="ASIDE_W"
|
||||
:siderWidth="SUB_W"
|
||||
@sub-click="onSubClick"
|
||||
@@ -63,7 +64,7 @@ import AdminFooter from './components/AdminFooter.uvue'
|
||||
import { menuList as menuConst } from './utils/menu.uts'
|
||||
import { findActiveByCurrentPage, getCurrentRoutePath } from './utils/nav.uts'
|
||||
import { makeTabFromPath, upsertTab, removeTab } from './utils/tabs.uts'
|
||||
import type { MenuItem, TabItem } from './types.uts'
|
||||
import type { MenuItem, TabItem , MenuChild } from './types.uts'
|
||||
|
||||
// 你页面传进来的 currentPage:可能是顶级 id,也可能是子页面 id(user-list)
|
||||
const props = defineProps<{ currentPage: string }>()
|
||||
@@ -115,19 +116,24 @@ syncTabsByRoute()
|
||||
// computed
|
||||
const activeMenu = computed(() => menuList.value.find(m => m.id === activeMenuId.value))
|
||||
const activeMenuTitle = computed(() => activeMenu.value?.title || '商城后台')
|
||||
const activeGroups = computed(() => activeMenu.value?.groups || [])
|
||||
const activeGroups = computed(() => {
|
||||
const m = menuList.value.find(it => it.id === activeMenuId.value)
|
||||
return m?.groups ?? [] // ✅ 永远是数组
|
||||
})
|
||||
|
||||
|
||||
const breadcrumb = computed(() => {
|
||||
// “一级 / 二级”
|
||||
let subTitle = ''
|
||||
const groups = activeGroups.value
|
||||
for (const g of groups) {
|
||||
const hit = g.children.find(c => c.id === activeSubId.value)
|
||||
const cs = g.children ?? []
|
||||
const hit = cs.find(c => c.id === activeSubId.value)
|
||||
if (hit) { subTitle = hit.title; break }
|
||||
}
|
||||
return subTitle ? `${activeMenuTitle.value} / ${subTitle}` : `${activeMenuTitle.value}`
|
||||
})
|
||||
|
||||
|
||||
// handlers
|
||||
const toggleCollapse = () => {
|
||||
isCollapsed.value = !isCollapsed.value
|
||||
@@ -153,27 +159,54 @@ const firstLeafOfMenu = (m: MenuItem): MenuChild | null => {
|
||||
return g0.children[0]
|
||||
}
|
||||
|
||||
const go = (url: string) => {
|
||||
// 你明确要用 navigateTo:页面栈会增长(这是正常行为):contentReference[oaicite:4]{index=4}
|
||||
uni.navigateTo({ url })
|
||||
let navigating = false
|
||||
|
||||
const go = async (url?: string | null) => {
|
||||
if (!url || url.length === 0) return
|
||||
if (navigating) return
|
||||
navigating = true
|
||||
try {
|
||||
await uni.navigateTo({ url })
|
||||
} catch (e) {
|
||||
// 可选:忽略取消类报错,避免控制台刷屏
|
||||
} finally {
|
||||
setTimeout(() => { navigating = false }, 80)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const onMenuClick = (menuId: string) => {
|
||||
const m = menuList.value.find(x => x.id === menuId)
|
||||
if (!m) return
|
||||
|
||||
activeMenuId.value = m.id
|
||||
// 默认激活该菜单第一个子项
|
||||
const g0 = (m.groups && m.groups.length > 0) ? m.groups[0] : null
|
||||
const c0 = g0 && g0.children.length > 0 ? g0.children[0] : null
|
||||
activeSubId.value = c0 ? c0.id : ''
|
||||
go(m.path)
|
||||
|
||||
const leaf = firstLeafOfMenu(m)
|
||||
activeSubId.value = leaf ? leaf.id : ''
|
||||
|
||||
// ✅ 优先 leaf.path,其次才考虑 m.path
|
||||
go(leaf?.path ?? m.path ?? '')
|
||||
}
|
||||
|
||||
const firstLeafInChildren = (list?: MenuChild[] | null): MenuChild | null => {
|
||||
const arr = list ?? []
|
||||
if (arr.length === 0) return null
|
||||
const n = arr[0]
|
||||
const deep = n.children ?? []
|
||||
return deep.length > 0 ? firstLeafInChildren(deep) : n
|
||||
}
|
||||
|
||||
const onSubClick = (c: MenuChild) => {
|
||||
activeSubId.value = c.id
|
||||
go(c.path)
|
||||
if (c.path && c.path.length > 0) {
|
||||
go(c.path)
|
||||
} else {
|
||||
const leaf = firstLeafInChildren(c.children)
|
||||
go(leaf?.path ?? '')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const onTabClick = (tab: TabItem) => {
|
||||
activeTabId.value = tab.id
|
||||
go(tab.path)
|
||||
@@ -216,6 +249,6 @@ const onNotify = () => uni.showToast({ title: '通知', icon: 'none' })
|
||||
height: calc(100vh - 56px - 44px);
|
||||
}
|
||||
.content-inner{
|
||||
padding: 16px;
|
||||
padding:5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user