fix: route

pull/12/head
xingyu 2023-05-08 10:13:36 +08:00
parent e7571ea66c
commit 86642691a3
4 changed files with 21 additions and 35 deletions

View File

@ -55,6 +55,7 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) {
meta.orderNo = item.sort meta.orderNo = item.sort
meta.ignoreKeepAlive = !item.keepAlive meta.ignoreKeepAlive = !item.keepAlive
item.meta = meta item.meta = meta
item.name = item.name = item.componentName && item.componentName.length > 0 ? item.componentName : toCamelCase(item.path, true)
children && asyncImportRoute(children) children && asyncImportRoute(children)
}) })
} }
@ -145,7 +146,7 @@ export function transformObjToRoute<T = AppRouteModule>(routeList: AppRouteModul
meta.single = true meta.single = true
route.children = [cloneDeep(route)] route.children = [cloneDeep(route)]
route.component = LAYOUT route.component = LAYOUT
route.name = `${route.name}Parent` route.name = `${toCamelCase(route.path, true)}Parent`
route.path = '' route.path = ''
route.meta = meta route.meta = meta
} }
@ -236,3 +237,17 @@ function isMultipleRoute(routeModule: AppRouteModule) {
} }
return flag 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
}

View File

@ -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

View File

@ -10,11 +10,12 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
visible?: boolean visible?: boolean
icon?: string icon?: string
name: string name: string
sort: number sort?: number
parentId?: number parentId?: number
meta: RouteMeta meta: RouteMeta
component?: Component | string component?: Component | string
components?: Component components?: Component
componentName?: string
children?: AppRouteRecordRaw[] children?: AppRouteRecordRaw[]
props?: Recordable props?: Recordable
fullPath?: string fullPath?: string

View File

@ -8,7 +8,6 @@ import { useUserStore } from './user'
import { useAppStoreWithOut } from './app' import { useAppStoreWithOut } from './app'
import { asyncRoutes } from '@/router/routes' import { asyncRoutes } from '@/router/routes'
import about from '@/router/routes/modules/about' import about from '@/router/routes/modules/about'
import menu from '@/router/routes/modules/menu'
import dashboard from '@/router/routes/modules/dashboard' import dashboard from '@/router/routes/modules/dashboard'
import { PAGE_NOT_FOUND_ROUTE } from '@/router/routes/basic' import { PAGE_NOT_FOUND_ROUTE } from '@/router/routes/basic'
import { transformRouteToMenu } from '@/router/helper/menuHelper' import { transformRouteToMenu } from '@/router/helper/menuHelper'
@ -228,7 +227,7 @@ export const usePermissionStore = defineStore('app-permission', {
// Background routing to menu structure // Background routing to menu structure
// 后台路由到菜单结构 // 后台路由到菜单结构
const backMenuList = transformRouteToMenu([dashboard, ...routeList, menu, about]) const backMenuList = transformRouteToMenu([dashboard, ...routeList, about])
this.setBackMenuList(backMenuList) this.setBackMenuList(backMenuList)
// remove meta.ignoreRoute item // remove meta.ignoreRoute item
@ -236,7 +235,8 @@ export const usePermissionStore = defineStore('app-permission', {
routeList = filter(routeList, routeRemoveIgnoreFilter) routeList = filter(routeList, routeRemoveIgnoreFilter)
routeList = routeList.filter(routeRemoveIgnoreFilter) routeList = routeList.filter(routeRemoveIgnoreFilter)
routeList = flatMultiLevelRoutes(routeList) routeList = flatMultiLevelRoutes(routeList)
routes = [PAGE_NOT_FOUND_ROUTE, dashboard, ...routeList, menu, about] routes = [PAGE_NOT_FOUND_ROUTE, dashboard, ...routeList, about]
console.info(routes)
break break
} }