From 43443ee2bb9857dc5473a38c0fad8442af124343 Mon Sep 17 00:00:00 2001 From: Cosmokey <253180123@qq.com> Date: Sun, 3 Dec 2023 15:17:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A1=EF=BC=89=E9=9D=A2?= =?UTF-8?q?=E5=8C=85=E5=B1=91=E4=B8=A2=E5=A4=B1=E4=B8=AD=E9=97=B4=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E9=97=AE=E9=A2=98=E3=80=82=202=EF=BC=89=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=B8=8D=E5=90=8C=E5=B1=82=E7=BA=A7=E4=B8=8B=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E8=B7=AF=E5=BE=84=E4=B8=8D=E8=83=BD=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/permission.js | 44 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index ca4bcea..c228144 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) { -- Gitee