From 41160520fb99ab34632cba957006da16f316ca79 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期四, 16 二月 2023 14:09:49 +0800
Subject: [PATCH] 优化

---
 src/views/layout/components/Menu/index.vue |   93 +++++++++++++++++++++++-----------------------
 1 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/src/views/layout/components/Menu/index.vue b/src/views/layout/components/Menu/index.vue
index df0d374..f7208f3 100644
--- a/src/views/layout/components/Menu/index.vue
+++ b/src/views/layout/components/Menu/index.vue
@@ -2,19 +2,22 @@
   <div>
     <!-- 渚ц竟瀵艰埅鏍� -->
     <el-aside width="200px">
-      <h2 class="siderbar-title">閬傛槍鎵ф硶骞冲彴</h2>
+      <h2 class="siderbar-title" @click="toHome()">閬傛槍鎵ф硶骞冲彴</h2>
       <el-scrollbar>
         <!-- 璺敱 -->
-        <el-menu router class="el-menu-vertical" :default-active="$route.path">
+        <el-menu router
+                 class="el-menu-vertical"
+                 :default-active="$route.path.name"
+                 @select="handleSelect">
           <el-submenu
-            :index="menu.url ? menu.url : menu.id.toString()"
+            :index="String(menu.id)"
             v-for="menu in menuList"
             :key="menu.id"
             class="firstMenu"
           >
             <template slot="title">
               <span slot="prefix" class="icon-padding fisrtSpan">
-                <svg-icon :icon-class="menu.icon"></svg-icon>
+                <svg-icon class="icon-title" :icon-class="menu.icon"></svg-icon>
               </span>
               <span class="fisrtSpan">{{ menu.title }}</span>
             </template>
@@ -23,9 +26,7 @@
                 <el-submenu
                   :key="secondMenu.id"
                   v-if="secondMenu.menuVoArrayList.length > 0"
-                  :index="
-                    secondMenu.url ? secondMenu.url : secondMenu.id.toString()
-                  "
+                  :index="secondMenu.url ? secondMenu.url : secondMenu.id.toString()"
                   class="secondMenu"
                 >
                   <template slot="title">
@@ -39,16 +40,13 @@
                     >{{ thirdMenu.title }}</el-menu-item
                   >
                 </el-submenu>
-
                 <el-menu-item
                   v-else
                   :index="`${secondMenu.id}`"
                   :route="{ name: secondMenu.url }"
-                  >{{ secondMenu.title }}</el-menu-item
-                >
+                  >{{ secondMenu.title }}</el-menu-item>
               </template>
             </template>
-
             <el-menu-item
               v-else
               :key="menu.id"
@@ -64,45 +62,43 @@
 </template>
 
 <script>
-let timer = null;
+import users from "@/api/users";
+import router from "@/router";
+
 export default {
   data() {
     return {
       menuList: [],
+      isActive:''
     };
   },
   created() {
-    // this.getMenuList();
     this.loadMenu();
   },
+  watch: {
+    $route(){
+      this.handleSelect(this.$route.fullPath)
+      console.log(this.$route)
+    }
+  },
   methods: {
+    handleSelect(path){
+      this.isActive = path
+    },
     loadMenu() {
-      const info = JSON.parse(sessionStorage.getItem("user"));
-
-      if (info && info.menus) {
-        console.log("timer--", timer);
-        window.clearInterval(timer);
-        this.menuList = info.menus;
-        console.log(this.menuList);
-      } else {
-        if (!timer) {
-          timer = window.setInterval(() => {
-            this.loadMenu();
-          }, 1000);
-          console.log("timer++", timer);
-        }
-      }
+      const userName = sessionStorage.getItem('name');
+      users.getMenu({ name: userName })
+          .then(res => {
+            console.log(res)
+            debugger
+            this.menuList = res.menus;
+            sessionStorage.setItem('user', JSON.stringify(res));
+          })
+          .catch(err => this.$message.error(err))
     },
-    // 鑾峰彇鑿滃崟鍒楄〃
-    getMenuList() {
-      let arr;
-      this.$axios({
-        method: "get",
-        url: "sccg/system/portal/menu/search_myself",
-      }).then((res) => {
-        console.log(res);
-      });
-    },
+    toHome(){
+      router.push("/home")
+    }
   },
 };
 </script>
@@ -110,10 +106,14 @@
 <style lang="scss" scpoed>
 .icon-padding {
   padding-right: 10px;
+  .icon-title{
+    width: 36px;
+    height: 36px;
+  }
 }
 
 .el-aside {
-  background: #07162e;
+  background: #313350;
   color: #e9eef3;
   text-align: center;
   box-sizing: border-box;
@@ -130,6 +130,7 @@
     top: 0;
     left: 0;
     z-index: 999;
+    cursor: pointer;
   }
 
   .el-scrollbar {
@@ -138,11 +139,11 @@
     box-sizing: border-box;
 
     .el-menu {
-      background: linear-gradient(#07162e, #0f2b56);
+      background: linear-gradient(#313350, #0f2b56);
       border: 0;
 
       .firstMenu {
-        background: #07162e;
+        background: #313350;
         text-align: left;
 
         &:hover > .el-submenu__title {
@@ -160,17 +161,17 @@
 
         .el-menu-item {
           color: #e9eef3;
-          background-color: #07162e;
+          background-color: #313350;
         }
 
         .el-menu-item:hover {
-          background-color: #092c4a;
+          background-color: #409EFF;
           color: #22d3eb;
         }
 
         .is-active {
-          background-color: #07162e;
-          color: #22d3eb;
+          background-color: #409EFF;
+          color: #fff;
         }
       }
 
@@ -204,4 +205,4 @@
     }
   }
 }
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.8.0