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

154 lines
4.9 KiB
TypeScript
Raw Normal View History

/** 权限路由相关类型 */
declare namespace AuthRoute {
/** 多级路由分割符号 */
type RouteSplitMark = '_';
/** 路由的key */
type RouteKey =
// 固定的路由
| 'root' // 根路由
| 'login'
| 'not-found'
| 'no-permission'
| 'service-error'
| 'not-found-page' // 捕获无效path的路由
// 自定义路由
| 'dashboard'
| 'dashboard_analysis'
| 'dashboard_workbench'
| 'document'
| 'document_vue'
| 'document_vue-new'
| 'document_vite'
| 'document_naive'
| 'document_project'
2022-01-24 00:00:59 +08:00
| 'component'
| 'component_button'
| 'component_card'
| 'component_table'
2022-01-24 00:36:38 +08:00
| 'plugin'
| 'plugin_map'
| 'plugin_video'
| 'plugin_editor'
| 'plugin_editor_quill'
| 'plugin_editor_markdown'
| 'plugin_copy'
| 'plugin_icon'
| 'plugin_print'
| 'plugin_swiper'
2022-01-24 00:00:59 +08:00
| 'exception'
| 'exception_403'
| 'exception_404'
| 'exception_500'
| 'multi-menu'
| 'multi-menu_first'
| 'multi-menu_first_second'
| 'multi-menu_first_second-new'
| 'multi-menu_first_second-new_third'
| 'about';
/** 路由的path */
type RoutePath =
| '/'
| Exclude<KeyToPath<RouteKey>, '/root' | 'not-found-page'>
| SingleRouteParentPath
| '/:pathMatch(.*)*';
/**
*
2022-01-08 20:49:21 +08:00
* - basic -
* - blank -
* - multi - ()
* - self - 使()
*/
2022-01-08 20:49:21 +08:00
type RouteComponent = 'basic' | 'blank' | 'multi' | 'self';
/** 路由描述 */
type RouteMeta = {
/** 路由标题(可用来作document.title或者菜单的名称) */
title: string;
/** 路由的动态路径 */
dynamicPath?: PathToDynamicPath<'/login'>;
2022-01-24 00:00:59 +08:00
/** 作为单级路由的父级路由布局组件 */
2022-01-08 20:49:21 +08:00
singleLayout?: Extract<RouteComponent, 'basic' | 'blank'>;
/** 需要登录权限 */
requiresAuth?: boolean;
2022-03-30 01:19:37 +08:00
/**
* 访()
* @description
*/
permissions?: Auth.RoleType[];
/** 缓存页面 */
keepAlive?: boolean;
/** 菜单和面包屑对应的图标 */
icon?: string;
/** 是否在菜单中隐藏 */
hide?: boolean;
2022-01-24 00:00:59 +08:00
/** 外链链接 */
href?: string;
/** 路由顺序,可用于菜单的排序 */
order?: number;
/** 表示是否是多级路由的中间级路由(用于转换路由数据时筛选多级路由的标识,定义路由时不用填写) */
multi?: boolean;
};
2022-03-30 01:19:37 +08:00
/** 单个路由的类型结构(动态路由模式:后端返回此类型结构的路由) */
interface Route {
/** 路由名称(路由唯一标识) */
name: RouteKey;
/** 路由路径 */
path: RoutePath;
/** 路由重定向 */
redirect?: RoutePath;
/**
*
2022-01-08 20:49:21 +08:00
* - basic: 基础布局
* - 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>);
}
2022-03-30 01:19:37 +08:00
/** 前端导入的路由模块 */
type RouteModule = Record<string, { default: AuthRoute.Route }>;
/** 单独一级路由的key (单独路由需要添加一个父级路由用于应用布局组件) */
type SingleRouteKey = Exclude<
GetSingleRouteKey<RouteKey>,
2022-01-24 00:00:59 +08:00
GetRouteFirstParentKey<RouteKey> | 'root' | 'not-found-page'
>;
/** 单独路由父级路由key */
type SingleRouteParentKey = `${SingleRouteKey}-parent`;
/** 单独路由父级路由path */
type SingleRouteParentPath = KeyToPath<SingleRouteParentKey>;
/** 路由key转换路由path */
type KeyToPath<Key extends string> = Key extends `${infer Left}_${infer Right}`
? KeyToPath<`${Left}/${Right}`>
: `/${Key}`;
/** 路由path转换动态路径 */
type PathToDynamicPath<Path extends RoutePath> =
| `${Path}/:module`
| `${Path}/:module(${string})`
| `${Path}/:module(${string})?`;
2022-01-24 00:00:59 +08:00
/** 获取一级路由(包括有子路由的一级路由) */
type GetSingleRouteKey<Key extends RouteKey> = Key extends `${infer _Left}${RouteSplitMark}${infer _Right}`
? never
: Key;
2022-01-24 00:00:59 +08:00
/** 获取子路由的一级父路由 */
type GetRouteFirstParentKey<Key extends RouteKey> = Key extends `${infer Left}${RouteSplitMark}${infer _Right}`
? Left
: never;
}