重构次导航默认展开效果

This commit is contained in:
Hooray Hu 2023-05-06 16:16:42 +08:00
parent 2ffc8fe59d
commit 136d2cf216
2 changed files with 19 additions and 14 deletions

View File

@ -22,18 +22,21 @@ function onSidebarScroll(e: Event) {
'shadow': sidebarScrollTop,
}"
/>
<!-- 侧边栏模式无主导航 -->
<el-menu
:unique-opened="settingsStore.settings.menu.subMenuUniqueOpened" :default-openeds="menuStore.defaultOpenedPaths" :default-active="$route.meta.activeMenu || $route.path" :collapse="settingsStore.mode === 'pc' && settingsStore.settings.menu.subMenuCollapse" :collapse-transition="false" :class="{
'is-collapse-without-logo': settingsStore.settings.menu.menuMode !== 'single' && settingsStore.settings.menu.subMenuCollapse,
}"
>
<transition-group name="sub-sidebar">
<template v-for="(route, index) in menuStore.sidebarMenus">
<SidebarItem v-if="route.meta?.sidebar !== false" :key="route.path || index" :item="route" :base-path="route.path" />
</template>
</transition-group>
</el-menu>
<transition-group name="sub-sidebar">
<template v-for="(mainItem, mainIndex) in menuStore.allMenus" :key="mainIndex">
<div v-show="mainIndex === menuStore.actived">
<el-menu
:unique-opened="settingsStore.settings.menu.subMenuUniqueOpened" :default-openeds="menuStore.defaultOpenedPaths" :default-active="$route.meta.activeMenu || $route.path" :collapse="settingsStore.mode === 'pc' && settingsStore.settings.menu.subMenuCollapse" :collapse-transition="false" :class="{
'is-collapse-without-logo': settingsStore.settings.menu.menuMode !== 'single' && settingsStore.settings.menu.subMenuCollapse,
}"
>
<template v-for="(route, index) in mainItem.children">
<SidebarItem v-if="route.meta?.sidebar !== false" :key="route.path || index" :item="route" :base-path="route.path" />
</template>
</el-menu>
</div>
</template>
</transition-group>
</div>
</template>

View File

@ -73,9 +73,11 @@ const useMenuStore = defineStore(
}
// 默认展开的导航路径
const defaultOpenedPaths = computed(() => {
let defaultOpenedPaths: string[] = []
const defaultOpenedPaths: string[] = []
if (settingsStore.settings.app.routeBaseOn !== 'filesystem') {
defaultOpenedPaths = getDefaultOpenedPaths(sidebarMenus.value)
allMenus.value.forEach((item) => {
defaultOpenedPaths.push(...getDefaultOpenedPaths(item.children))
})
}
return defaultOpenedPaths
})