From 5d0e4bcaf5d44a9ce2ff196e38c77676aa8ea880 Mon Sep 17 00:00:00 2001
From: zhouwx <1175765986@qq.com>
Date: Fri, 12 Jun 2026 16:37:15 +0800
Subject: [PATCH] 中科大支线—添加菜单、角色

---
 src/store/modules/permission.js |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index 958fe63..b53a0f0 100644
--- a/src/store/modules/permission.js
+++ b/src/store/modules/permission.js
@@ -32,6 +32,9 @@
       setSidebarRouters(routes) {
         this.sidebarRouters = routes
       },
+      setIndexPages(routes) {
+        this.indexPage = routes
+      },
       generateRoutes(roles) {
         return new Promise(resolve => {
           // 向后端请求路由数据
@@ -39,15 +42,40 @@
             const sdata = JSON.parse(JSON.stringify(res.data))
             const rdata = JSON.parse(JSON.stringify(res.data))
             const defaultData = JSON.parse(JSON.stringify(res.data))
+            let firstPage = ''
+            //通过权限返回菜单去避免 如有首页权限 出现//index 情况
+            // if (res.data[0].path == '/') {
+            //   firstPage = res.data[0].path + res.data[0].children[0].path
+            // } else{
+            //   firstPage = res.data[0].path + '/' + res.data[0].children[0].path
+            // }
+            if (res.data && res.data.length > 0 && res.data[0]) {
+              const firstMenu = res.data[0];
+              // 2. 判断第一个菜单是否有子菜单
+              if (firstMenu.children && firstMenu.children.length > 0) {
+                // 有子菜单,按原来的逻辑拼接
+                if (firstMenu.path === '/') {
+                  firstPage = firstMenu.path + firstMenu.children[0].path;
+                } else {
+                  firstPage = firstMenu.path + '/' + firstMenu.children[0].path;
+                }
+              } else {
+                firstPage = firstMenu.path;
+              }
+            } else {
+              firstPage = '/index';
+            }
             const sidebarRoutes = filterAsyncRouter(sdata)
             const rewriteRoutes = filterAsyncRouter(rdata, false, true)
             const defaultRoutes = filterAsyncRouter(defaultData)
             const asyncRoutes = filterDynamicRoutes(dynamicRoutes)
             asyncRoutes.forEach(route => { router.addRoute(route) })
-            this.setRoutes(rewriteRoutes)
+            // this.setRoutes(rewriteRoutes)
             this.setSidebarRouters(constantRoutes.concat(sidebarRoutes))
+            // this.setSidebarRouters(sidebarRoutes)
             this.setDefaultRoutes(sidebarRoutes)
             this.setTopbarRoutes(defaultRoutes)
+            this.setIndexPages(firstPage)
             resolve(rewriteRoutes)
           })
         })

--
Gitblit v1.9.2