Просмотр исходного кода

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

RuoYi лет назад: 5
Родитель
Сommit
5e167eb6e1
1 измененных файлов с 11 добавлено и 5 удалено
  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 27
           const sdata = JSON.parse(JSON.stringify(res.data))
28 28
           const rdata = JSON.parse(JSON.stringify(res.data))
29 29
           const sidebarRoutes = filterAsyncRouter(sdata)
30
-          const rewriteRoutes = filterAsyncRouter(rdata, true)
30
+          const rewriteRoutes = filterAsyncRouter(rdata, false, true)
31 31
           rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
32 32
           commit('SET_ROUTES', rewriteRoutes)
33 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 43
   return asyncRouterMap.filter(route => {
44
-    if (isRewrite && route.children) {
44
+    if (type && route.children) {
45 45
       route.children = filterChildren(route.children)
46 46
     }
47 47
     if (route.component) {
@@ -55,13 +55,16 @@ function filterAsyncRouter(asyncRouterMap, isRewrite = false) {
55 55
       }
56 56
     }
57 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 63
     return true
61 64
   })
62 65
 }
63 66
 
64
-function filterChildren(childrenMap) {
67
+function filterChildren(childrenMap, lastRouter = false) {
65 68
   var children = []
66 69
   childrenMap.forEach((el, index) => {
67 70
     if (el.children && el.children.length) {
@@ -77,6 +80,9 @@ function filterChildren(childrenMap) {
77 80
         return
78 81
       }
79 82
     }
83
+    if (lastRouter) {
84
+      el.path = lastRouter.path + '/' + el.path
85
+    }
80 86
     children = children.concat(el)
81 87
   })
82 88
   return children