feat(router): 优化路由系统并支持权限标识

- 扩展路由元数据字段,新增auth权限标识支持
- 完善路由转换器,支持从后端菜单数据提取权限标识
- 优化静态路由配置,为仪表板添加固定标签页属性
- 增强路由类型定义,支持更灵活的权限验证机制
This commit is contained in:
Leo 2025-07-08 10:54:10 +08:00
parent a95fe3db06
commit 7de53bcc6d
3 changed files with 7 additions and 1 deletions

View File

@ -9,6 +9,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [
componentPath: '/dashboard/monitor/index', componentPath: '/dashboard/monitor/index',
id: 3, id: 3,
pid: null, pid: null,
pinTab: true,
}, },
// { // {
// name: 'personal-center', // name: 'personal-center',

View File

@ -9,7 +9,7 @@ import { clone, min, omit, pick } from 'radash'
import { RouterLink } from 'vue-router' import { RouterLink } from 'vue-router'
const metaFields: AppRoute.MetaKeys[] 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 { function transformBackendToRoute(backendRoute: AppRoute.BackendRoute): AppRoute.RowRoute {
@ -22,6 +22,7 @@ function transformBackendToRoute(backendRoute: AppRoute.BackendRoute): AppRoute.
redirect: backendRoute.redirect || undefined, redirect: backendRoute.redirect || undefined,
title: backendRoute.menuName, title: backendRoute.menuName,
icon: backendRoute.icon, icon: backendRoute.icon,
auth: backendRoute.auth, // 权限标识
requiresAuth: true, // 动态路由都需要认证 requiresAuth: true, // 动态路由都需要认证
hide: backendRoute.isHide === '0', // 0-隐藏 1-显示 hide: backendRoute.isHide === '0', // 0-隐藏 1-显示
keepAlive: backendRoute.isKeepAlive === '0', // 0-是 1-否 keepAlive: backendRoute.isKeepAlive === '0', // 0-是 1-否

View File

@ -12,6 +12,8 @@ declare namespace AppRoute {
requiresAuth?: boolean requiresAuth?: boolean
/* 可以访问的角色 */ /* 可以访问的角色 */
roles?: Entity.RoleType[] roles?: Entity.RoleType[]
/* 权限标识,用于按钮权限验证 */
auth?: string
/* 是否开启页面缓存 */ /* 是否开启页面缓存 */
keepAlive?: boolean keepAlive?: boolean
/* 有些路由我们并不想在菜单中显示,比如某些编辑页面。 */ /* 有些路由我们并不想在菜单中显示,比如某些编辑页面。 */
@ -52,6 +54,8 @@ declare namespace AppRoute {
component?: string component?: string
/** 菜单图标 */ /** 菜单图标 */
icon?: string icon?: string
/** 权限标识 */
auth?: string
/** 是否隐藏 0-隐藏 1-显示 */ /** 是否隐藏 0-隐藏 1-显示 */
isHide: string isHide: string
/** 是否外链 */ /** 是否外链 */