zlwu преди 10 месеца
родител
ревизия
2e8ece94ce
променени са 3 файла, в които са добавени 23 реда и са изтрити 7 реда
  1. 17 1
      web/src/layout/components/Navbar.vue
  2. 1 3
      web/src/layout/index.vue
  3. 5 3
      web/src/store/modules/app.ts

+ 17 - 1
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 () => {

+ 1 - 3
web/src/layout/index.vue

@@ -50,9 +50,7 @@ watchEffect(() => {
     appStore.closeSideBar({ withoutAnimation: true });
   } else {
     appStore.toggleDevice('desktop');
-    if (!appStore.sidebar.opened) {
-      appStore.openSideBar();
-    }
+    // 桌面端保持用户的侧边栏状态,不自动打开
   }
 });
 

+ 5 - 3
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<string>('desktop');
   const size = useStorage<'large' | 'default' | 'small'>('size', 'default');