diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index ca4bcea1caa5ac2d85c7577773150a33e5e8dfc0..c228144c432338f5ce7969ced08a97e600aea91c 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -39,7 +39,7 @@ const usePermissionStore = defineStore('permission', { const rdata = JSON.parse(JSON.stringify(res.data)) const defaultData = JSON.parse(JSON.stringify(res.data)) const sidebarRoutes = filterAsyncRouter(sdata) - const rewriteRoutes = filterAsyncRouter(rdata, false, true) + const rewriteRoutes = filterAsyncRouter(rdata,false,true) const defaultRoutes = filterAsyncRouter(defaultData) this.setRoutes(rewriteRoutes) this.setSidebarRouters(constantRoutes.concat(sidebarRoutes)) @@ -69,9 +69,10 @@ const usePermissionStore = defineStore('permission', { // 遍历后台传来的路由字符串,转换为组件对象 function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { return asyncRouterMap.filter((route) => { - if (type && route.children) { - route.children = filterChildren(route.children) + if (type&& route.children) { + filterChildren(route.children) } + if (route.component) { // Layout ParentView 组件特殊处理 if (route.component === 'Layout') { @@ -94,30 +95,25 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { }) } -function filterChildren(childrenMap, lastRouter = false) { - var children = [] - childrenMap.forEach((el, index) => { - if (el.children && el.children.length) { - if (el.component === 'ParentView' && !lastRouter) { - el.children.forEach((c) => { - c.path = el.path + '/' + c.path - if (c.children && c.children.length) { - children = children.concat(filterChildren(c.children, c)) - return - } - children.push(c) - }) - return +function filterChildren(childrenMap, parentName = false) { + if (childrenMap && childrenMap.length) { + + childrenMap.forEach((el, index) => { + if (parentName) { + el.name = parentName + '/' + el.name } - } - if (lastRouter) { - el.path = lastRouter.path + '/' + el.path - } - children = children.concat(el) - }) - return children + + + if (el.children && el.children.length) { + if (el.component === 'ParentView') { + filterChildren(el.children, el.name) + } + } + }); + } } + export const loadView = (view) => { let res for (const path in modules) {