From 04fb4c0365879949a0b71d75801af41fe400f0cd Mon Sep 17 00:00:00 2001 From: weikun <> Date: Fri, 28 Oct 2022 10:55:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B7=AF=E7=94=B1=E9=A1=B6=E7=BA=A7?= =?UTF-8?q?=E9=9D=9E=E7=9B=AE=E5=BD=95=E8=8F=9C=E5=8D=95=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin-vue3/src/utils/routerHelper.ts | 59 ++++++++++++------- yudao-ui-admin-vue3/types/router.d.ts | 1 + 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/yudao-ui-admin-vue3/src/utils/routerHelper.ts b/yudao-ui-admin-vue3/src/utils/routerHelper.ts index 73e673037..79fd410d8 100644 --- a/yudao-ui-admin-vue3/src/utils/routerHelper.ts +++ b/yudao-ui-admin-vue3/src/utils/routerHelper.ts @@ -65,30 +65,49 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord redirect: route.redirect, meta: meta } - // 目录 - if (route.children) { + //处理顶级非目录路由 + if (!route.children && route.parentId == 0 && route.component) { data.component = Layout - data.redirect = getRedirect(route.path, route.children) - // 外链 - } else if (isUrl(route.path)) { - data = { - path: '/external-link', - component: Layout, - meta: { - name: route.name - }, - children: [data] - } as AppRouteRecordRaw - // 菜单 - } else { - // 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会根path保持一致) + data.meta = {} + data.name = toCamelCase(route.path, true) + 'Parent' + data.redirect = '' + const childrenData: AppRouteRecordRaw = { + path: '', + name: toCamelCase(route.path, true), + redirect: route.redirect, + meta: meta + } const index = route?.component ? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component)) : modulesRoutesKeys.findIndex((ev) => ev.includes(route.path)) - data.component = modules[modulesRoutesKeys[index]] - } - if (route.children) { - data.children = generateRoute(route.children) + childrenData.component = modules[modulesRoutesKeys[index]] + data.children = [childrenData] + } else { + // 目录 + if (route.children) { + data.component = Layout + data.redirect = getRedirect(route.path, route.children) + // 外链 + } else if (isUrl(route.path)) { + data = { + path: '/external-link', + component: Layout, + meta: { + name: route.name + }, + children: [data] + } as AppRouteRecordRaw + // 菜单 + } else { + // 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会根path保持一致) + const index = route?.component + ? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component)) + : modulesRoutesKeys.findIndex((ev) => ev.includes(route.path)) + data.component = modules[modulesRoutesKeys[index]] + } + if (route.children) { + data.children = generateRoute(route.children) + } } res.push(data) } diff --git a/yudao-ui-admin-vue3/types/router.d.ts b/yudao-ui-admin-vue3/types/router.d.ts index ba24ac588..7cc1c2f3b 100644 --- a/yudao-ui-admin-vue3/types/router.d.ts +++ b/yudao-ui-admin-vue3/types/router.d.ts @@ -74,5 +74,6 @@ declare global { children?: AppCustomRouteRecordRaw[] keepAlive?: boolean visible?: boolean + parentId?: number } }