Bläddra i källkod

前端:赵主任要求:只保持一个子菜单的展开;查询参数的持久化仅限当前页面,打开到其他页面时就清理掉其他页面的查询参数

baichengfei 4 år sedan
förälder
incheckning
27f7c666ab
1 ändrade filer med 18 tillägg och 0 borttagningar
  1. 18 0
      src/dashoo.cn/frontend_web/src/components/sidebar.vue

+ 18 - 0
src/dashoo.cn/frontend_web/src/components/sidebar.vue

@@ -22,12 +22,15 @@ active-text-color="#1890FF"
 
 <template>
   <aside class="sidebar-container sidebar" id="aside" :class="{ collapse: isMenuHidden }">
+    <!--点击一个菜单后,自动菜单自动折叠-->
     <el-scrollbar style="height: calc(100vh - 85px); overflow: hidden;" wrap-class="scrollbar-wrapper">
       <el-menu
         :collapse="isCollapse"
         :router="true"
+        :unique-opened="true"
         default-active="/"
         :collapse-transition="false"
+        @select="handleSelectMenu"
         @open="handleOpen"
         @close="handleClose"
       >
@@ -154,6 +157,7 @@ const MenuGetter = namespace('menu', Getter)
     },
     // open事件,用于判断是否需要通过点击导航栏就显示页面而不只是展开列表
     handleOpen (index, indexPath) {
+      this.updateMenuSession(index)
       var rule = /[u4e00-u9fa5]/
       if (rule.exec(index)) {
         this.$router.push({path: index})
@@ -161,10 +165,24 @@ const MenuGetter = namespace('menu', Getter)
     },
     // close事件,用于判断是否需要通过点击导航栏就显示页面而不只是展开列表
     handleClose (index, indexPath) {
+      this.updateMenuSession(index)
       var rule = /[u4e00-u9fa5]/
       if (rule.exec(index)) {
         this.$router.push({path: index})
       }
+    },
+    handleSelectMenu (index, indexPath) {
+      this.updateMenuSession(index)
+    },
+    updateMenuSession (currentPath) {
+      // 赵主任原话:类似这样的痕迹在点击其他菜单后自动清除。点击其他菜单后自动清除。2021年03月23日
+      if (process.client) {
+        let hisPath = window.localStorage.getItem('menuParams')
+        if (currentPath !== hisPath) {
+          Object.keys(localStorage).forEach(item => item.indexOf('Params') !== -1 ? localStorage.removeItem(item) : '')
+          window.localStorage.setItem('menuParams', currentPath) // 初次登录弹框
+        }
+      }
     }
   },
   watch: {