From 6d3e42d9c12055d374c6438ebdb266a3f405777e Mon Sep 17 00:00:00 2001 From: fhysy <1149505133@qq.com> Date: Tue, 1 Jul 2025 17:52:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(layout):=20=E9=BB=98=E8=AE=A4=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E6=89=80=E6=9C=89=E6=9C=89=E5=AD=90=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E8=8F=9C=E5=8D=95=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了 sidebar 的初始折叠状态,设置为关闭 - 在 Sidebar 组件中添加了递归获取所有有 children 的菜单项的逻辑 - 在折叠展开菜单时,自动展开所有有子菜单的菜单项 --- src/layout/components/Sidebar/index.vue | 40 ++++++++++++++++++++++++- src/store/modules/app.js | 2 +- 2 files changed, 40 insertions(+), 2 deletions(-) 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',