feat(admin): 侧边栏父菜单默认全展开+mount 断言对齐标题去后缀(2026-11-17 用户口径「父菜单不要默认折叠」)——menu-mapper 的 groupKeysForActive(按激活路由命中展开)换 allGroupKeys(全部分组);AdminLayout 对 entries 变更命令式补开(el-menu 的 default-openeds 只在挂载读一次,平台 tab 切换/菜单树刷新后新分组不会自动展开;watch 里读当下 computed 而非触发快照,快速连切 tab 不补开已离开渲染树的旧分组——el-menu 的 open 对未注册 index 会抛);用户手动收起的组在 entries 不变期间保持收起。判据:task-6 8 例(allGroupKeys 全展开/顶级叶不产键/空菜单空键+壳层绊线:groupKeysForActive 回流即红、watch(openedKeys)+nextTick 缺一即红);mount 京东页「分类管理」断言对齐 ea9dca3f 标题去后缀(那笔漏改的存量红);vue-tsc rc=0;node --test 1932/1933(唯一红=在册 B116-03 ENOENT);vitest mount 180/180;ops fast 闸门后管格绿(overall=fail 甄别=后端巡检格/用户端棘轮格红属 crawler-plugin 34 个在飞件,本笔不触碰后端与用户端)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, watch } from 'vue'
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { joinAdminPath } from '@/config/app'
|
||||
import { pageTitleOf, topbarUserOf } from '@/layout/topbar-model'
|
||||
import { groupKeysForActive, toSidebarEntries } from '@/layout/menu-mapper'
|
||||
import { allGroupKeys, toSidebarEntries } from '@/layout/menu-mapper'
|
||||
import { filterMenuTreeByPlatform, visiblePlatformsFor } from '@/layout/platform-menu-filter'
|
||||
import { PLATFORM_TABS, platformsOfMenuKey } from '@/config/platform-scope'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
@@ -44,7 +44,21 @@ const menuEntries = computed(() =>
|
||||
const visibleTabIds = computed(() => visiblePlatformsFor(session.menuTree))
|
||||
const visibleTabDefs = computed(() => PLATFORM_TABS.filter((tab) => visibleTabIds.value.includes(tab.id)))
|
||||
const showPlatformTabs = computed(() => visibleTabIds.value.length > 1)
|
||||
const openedKeys = computed(() => groupKeysForActive(menuEntries.value, route.path))
|
||||
// 父菜单默认全展开(2026-11-17 用户口径「父菜单不要默认折叠」)。el-menu 的 default-openeds
|
||||
// 只在挂载时读一次,平台 tab 切换/菜单树刷新导致 entries 变化后新分组不会自动展开,
|
||||
// 这里在 entries 变更渲染完成后按当下值命令式补开;用户手动收起的组在 entries 不变期间
|
||||
// 保持收起(watch 不重触发)。读当下 computed 而非触发时快照:快速连切 tab 时不补开已
|
||||
// 离开渲染树的旧分组(el-menu 的 open 对未注册 index 会抛)。
|
||||
const menuRef = ref<{ open: (index: string) => void } | null>(null)
|
||||
const openedKeys = computed(() => allGroupKeys(menuEntries.value))
|
||||
watch(openedKeys, async () => {
|
||||
await nextTick()
|
||||
const menu = menuRef.value
|
||||
if (!menu) return
|
||||
for (const key of openedKeys.value) {
|
||||
menu.open(key)
|
||||
}
|
||||
}, { immediate: true })
|
||||
const emptyMenu = computed(() => shouldShowEmptyMenu(menuEntries.value.length > 0, session.loading, session.initialized))
|
||||
const pageTitle = computed(() => pageTitleOf(route.meta.title))
|
||||
const userVm = computed(() => topbarUserOf(session.user))
|
||||
@@ -131,7 +145,7 @@ async function signOut() {
|
||||
</nav>
|
||||
|
||||
<el-scrollbar class="admin-menu-scroll">
|
||||
<el-menu :default-active="activePath" :default-openeds="openedKeys" router class="admin-menu">
|
||||
<el-menu ref="menuRef" :default-active="activePath" :default-openeds="openedKeys" router class="admin-menu">
|
||||
<template v-for="entry in menuEntries" :key="entry.key">
|
||||
<el-sub-menu v-if="entry.kind === 'group'" :index="entry.key">
|
||||
<template #title>
|
||||
|
||||
@@ -34,11 +34,11 @@ export function toSidebarEntries(nodes: AdminMenuNode[] | null | undefined): Sid
|
||||
return entries
|
||||
}
|
||||
|
||||
/** 计算需默认展开的分组 key:分组下含当前激活路由子项时返回该分组 key。 */
|
||||
export function groupKeysForActive(entries: SidebarEntry[], activeRoute: string): string[] {
|
||||
/** 计算需默认展开的分组 key:父菜单默认全展开(2026-11-17 用户口径「父菜单不要默认折叠」)。 */
|
||||
export function allGroupKeys(entries: SidebarEntry[]): string[] {
|
||||
const keys: string[] = []
|
||||
for (const entry of entries) {
|
||||
if (entry.kind === 'group' && entry.children.some((child) => child.route === activeRoute)) {
|
||||
if (entry.kind === 'group') {
|
||||
keys.push(entry.key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user