Browse Source

持久化路由

yangdr 1 day ago
parent
commit
5e8ec34b98
2 changed files with 54 additions and 56 deletions
  1. 39 35
      src/stores/menu.js
  2. 15 21
      src/views/AppCopy.vue

+ 39 - 35
src/stores/menu.js

@@ -1,42 +1,46 @@
 import { ref } from 'vue'
 import { defineStore } from 'pinia'
-
+import {
+  deleteSessionVar,
+  getSessionVar,
+  saveSessionVar,
+} from "@/utils/session";
 export const useMenuStore = defineStore('menu', () => {
-  let routeList = ref([])
-//   const routeList = ref([{
-//     path: '/kmplatform/home',
-//     name: 'kmplatform-home',
-//     title: "主页",
-//     children: []
-//   },
-//   {
-//     path: '/kmplatform/knowledgebase',
-//     name: 'knowledgebase',
-//     title: "知识库",
-//     children: []
-//   },
-//   {
-//     path: '/kmplatform/kgbuilder',
-//     name: 'kgbuilder',
-//     title: "知识图谱构建",
-//     children: []
-//   },
-//   {
-//     path: '/kmplatform/openplatform',
-//     name: 'openplatform',
-//     title: "开放平台",
-//     children: []
-//   },
-//   {
-//     path: '/kmplatform/kgpermission',
-//     name: 'kgpermission',
-//     title: "系统权限",
-//     children: []
-//   }
-// ])
+  let routeList = ref(getSessionVar("routeList") ? JSON.parse(getSessionVar("routeList")) : [])
+  //   const routeList = ref([{
+  //     path: '/kmplatform/home',
+  //     name: 'kmplatform-home',
+  //     title: "主页",
+  //     children: []
+  //   },
+  //   {
+  //     path: '/kmplatform/knowledgebase',
+  //     name: 'knowledgebase',
+  //     title: "知识库",
+  //     children: []
+  //   },
+  //   {
+  //     path: '/kmplatform/kgbuilder',
+  //     name: 'kgbuilder',
+  //     title: "知识图谱构建",
+  //     children: []
+  //   },
+  //   {
+  //     path: '/kmplatform/openplatform',
+  //     name: 'openplatform',
+  //     title: "开放平台",
+  //     children: []
+  //   },
+  //   {
+  //     path: '/kmplatform/kgpermission',
+  //     name: 'kgpermission',
+  //     title: "系统权限",
+  //     children: []
+  //   }
+  // ])
 
-const updateRouteList = (newRoutes) => {
+  const updateRouteList = (newRoutes) => {
     routeList.value = newRoutes; // 更新路由列表
   };
-  return { routeList,updateRouteList }
+  return { routeList, updateRouteList }
 })

+ 15 - 21
src/views/AppCopy.vue

@@ -60,15 +60,12 @@
             <span class="knowledge-base-icon" @click="goToKMPlatform"></span>
           </div>
         </el-col>
-        <el-col
-          :span="6"
-          style="
+        <el-col :span="6" style="
             justify-content: flex-end;
             display: flex;
             flex-direction: row;
             margin-top: 8px;
-          "
-        >
+          ">
           <el-dropdown style="margin-top: 10px">
             <div style="font-size: medium; font-weight: bold; color: #000">
               {{ user.full_name }}
@@ -86,10 +83,7 @@
     </el-header>
     <el-container>
       <el-aside class="main-aside">
-        <SideMenu
-          @selectQueue="onSelectQueue"
-          @selectMenu="onSelectMenu"
-        ></SideMenu>
+        <SideMenu @selectQueue="onSelectQueue" @selectMenu="onSelectMenu"></SideMenu>
       </el-aside>
       <el-main class="content-area">
         <!-- 主要内容区域 -->
@@ -101,7 +95,7 @@
   </el-container>
 </template>
 <script setup lang="ts">
-import { onMounted, ref,  watch, watchEffect } from "vue";
+import { onMounted, ref, watch, watchEffect } from "vue";
 import { useRouter, useRoute } from "vue-router";
 import { RouterView } from "vue-router";
 import SideMenu from "@/components/SideMenu.vue";
@@ -254,17 +248,17 @@ const handleLoginSubmit = () => {
     saveSessionVar("username", res.records[0].session.username);
     saveSessionVar("full_name", res.records[0].session.full_name);
     let knowledageSystem = '';
-    let routeList:any= [{
-    path: '/kmplatform/home',
-    name: 'kmplatform-home',
-    title: "主页",
-    children: []
-  }]
-  res.records[0].menu_permissions.sort((a: any, b: any) => {
+    let routeList: any = [{
+      path: '/kmplatform/home',
+      name: 'kmplatform-home',
+      title: "主页",
+      children: []
+    }]
+    res.records[0].menu_permissions.sort((a: any, b: any) => {
       return a.id - b.id;
     });
     res.records[0].menu_permissions.forEach((item: any) => {
-      if(item.menu_name == "知识更新管理") {
+      if (item.menu_name == "知识更新管理") {
         knowledageSystem = 'true';
       }
       if (item.menu_route) {
@@ -273,12 +267,12 @@ const handleLoginSubmit = () => {
           name: item.menu_route.split("/")[2],
           title: item.name,
           children: item.children,
-        }) ;
+        });
       }
     });
     console.log("knowledageSystem", knowledageSystem);
-    saveSessionVar("knowledageSystem",knowledageSystem);
-
+    saveSessionVar("knowledageSystem", knowledageSystem);
+    saveSessionVar('routeList', JSON.stringify(routeList))
 
     updateRouteList(routeList);