修复四级菜单无法显示问题
This commit is contained in:
@@ -56,7 +56,7 @@ export const loadMenus = (next, to) => {
|
||||
const sdata = JSON.parse(JSON.stringify(res))
|
||||
const rdata = JSON.parse(JSON.stringify(res))
|
||||
const sidebarRoutes = filterAsyncRouter(sdata)
|
||||
const rewriteRoutes = filterAsyncRouter(rdata, true)
|
||||
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
|
||||
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
|
||||
|
||||
store.dispatch('GenerateRoutes', rewriteRoutes).then(() => { // 存储路由
|
||||
|
||||
@@ -27,9 +27,9 @@ const permission = {
|
||||
}
|
||||
}
|
||||
|
||||
export const filterAsyncRouter = (routers, isRewrite = false) => { // 遍历后台传来的路由字符串,转换为组件对象
|
||||
export const filterAsyncRouter = (routers, lastRouter = false, type = false) => { // 遍历后台传来的路由字符串,转换为组件对象
|
||||
return routers.filter(router => {
|
||||
if (isRewrite && router.children) {
|
||||
if (type && router.children) {
|
||||
router.children = filterChildren(router.children)
|
||||
}
|
||||
if (router.component) {
|
||||
@@ -42,14 +42,17 @@ export const filterAsyncRouter = (routers, isRewrite = false) => { // 遍历后
|
||||
router.component = loadView(component)
|
||||
}
|
||||
}
|
||||
if (router.children && router.children.length) {
|
||||
router.children = filterAsyncRouter(router.children, router, isRewrite)
|
||||
if (router.children != null && router.children && router.children.length) {
|
||||
router.children = filterAsyncRouter(router.children, router, type)
|
||||
} else {
|
||||
delete router['children']
|
||||
delete router['redirect']
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
function filterChildren(childrenMap) {
|
||||
function filterChildren(childrenMap, lastRouter = false) {
|
||||
var children = []
|
||||
childrenMap.forEach((el, index) => {
|
||||
if (el.children && el.children.length) {
|
||||
@@ -65,6 +68,9 @@ function filterChildren(childrenMap) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if (lastRouter) {
|
||||
el.path = lastRouter.path + '/' + el.path
|
||||
}
|
||||
children = children.concat(el)
|
||||
})
|
||||
return children
|
||||
|
||||
Reference in New Issue
Block a user