From 86642691a3d3edf18617e0c540dd74f2519793b0 Mon Sep 17 00:00:00 2001 From: xingyu Date: Mon, 8 May 2023 10:13:36 +0800 Subject: [PATCH] fix: route --- src/router/helper/routeHelper.ts | 17 ++++++++++++++++- src/router/routes/modules/menu.ts | 30 ------------------------------ src/router/types.ts | 3 ++- src/store/modules/permission.ts | 6 +++--- 4 files changed, 21 insertions(+), 35 deletions(-) delete mode 100644 src/router/routes/modules/menu.ts diff --git a/src/router/helper/routeHelper.ts b/src/router/helper/routeHelper.ts index 94b5a314..04f5621e 100644 --- a/src/router/helper/routeHelper.ts +++ b/src/router/helper/routeHelper.ts @@ -55,6 +55,7 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) { meta.orderNo = item.sort meta.ignoreKeepAlive = !item.keepAlive item.meta = meta + item.name = item.name = item.componentName && item.componentName.length > 0 ? item.componentName : toCamelCase(item.path, true) children && asyncImportRoute(children) }) } @@ -145,7 +146,7 @@ export function transformObjToRoute(routeList: AppRouteModul meta.single = true route.children = [cloneDeep(route)] route.component = LAYOUT - route.name = `${route.name}Parent` + route.name = `${toCamelCase(route.path, true)}Parent` route.path = '' route.meta = meta } @@ -236,3 +237,17 @@ function isMultipleRoute(routeModule: AppRouteModule) { } return flag } + +function toCamelCase(str: string, upperCaseFirst: boolean) { + str = (str || '') + .replace(/-(.)/g, function (group1: string) { + return group1.toUpperCase() + }) + .replaceAll('-', '') + + if (upperCaseFirst && str) { + str = str.charAt(0).toUpperCase() + str.slice(1) + } + + return str +} diff --git a/src/router/routes/modules/menu.ts b/src/router/routes/modules/menu.ts deleted file mode 100644 index bc4c1d0a..00000000 --- a/src/router/routes/modules/menu.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { AppRouteModule } from '@/router/types' - -import { LAYOUT } from '@/router/constant' - -const menu: AppRouteModule = { - path: '/sysmenu', - name: 'SysMenu', - component: LAYOUT, - redirect: '/sysmenu/index', - meta: { - hideChildrenInMenu: true, - icon: 'ant-design:bank-twotone', - title: '系统菜单', - orderNo: 9999 - }, - children: [ - { - path: 'index', - name: 'SystemMenu', - component: () => import('@/views/system/menu/index.vue'), - meta: { - title: '系统菜单', - icon: 'ant-design:bank-twotone', - hideMenu: true - } - } - ] -} - -export default menu diff --git a/src/router/types.ts b/src/router/types.ts index d73841eb..25f78fef 100644 --- a/src/router/types.ts +++ b/src/router/types.ts @@ -10,11 +10,12 @@ export interface AppRouteRecordRaw extends Omit { visible?: boolean icon?: string name: string - sort: number + sort?: number parentId?: number meta: RouteMeta component?: Component | string components?: Component + componentName?: string children?: AppRouteRecordRaw[] props?: Recordable fullPath?: string diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index 5e99cd9a..16b984aa 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -8,7 +8,6 @@ import { useUserStore } from './user' import { useAppStoreWithOut } from './app' import { asyncRoutes } from '@/router/routes' import about from '@/router/routes/modules/about' -import menu from '@/router/routes/modules/menu' import dashboard from '@/router/routes/modules/dashboard' import { PAGE_NOT_FOUND_ROUTE } from '@/router/routes/basic' import { transformRouteToMenu } from '@/router/helper/menuHelper' @@ -228,7 +227,7 @@ export const usePermissionStore = defineStore('app-permission', { // Background routing to menu structure // 后台路由到菜单结构 - const backMenuList = transformRouteToMenu([dashboard, ...routeList, menu, about]) + const backMenuList = transformRouteToMenu([dashboard, ...routeList, about]) this.setBackMenuList(backMenuList) // remove meta.ignoreRoute item @@ -236,7 +235,8 @@ export const usePermissionStore = defineStore('app-permission', { routeList = filter(routeList, routeRemoveIgnoreFilter) routeList = routeList.filter(routeRemoveIgnoreFilter) routeList = flatMultiLevelRoutes(routeList) - routes = [PAGE_NOT_FOUND_ROUTE, dashboard, ...routeList, menu, about] + routes = [PAGE_NOT_FOUND_ROUTE, dashboard, ...routeList, about] + console.info(routes) break }