Quellcode durchsuchen

修复四级菜单无法显示问题

RuoYi vor 5 Jahren
Ursprung
Commit
5e167eb6e1
1 geänderte Dateien mit 11 neuen und 5 gelöschten Zeilen
  1. 11 5
      ruoyi-ui/src/store/modules/permission.js

+ 11 - 5
ruoyi-ui/src/store/modules/permission.js

@@ -27,7 +27,7 @@ const permission = {
27
           const sdata = JSON.parse(JSON.stringify(res.data))
27
           const sdata = JSON.parse(JSON.stringify(res.data))
28
           const rdata = JSON.parse(JSON.stringify(res.data))
28
           const rdata = JSON.parse(JSON.stringify(res.data))
29
           const sidebarRoutes = filterAsyncRouter(sdata)
29
           const sidebarRoutes = filterAsyncRouter(sdata)
30
-          const rewriteRoutes = filterAsyncRouter(rdata, true)
30
+          const rewriteRoutes = filterAsyncRouter(rdata, false, true)
31
           rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
31
           rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
32
           commit('SET_ROUTES', rewriteRoutes)
32
           commit('SET_ROUTES', rewriteRoutes)
33
           commit('SET_SIDEBAR_ROUTERS', sidebarRoutes)
33
           commit('SET_SIDEBAR_ROUTERS', sidebarRoutes)
@@ -39,9 +39,9 @@ const permission = {
39
 }
39
 }
40
 
40
 
41
 // 遍历后台传来的路由字符串,转换为组件对象
41
 // 遍历后台传来的路由字符串,转换为组件对象
42
-function filterAsyncRouter(asyncRouterMap, isRewrite = false) {
42
+function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
43
   return asyncRouterMap.filter(route => {
43
   return asyncRouterMap.filter(route => {
44
-    if (isRewrite && route.children) {
44
+    if (type && route.children) {
45
       route.children = filterChildren(route.children)
45
       route.children = filterChildren(route.children)
46
     }
46
     }
47
     if (route.component) {
47
     if (route.component) {
@@ -55,13 +55,16 @@ function filterAsyncRouter(asyncRouterMap, isRewrite = false) {
55
       }
55
       }
56
     }
56
     }
57
     if (route.children != null && route.children && route.children.length) {
57
     if (route.children != null && route.children && route.children.length) {
58
-      route.children = filterAsyncRouter(route.children, route, isRewrite)
58
+      route.children = filterAsyncRouter(route.children, route, type)
59
+    } else {
60
+      delete route['children']
61
+      delete route['redirect']
59
     }
62
     }
60
     return true
63
     return true
61
   })
64
   })
62
 }
65
 }
63
 
66
 
64
-function filterChildren(childrenMap) {
67
+function filterChildren(childrenMap, lastRouter = false) {
65
   var children = []
68
   var children = []
66
   childrenMap.forEach((el, index) => {
69
   childrenMap.forEach((el, index) => {
67
     if (el.children && el.children.length) {
70
     if (el.children && el.children.length) {
@@ -77,6 +80,9 @@ function filterChildren(childrenMap) {
77
         return
80
         return
78
       }
81
       }
79
     }
82
     }
83
+    if (lastRouter) {
84
+      el.path = lastRouter.path + '/' + el.path
85
+    }
80
     children = children.concat(el)
86
     children = children.concat(el)
81
   })
87
   })
82
   return children
88
   return children