From 725da078afc3398f49f1efdc25bc82b9ec1dac35 Mon Sep 17 00:00:00 2001 From: DYL0109 <dn18191638832@163.com> Date: 星期三, 16 四月 2025 19:27:30 +0800 Subject: [PATCH] Merge pull request #64 from zhitan-cloud/develop1.0 --- zhitan-vue/src/store/modules/permission.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 52 insertions(+), 4 deletions(-) diff --git a/zhitan-vue/src/store/modules/permission.js b/zhitan-vue/src/store/modules/permission.js index c9d09e6..5613f1c 100644 --- a/zhitan-vue/src/store/modules/permission.js +++ b/zhitan-vue/src/store/modules/permission.js @@ -56,8 +56,27 @@ }) // 閬嶅巻鍚庡彴浼犳潵鐨勮矾鐢卞瓧绗︿覆锛岃浆鎹负缁勪欢瀵硅薄 -function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { +function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false, parentRoute = null) { return asyncRouterMap.filter(route => { + // 涓嶅啀杩囨护鎺夐椤电湅鏉跨浉鍏宠矾鐢� + /* + // 杩囨护鎺夐椤电湅鏉跨浉鍏宠矾鐢� + if (route.name === 'Index' && route.meta && route.meta.title === '棣栭〉鐪嬫澘') { + return false; + } + + // 濡傛灉鏄椤电湅鏉跨殑瀛愯彍鍗曪紝涔熻繃婊ゆ帀 + if (route.path === '/index' || route.path === 'index' || + (route.meta && route.meta.title === '棣栭〉鐪嬫澘')) { + return false; + } + */ + + // 璁剧疆鐖惰矾鐢卞紩鐢� + if (parentRoute) { + route.parent = parentRoute; + } + if (type && route.children) { route.children = filterChildren(route.children) } @@ -82,7 +101,8 @@ } } if (route.children != null && route.children && route.children.length) { - route.children = filterAsyncRouter(route.children, route, type) + // 灏嗗綋鍓嶈矾鐢变綔涓虹埗璺敱浼犻�掔粰瀛愯矾鐢� + route.children = filterAsyncRouter(route.children, route, type, route) } else { delete route['children'] delete route['redirect'] @@ -97,7 +117,21 @@ if (el.children && el.children.length) { if (el.component === 'ParentView' && !lastRouter) { el.children.forEach(c => { - c.path = el.path + '/' + c.path + // 璁剧疆鐖惰矾鐢卞紩鐢� + c.parent = el; + + // 纭繚璺緞鏍煎紡姝g‘鎷兼帴 + if (el.path) { + if (c.path.startsWith('/')) { + // 缁濆璺緞淇濇寔涓嶅彉 + // 浣嗕篃璁剧疆鍘熷鐖惰矾寰勭敤浜庤彍鍗曞鑸� + c.parentPath = el.path; + } else { + // 鐩稿璺緞闇�瑕佹嫾鎺� + c.path = el.path.endsWith('/') ? el.path + c.path : el.path + '/' + c.path; + } + } + if (c.children && c.children.length) { children = children.concat(filterChildren(c.children, c)) return @@ -108,7 +142,21 @@ } } if (lastRouter) { - el.path = lastRouter.path + '/' + el.path + // 璁剧疆鐖惰矾鐢卞紩鐢� + el.parent = lastRouter; + + // 纭繚璺緞鏍煎紡姝g‘鎷兼帴 + if (lastRouter.path) { + if (el.path.startsWith('/')) { + // 缁濆璺緞淇濇寔涓嶅彉 + // 浣嗕篃璁剧疆鍘熷鐖惰矾寰勭敤浜庤彍鍗曞鑸� + el.parentPath = lastRouter.path; + } else { + // 鐩稿璺緞闇�瑕佹嫾鎺� + el.path = lastRouter.path.endsWith('/') ? lastRouter.path + el.path : lastRouter.path + '/' + el.path; + } + } + if (el.children && el.children.length) { children = children.concat(filterChildren(el.children, el)) return -- Gitblit v1.9.3