diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue index 0a8e0491..ed2ac108 100644 --- a/src/layout/components/Sidebar/index.vue +++ b/src/layout/components/Sidebar/index.vue @@ -5,13 +5,15 @@ { + if (route.hidden) return; + let fullPath = ''; + if (route.path.startsWith('/')) { + fullPath = route.path; + } else { + fullPath = basePath ? (basePath.endsWith('/') ? basePath + route.path : basePath + '/' + route.path) : route.path; + } + if (route.children && route.children.length > 0) { + if (fullPath) keys.push(fullPath); + collectKeys(route.children, fullPath); + } + }); + } + collectKeys(this.sidebarRouters); + // 过滤空字符串和重复项 + return Array.from(new Set(keys.filter(Boolean))); + }, showLogo() { return this.$store.state.settings.sidebarLogo; }, @@ -59,6 +83,20 @@ export default { return process.env.VUE_APP_THEME_CLASS !=='theme-blue-white'?'#ffffff':'#000000'; } }, + watch: { + isCollapse(val) { + if (!val) { + // 展开所有有children的菜单 + this.$nextTick(() => { + this.allOpenKeys.forEach(key => { + if (this.$refs.menuRef && this.$refs.menuRef.submenus && this.$refs.menuRef.submenus[key]) { + this.$refs.menuRef.open(key); + } + }); + }); + } + } + }, methods: { toggleSideBar() { this.$store.dispatch('app/toggleSideBar') diff --git a/src/store/modules/app.js b/src/store/modules/app.js index c8d8bd09..2ac0400c 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -2,7 +2,7 @@ import Cookies from 'js-cookie' const state = { sidebar: { - opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true, + opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : false, withoutAnimation: false }, device: 'desktop',