refactor(projects): 精简版+动态路由权限初步

This commit is contained in:
Soybean
2022-01-03 22:20:10 +08:00
parent 7a0648dba5
commit de2057f141
354 changed files with 2053 additions and 22117 deletions

View File

@ -1 +0,0 @@
/// <reference types="@amap/amap-jsapi-types" />

10
src/typings/api/route.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
/** 后端返回的路由相关类型 */
declare namespace ApiRoute {
/** 后端返回的路由数据类型 */
interface ResponseRoute {
/** 动态路由 */
routes: AuthRoute.Route[];
/** 路由首页对应的key */
home: AuthRoute.RoutePath;
}
}

View File

@ -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
View 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
View File

@ -0,0 +1,8 @@
/** 通用类型 */
declare namespace Common {
/**
* 策略模式
* [状态, 为true时执行的回调函数]
*/
type StrategyAction = [boolean, () => void];
}

25
src/typings/common/env.d.ts vendored Normal file
View 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
View 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
View 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
View 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
View File

@ -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;
}

View File

@ -1,2 +0,0 @@
/** 构建时间 */
declare const PROJECT_BUILD_TIME: string;

View File

@ -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;
}
}

View File

@ -1,6 +0,0 @@
declare module '*.vue' {
import { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, any>;
export default component;
}

View File

@ -1 +0,0 @@
declare const TMap: any;

View File

@ -1 +0,0 @@
/// <reference types="vite/client" />