Commit bc41aa70d1b662e64d28542cf5a95443e4ef817a

Authored by YunaiV
1 parent f540c8a3

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

yudao-ui-admin/src/store/modules/permission.js
@@ -27,7 +27,7 @@ const permission = { @@ -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,7 +39,7 @@ const permission = { @@ -39,7 +39,7 @@ 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 // 将 ruoyi 后端原有耦合前端的逻辑,迁移到此处 44 // 将 ruoyi 后端原有耦合前端的逻辑,迁移到此处
45 // 处理 meta 属性 45 // 处理 meta 属性
@@ -60,17 +60,19 @@ function filterAsyncRouter(asyncRouterMap, isRewrite = false) { @@ -60,17 +60,19 @@ function filterAsyncRouter(asyncRouterMap, isRewrite = false) {
60 } 60 }
61 61
62 // filterChildren 62 // filterChildren
63 - if (isRewrite && route.children) { 63 + if (type && route.children) {
64 route.children = filterChildren(route.children) 64 route.children = filterChildren(route.children)
65 } 65 }
66 if (route.children != null && route.children && route.children.length) { 66 if (route.children != null && route.children && route.children.length) {
67 - route.children = filterAsyncRouter(route.children, route, isRewrite) 67 + route.children = filterAsyncRouter(route.children, route, type)
  68 + } else {
  69 + delete route['children']
68 } 70 }
69 return true 71 return true
70 }) 72 })
71 } 73 }
72 74
73 -function filterChildren(childrenMap) { 75 +function filterChildren(childrenMap, lastRouter = false) {
74 var children = [] 76 var children = []
75 childrenMap.forEach((el, index) => { 77 childrenMap.forEach((el, index) => {
76 if (el.children && el.children.length) { 78 if (el.children && el.children.length) {
@@ -86,6 +88,9 @@ function filterChildren(childrenMap) { @@ -86,6 +88,9 @@ function filterChildren(childrenMap) {
86 return 88 return
87 } 89 }
88 } 90 }
  91 + if (lastRouter) {
  92 + el.path = lastRouter.path + '/' + el.path
  93 + }
89 children = children.concat(el) 94 children = children.concat(el)
90 }) 95 })
91 return children 96 return children