From 2e8ece94ce3c02b7dd9216484052389e708f52ac Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Fri, 26 Dec 2025 11:34:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/layout/components/Navbar.vue | 18 +++++++++++++++++- web/src/layout/index.vue | 4 +--- web/src/store/modules/app.ts | 8 +++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/web/src/layout/components/Navbar.vue b/web/src/layout/components/Navbar.vue index 6bbcda91..03bf188a 100644 --- a/web/src/layout/components/Navbar.vue +++ b/web/src/layout/components/Navbar.vue @@ -188,7 +188,23 @@ defineExpose({ }); const toggleSideBar = () => { - appStore.toggleSideBar(false); + // 点击 hamburger: + // - 移动端:关闭侧边栏(覆盖式) + // - 桌面端:如果当前是隐藏状态 -> 取消隐藏并展开;如果当前可见 -> 隐藏(完全移除) + if (appStore.device === 'mobile') { + appStore.closeSideBar({ withoutAnimation: false }); + return; + } + + if (appStore.sidebar.hide) { + // 当前被隐藏,显示并展开 + appStore.toggleSideBarHide(false); + appStore.openSideBar(); + } else { + // 当前可见,先收起(关闭),再隐藏 + appStore.closeSideBar({ withoutAnimation: false }); + appStore.toggleSideBarHide(true); + } }; const logout = async () => { diff --git a/web/src/layout/index.vue b/web/src/layout/index.vue index 3920866a..e5d2aeef 100644 --- a/web/src/layout/index.vue +++ b/web/src/layout/index.vue @@ -50,9 +50,7 @@ watchEffect(() => { appStore.closeSideBar({ withoutAnimation: true }); } else { appStore.toggleDevice('desktop'); - if (!appStore.sidebar.opened) { - appStore.openSideBar(); - } + // 桌面端保持用户的侧边栏状态,不自动打开 } }); diff --git a/web/src/store/modules/app.ts b/web/src/store/modules/app.ts index f3790325..7fb8c70f 100644 --- a/web/src/store/modules/app.ts +++ b/web/src/store/modules/app.ts @@ -5,11 +5,13 @@ import { useStorage } from '@vueuse/core'; import { ref, reactive, computed } from 'vue'; export const useAppStore = defineStore('app', () => { - const sidebarStatus = useStorage('sidebarStatus', '1'); + // 默认隐藏侧边栏(首次打开页面时不渲染侧边栏) + const sidebarStatus = useStorage('sidebarStatus', '0'); + const sidebar = reactive({ - opened: sidebarStatus.value ? !!+sidebarStatus.value : true, + opened: false, withoutAnimation: false, - hide: false + hide: true }); const device = ref('desktop'); const size = useStorage<'large' | 'default' | 'small'>('size', 'default');