feat(router): 优化路由系统并支持权限标识
- 扩展路由元数据字段,新增auth权限标识支持 - 完善路由转换器,支持从后端菜单数据提取权限标识 - 优化静态路由配置,为仪表板添加固定标签页属性 - 增强路由类型定义,支持更灵活的权限验证机制
This commit is contained in:
parent
a95fe3db06
commit
7de53bcc6d
@ -9,6 +9,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [
|
||||
componentPath: '/dashboard/monitor/index',
|
||||
id: 3,
|
||||
pid: null,
|
||||
pinTab: true,
|
||||
},
|
||||
// {
|
||||
// name: 'personal-center',
|
||||
|
||||
@ -9,7 +9,7 @@ import { clone, min, omit, pick } from 'radash'
|
||||
import { RouterLink } from 'vue-router'
|
||||
|
||||
const metaFields: AppRoute.MetaKeys[]
|
||||
= ['title', 'icon', 'requiresAuth', 'roles', 'keepAlive', 'hide', 'order', 'href', 'activeMenu', 'withoutTab', 'pinTab', 'menuType']
|
||||
= ['title', 'icon', 'requiresAuth', 'roles', 'auth', 'keepAlive', 'hide', 'order', 'href', 'activeMenu', 'withoutTab', 'pinTab', 'menuType']
|
||||
|
||||
// 将后端菜单数据转换为前端路由数据
|
||||
function transformBackendToRoute(backendRoute: AppRoute.BackendRoute): AppRoute.RowRoute {
|
||||
@ -22,6 +22,7 @@ function transformBackendToRoute(backendRoute: AppRoute.BackendRoute): AppRoute.
|
||||
redirect: backendRoute.redirect || undefined,
|
||||
title: backendRoute.menuName,
|
||||
icon: backendRoute.icon,
|
||||
auth: backendRoute.auth, // 权限标识
|
||||
requiresAuth: true, // 动态路由都需要认证
|
||||
hide: backendRoute.isHide === '0', // 0-隐藏 1-显示
|
||||
keepAlive: backendRoute.isKeepAlive === '0', // 0-是 1-否
|
||||
|
||||
4
src/typings/route.d.ts
vendored
4
src/typings/route.d.ts
vendored
@ -12,6 +12,8 @@ declare namespace AppRoute {
|
||||
requiresAuth?: boolean
|
||||
/* 可以访问的角色 */
|
||||
roles?: Entity.RoleType[]
|
||||
/* 权限标识,用于按钮权限验证 */
|
||||
auth?: string
|
||||
/* 是否开启页面缓存 */
|
||||
keepAlive?: boolean
|
||||
/* 有些路由我们并不想在菜单中显示,比如某些编辑页面。 */
|
||||
@ -52,6 +54,8 @@ declare namespace AppRoute {
|
||||
component?: string
|
||||
/** 菜单图标 */
|
||||
icon?: string
|
||||
/** 权限标识 */
|
||||
auth?: string
|
||||
/** 是否隐藏 0-隐藏 1-显示 */
|
||||
isHide: string
|
||||
/** 是否外链 */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user