ruoyi-plus-soybean/src/typings/common/route.d.ts

95 lines
2.9 KiB
TypeScript
Raw Normal View History

/** 权限路由相关类型 */
declare namespace AuthRoute {
/** 路由的key */
type RouteKey =
// 固定的路由
| 'root'
| 'login'
| 'not-found'
| 'no-permission'
| 'service-error'
| 'redirect-not-found' // 重定向not-found
// 自定义路由
| 'dashboard'
| 'dashboard_analysis'
| 'dashboard_workbench'
| 'multi-menu'
| 'multi-menu_first'
| 'multi-menu_first_second'
| 'about';
/** 路由Key转换路由Path */
type KeyToPath<Key extends string> = Key extends `${infer Left}_${infer Right}`
? KeyToPath<`${Left}/${Right}`>
: `/${Key}`;
/** 路由路径 */
2022-01-05 01:35:32 +08:00
type RoutePath<Key extends string = '' | LoginPath> =
| '/'
| Exclude<KeyToPath<RouteKey>, '/root' | '/redirect'>
| Key
| '/:path(.*)*'
| '/:pathMatch(.*)*';
/** 多级路由分割符号 */
type RouteSplitMark = '_';
/**
*
* - layout -
* - blank -
* - multi - ()
* - self - 使()
*/
type RouteComponent = 'layout' | 'blank' | 'multi' | 'self';
/** 路由描述 */
type RouteMeta = {
/** 路由标题(可用来作document.title或者菜单的名称) */
title: string;
/** 需要登录权限 */
requiresAuth?: boolean;
/** 哪些类型的用户有权限才能访问的路由 */
permissions?: Auth.RoleType[];
/** 缓存页面 */
keepAlive?: boolean;
/** 是否是空白布局 */
blankLayout?: boolean;
/** 菜单和面包屑对应的图标 */
icon?: string;
/** 是否在菜单中隐藏 */
hide?: boolean;
/** 是否作为单独的路由(作为菜单时只有自身,没有子菜单) */
single?: boolean;
/** 路由顺序,可用于菜单的排序 */
order?: number;
};
2022-01-05 01:35:32 +08:00
/** 登录路由路径 */
type LoginPath = `/login/:module(${string})?`;
/** 单个路由的类型结构(后端返回此类型结构的路由) */
2022-01-05 01:35:32 +08:00
interface Route<T extends string = '' | LoginPath> {
/** 路由名称(路由唯一标识) */
name: RouteKey;
/** 路由路径 */
path: RoutePath<T>;
/** 路由重定向 */
redirect?: RoutePath;
/**
*
* - layout: 基础布局
* - blank: 空白布局
* - multi: 多级路由布局()
* - self: 作为子路由使()
*/
component?: RouteComponent;
/** 子路由 */
children?: Route[];
/** 路由描述 */
meta: RouteMeta;
2022-01-05 01:35:32 +08:00
/** 属性 */
props?: boolean | Record<string, any> | ((to: any) => Record<string, any>);
}
}