diff --git a/src/router/guard.ts b/src/router/guard.ts index 820c2c6..0bb10c9 100644 --- a/src/router/guard.ts +++ b/src/router/guard.ts @@ -43,8 +43,8 @@ export function setupRouterGuard(router: Router) { if (!routeStore.isInitAuthRoute) { await routeStore.initAuthRoute() // 动态路由加载完回到根路由 - if (to.name === '404') { - // 等待权限路由加载好了,回到之前的路由,否则404 + if (to.name === 'notFound' || to.name === '404') { + // 等待权限路由加载好了,回到之前的路由,否则404 next({ path: to.fullPath, replace: true, diff --git a/src/router/routes.inner.ts b/src/router/routes.inner.ts index cce97df..a080117 100644 --- a/src/router/routes.inner.ts +++ b/src/router/routes.inner.ts @@ -50,7 +50,7 @@ export const routes: RouteRecordRaw[] = [ { path: '/:pathMatch(.*)*', component: () => import('@/views/error/404/index.vue'), - name: '404', + name: 'notFound', meta: { title: '找不到页面', icon: 'icon-park-outline:ghost', diff --git a/src/router/routes.static.ts b/src/router/routes.static.ts index 3ea2a3a..54104d4 100644 --- a/src/router/routes.static.ts +++ b/src/router/routes.static.ts @@ -5,30 +5,9 @@ export const staticRoutes: AppRoute.RowRoute[] = [ title: '仪表盘', requiresAuth: true, icon: 'icon-park-outline:anchor', - menuType: 'page', - componentPath: '/dashboard/monitor/index.vue', + menuType: '2', + componentPath: '/dashboard/monitor/index', id: 3, pid: null, }, - { - name: 'setting', - path: '/setting', - title: '系统管理', - requiresAuth: true, - icon: 'icon-park-outline:setting', - menuType: 'dir', - componentPath: null, - id: 35, - pid: null, - }, - { - name: 'accountSetting', - path: '/setting/account', - title: '用户管理', - requiresAuth: true, - icon: 'icon-park-outline:every-user', - componentPath: '/setting/account/index.vue', - id: 36, - pid: 35, - }, ] diff --git a/src/typings/route.d.ts b/src/typings/route.d.ts index c5c7f24..b0bdffe 100644 --- a/src/typings/route.d.ts +++ b/src/typings/route.d.ts @@ -1,6 +1,7 @@ declare namespace AppRoute { - type MenuType = 'dir' | 'page' + type MenuType = '1' | '2' | '3' // 1-目录 2-菜单 3-按钮 + /** 单个路由所携带的meta标识 */ interface RouteMeta { /* 页面标题,通常必选。 */ @@ -31,6 +32,42 @@ declare namespace AppRoute { type MetaKeys = keyof RouteMeta + // 后端返回的菜单数据结构 + interface BackendRoute { + /** 菜单ID */ + menuId: number + /** 菜单名称 */ + menuName: string + /** 英文名称 */ + enName?: string + /** 父菜单ID */ + parentId: number + /** 菜单类型 1-目录 2-菜单 3-按钮 */ + menuType: string + /** 路由名称 */ + name: string + /** 路由路径 */ + path: string + /** 组件路径 */ + component?: string + /** 菜单图标 */ + icon?: string + /** 是否隐藏 0-隐藏 1-显示 */ + isHide: string + /** 是否外链 */ + isLink?: string + /** 是否缓存 0-是 1-否 */ + isKeepAlive: string + /** 是否全屏 0-是 1-否 */ + isFull: string + /** 是否固定 0-是 1-否 */ + isAffix: string + /** 重定向地址 */ + redirect?: string | null + /** 选中路由 */ + activeMenu?: string | null + } + interface baseRoute { /** 路由名称(路由唯一标识) */ name: string