mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 精简版+动态路由权限初步
This commit is contained in:
1
src/typings/amap.d.ts
vendored
1
src/typings/amap.d.ts
vendored
@ -1 +0,0 @@
|
||||
/// <reference types="@amap/amap-jsapi-types" />
|
10
src/typings/api/route.d.ts
vendored
Normal file
10
src/typings/api/route.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/** 后端返回的路由相关类型 */
|
||||
declare namespace ApiRoute {
|
||||
/** 后端返回的路由数据类型 */
|
||||
interface ResponseRoute {
|
||||
/** 动态路由 */
|
||||
routes: AuthRoute.Route[];
|
||||
/** 路由首页对应的key */
|
||||
home: AuthRoute.RoutePath;
|
||||
}
|
||||
}
|
5
src/typings/bmapgl.d.ts
vendored
5
src/typings/bmapgl.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
/// <reference types="bmapgl" />
|
||||
declare namespace BMap {
|
||||
class Map extends BMapGL.Map {}
|
||||
class Point extends BMapGL.Point {}
|
||||
}
|
21
src/typings/business/auth.d.ts
vendored
Normal file
21
src/typings/business/auth.d.ts
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
/** 用户相关模块 */
|
||||
declare namespace Auth {
|
||||
/** 用户信息 */
|
||||
interface UserInfo {
|
||||
/** 用户id */
|
||||
userId: string;
|
||||
/** 用户名 */
|
||||
userName: string;
|
||||
/** 用户手机号 */
|
||||
userPhone: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户角色类型
|
||||
* - super: 超级管理员
|
||||
* - admin: 管理员
|
||||
* - test: 测试
|
||||
* - visitor: 游客
|
||||
*/
|
||||
type RoleType = 'super' | 'admin' | 'test' | 'visitor';
|
||||
}
|
8
src/typings/common/common.d.ts
vendored
Normal file
8
src/typings/common/common.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/** 通用类型 */
|
||||
declare namespace Common {
|
||||
/**
|
||||
* 策略模式
|
||||
* [状态, 为true时执行的回调函数]
|
||||
*/
|
||||
type StrategyAction = [boolean, () => void];
|
||||
}
|
25
src/typings/common/env.d.ts
vendored
Normal file
25
src/typings/common/env.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import { DefineComponent } from 'vue';
|
||||
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
||||
|
||||
interface ImportMetaEnv {
|
||||
/** 项目基本地址 */
|
||||
readonly BASE_URL: string;
|
||||
/** 项目名称 */
|
||||
readonly VITE_APP_NAME: string;
|
||||
/** 项目标题 */
|
||||
readonly VITE_APP_TITLE: string;
|
||||
/** 项目描述 */
|
||||
readonly VITE_APP_DESC: string;
|
||||
/** 网路请求环境类型 */
|
||||
readonly VITE_HTTP_ENV: Service.HttpEnv;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
89
src/typings/common/route.d.ts
vendored
Normal file
89
src/typings/common/route.d.ts
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
/** 权限路由相关类型 */
|
||||
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}`;
|
||||
|
||||
/** 路由路径 */
|
||||
type RoutePath<Key extends string = ''> =
|
||||
| '/'
|
||||
| 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;
|
||||
};
|
||||
|
||||
/** 单个路由的类型结构(后端返回此类型结构的路由) */
|
||||
interface Route {
|
||||
/** 路由名称(路由唯一标识) */
|
||||
name: RouteKey;
|
||||
/** 路由路径 */
|
||||
path: RoutePath;
|
||||
/** 路由重定向 */
|
||||
redirect?: RoutePath;
|
||||
/**
|
||||
* 路由组件
|
||||
* - layout: 基础布局,具有公共部分的布局
|
||||
* - blank: 空白布局
|
||||
* - multi: 多级路由布局(三级路由或三级以上时,除第一级路由和最后一级路由,其余的采用该布局)
|
||||
* - self: 作为子路由,使用自身的布局(作为最后一级路由,没有子路由)
|
||||
*/
|
||||
component?: RouteComponent;
|
||||
/** 子路由 */
|
||||
children?: Route[];
|
||||
/** 路由描述 */
|
||||
meta: RouteMeta;
|
||||
}
|
||||
}
|
7
src/typings/common/router.d.ts
vendored
Normal file
7
src/typings/common/router.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import 'vue-router';
|
||||
|
||||
declare module 'vue-router' {
|
||||
interface RouteMeta extends AuthRoute.RouteMeta {
|
||||
title: string;
|
||||
}
|
||||
}
|
54
src/typings/common/service.d.ts
vendored
Normal file
54
src/typings/common/service.d.ts
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/** 请求的相关类型 */
|
||||
declare namespace Service {
|
||||
/** 请求环境类型
|
||||
* - test:测试环境
|
||||
* - prod:正式环境 */
|
||||
type HttpEnv = 'test' | 'prod';
|
||||
|
||||
/**
|
||||
* 请求的错误类型:
|
||||
* - axios: axios错误:网络错误, 请求超时, 默认的兜底错误
|
||||
* - http: 请求成功,响应的状态码非200的错误
|
||||
* - backend: 请求成功,响应的状态码为200,由后端定义的业务错误
|
||||
*/
|
||||
type RequestErrorType = 'axios' | 'http' | 'backend';
|
||||
|
||||
/** 请求错误 */
|
||||
interface RequestError {
|
||||
/** 请求服务的错误类型 */
|
||||
type: RequestErrorType;
|
||||
/** 错误码 */
|
||||
code: string | number;
|
||||
/** 错误信息 */
|
||||
msg: string;
|
||||
}
|
||||
|
||||
/** 后端接口返回的数据的类型 */
|
||||
interface BackendServiceResult<T = any> {
|
||||
/** 状态码 */
|
||||
code: string | number;
|
||||
/** 接口数据 */
|
||||
data: T;
|
||||
/** 接口消息 */
|
||||
message: string;
|
||||
}
|
||||
|
||||
/** 自定义的请求成功结果 */
|
||||
interface SuccessResult<T = any> {
|
||||
/** 请求错误 */
|
||||
error: null;
|
||||
/** 请求数据 */
|
||||
data: T;
|
||||
}
|
||||
|
||||
/** 自定义的请求失败结果 */
|
||||
interface FailedResult {
|
||||
/** 请求错误 */
|
||||
error: RequestError;
|
||||
/** 请求数据 */
|
||||
data: null;
|
||||
}
|
||||
|
||||
/** 自定义的请求结果 */
|
||||
type RequestResult<T = any> = SuccessResult<T> | FailedResult;
|
||||
}
|
14
src/typings/env.d.ts
vendored
14
src/typings/env.d.ts
vendored
@ -1,14 +0,0 @@
|
||||
interface ImportMetaEnv {
|
||||
/** 项目基本地址 */
|
||||
VITE_BASE_URL: string;
|
||||
/** 项目名称 */
|
||||
VITE_APP_NAME: string;
|
||||
/** 项目标题 */
|
||||
VITE_APP_TITLE: string;
|
||||
/** 项目描述 */
|
||||
VITE_APP_DESC: string;
|
||||
/** 网路请求环境类型 */
|
||||
VITE_HTTP_ENV: 'DEV' | 'PROD' | 'STAGING';
|
||||
/** 网路请求地址 */
|
||||
VITE_HTTP_URL: string;
|
||||
}
|
2
src/typings/global.d.ts
vendored
2
src/typings/global.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
/** 构建时间 */
|
||||
declare const PROJECT_BUILD_TIME: string;
|
22
src/typings/router.d.ts
vendored
22
src/typings/router.d.ts
vendored
@ -1,22 +0,0 @@
|
||||
import 'vue-router';
|
||||
|
||||
declare module 'vue-router' {
|
||||
interface RouteMeta {
|
||||
/** 路由名称(作为菜单时为菜单的名称) */
|
||||
title: string;
|
||||
/** 需要登录权限 */
|
||||
requiresAuth?: boolean;
|
||||
/** 缓存页面 */
|
||||
keepAlive?: boolean;
|
||||
/** 页面占满剩余高度(去除头部、tab和底部后的高度) */
|
||||
fullPage?: boolean;
|
||||
/** 不作为菜单 */
|
||||
notAsMenu?: boolean;
|
||||
/** 菜单和面包屑对应的图标 */
|
||||
icon?: string;
|
||||
/** 导入的路由模块排序,可用于菜单的排序 */
|
||||
order?: number;
|
||||
/** y方向滚动的距离(被缓存的页面保留滚动行为) */
|
||||
scrollY?: number;
|
||||
}
|
||||
}
|
6
src/typings/shims-vue.d.ts
vendored
6
src/typings/shims-vue.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
declare module '*.vue' {
|
||||
import { DefineComponent } from 'vue';
|
||||
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
1
src/typings/tmap.d.ts
vendored
1
src/typings/tmap.d.ts
vendored
@ -1 +0,0 @@
|
||||
declare const TMap: any;
|
1
src/typings/vite-env.d.ts
vendored
1
src/typings/vite-env.d.ts
vendored
@ -1 +0,0 @@
|
||||
/// <reference types="vite/client" />
|
Reference in New Issue
Block a user