From 3208edbb18edfcae3e67ba35c216afbced5934ac Mon Sep 17 00:00:00 2001 From: zimo493 <2081182432@qq.com> Date: Wed, 3 Sep 2025 13:17:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20(store)=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=B7=AF=E7=94=B1=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E6=95=B4=E8=BF=94=E5=9B=9E=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/permission-store.ts | 28 ++++++++------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/store/modules/permission-store.ts b/src/store/modules/permission-store.ts index bf67da4e..b980176d 100644 --- a/src/store/modules/permission-store.ts +++ b/src/store/modules/permission-store.ts @@ -107,31 +107,19 @@ const parseDynamicRoutes = (rawRoutes: RouteVO[]): RouteRecordRaw[] => { }; /** - * 去除中间层的路由 `component` 属性 + * 路由处理函数 + * - 去除中间层路由 `component: Layout` 的 `component` 属性 * @param routes 路由数组 * @param isTopLevel 是否是顶层路由 */ const processRoutes = (routes: RouteVO[], isTopLevel: boolean = true): RouteVO[] => { - return routes.map((route) => { - // 创建新对象 - const newRoute: RouteVO = { - path: route.path, - name: route.name, - children: route.children, - meta: { ...route.meta }, + return routes.map(({ component, children, ...args }) => { + return { + ...args, + component: isTopLevel || component !== "Layout" ? component : undefined, + // 递归处理children,标记为非顶层 + children: children && children.length > 0 ? processRoutes(children, false) : [], }; - - // 如果是顶层或者component不是"Layout",保留component属性 - if (isTopLevel || route.component !== "Layout") { - newRoute.component = route.component; - } - - // 递归处理children,标记为非顶层 - if (route.children && route.children.length > 0) { - newRoute.children = processRoutes(route.children, false); - } - - return newRoute; }); };