From f1299856fbd21edc531c58dc7f2f137d7575dd38 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 11 Jun 2021 12:53:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=9B=E7=BA=A7=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 2 +- src/store/modules/permission.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 7410141..47be649 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -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(() => { // 存储路由 diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index 49e4778..513e259 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -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