重构次导航默认展开效果

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, 'shadow': sidebarScrollTop,
}" }"
/> />
<!-- 侧边栏模式无主导航 --> <transition-group name="sub-sidebar">
<el-menu <template v-for="(mainItem, mainIndex) in menuStore.allMenus" :key="mainIndex">
: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="{ <div v-show="mainIndex === menuStore.actived">
'is-collapse-without-logo': settingsStore.settings.menu.menuMode !== 'single' && settingsStore.settings.menu.subMenuCollapse, <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 v-for="(route, index) in mainItem.children">
</template> <SidebarItem v-if="route.meta?.sidebar !== false" :key="route.path || index" :item="route" :base-path="route.path" />
</transition-group> </template>
</el-menu> </el-menu>
</div>
</template>
</transition-group>
</div> </div>
</template> </template>

View File

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