From d8b570430066fae42d6884671cef541fc820de1c Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期五, 15 十一月 2024 14:42:44 +0800
Subject: [PATCH] 动态路由

---
 src/layout/components/Sidebar/index.vue |   59 ++++++++++++++++++++++++++---------------------------------
 1 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue
index a625286..5acaeb5 100644
--- a/src/layout/components/Sidebar/index.vue
+++ b/src/layout/components/Sidebar/index.vue
@@ -3,20 +3,20 @@
     <logo v-if="showLogo" :collapse="isCollapse" />
     <el-scrollbar :class="sideTheme" wrap-class="scrollbar-wrapper">
       <el-menu
-        :default-active="activeMenu"
-        :collapse="isCollapse"
-        :background-color="sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground"
-        :text-color="sideTheme === 'theme-dark' ? variables.menuColor : variables.menuLightColor"
-        :unique-opened="true"
-        :active-text-color="theme"
-        :collapse-transition="false"
-        mode="vertical"
+          :default-active="activeMenu"
+          :collapse="isCollapse"
+          :background-color="sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground"
+          :text-color="sideTheme === 'theme-dark' ? variables.menuColor : variables.menuLightColor"
+          :unique-opened="true"
+          :active-text-color="theme"
+          :collapse-transition="false"
+          mode="vertical"
       >
         <sidebar-item
-          v-for="(route, index) in sidebarRouters"
-          :key="route.path + index"
-          :item="route"
-          :base-path="route.path"
+            v-for="(route, index) in sidebarRouters"
+            :key="route.path + index"
+            :item="route"
+            :base-path="route.path"
         />
       </el-menu>
     </el-scrollbar>
@@ -30,30 +30,16 @@
 import useAppStore from '@/store/modules/app'
 import useSettingsStore from '@/store/modules/settings'
 import usePermissionStore from '@/store/modules/permission'
-import {onMounted, ref} from "vue";
-import Cookies from "js-cookie";
-import menu from "./menu"
+import {computed} from "vue";
+import {useRoute} from "vue-router";
+
 const route = useRoute();
 const appStore = useAppStore()
 const settingsStore = useSettingsStore()
 const permissionStore = usePermissionStore()
-// const sidebarRouters =  computed(() => permissionStore.sidebarRouters);
-const sidebarRouters = ref([])
 
-onMounted(() => {
-    sidebarRouters.value = JSON.parse(Cookies.get('routers'))
-});
-// const getMenu = () => {
-//     const userInfo = JSON.parse(Cookies.get('userInfo'))
-//     if(userInfo.identity === 0) {
-//
-//         sidebarRouters.value =  menu.adminMenu
-//         Cookies.set('routers',JSON.stringify(sidebarRouters.value))
-//     }
-// }
-
-
-
+const sidebarRouters =  computed(() => permissionStore.sidebarRouters);
+console.log(sidebarRouters.value,789)
 const showLogo = computed(() => settingsStore.sidebarLogo);
 const sideTheme = computed(() => settingsStore.sideTheme);
 const theme = computed(() => settingsStore.theme);
@@ -65,7 +51,14 @@
   if (meta.activeMenu) {
     return meta.activeMenu;
   }
-  return path;
-})
 
+  const showRoute  = sidebarRouters.value.filter(item => !item.hidden);
+  if(showRoute[0].path === '/'){
+    return '/' + showRoute[0].children[0].path
+  }else{
+    return showRoute[0].path + '/' + showRoute[0].children[0].path
+  }
+
+  // return path
+})
 </script>

--
Gitblit v1.9.2