mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-26 15:00:16 +08:00
refactor(projects): 精简版+动态路由权限初步
This commit is contained in:
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;
|
||||
}
|
||||
15
src/typings/common/window.d.ts
vendored
Normal file
15
src/typings/common/window.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import type {
|
||||
LoadingBarProviderInst,
|
||||
DialogProviderInst,
|
||||
MessageProviderInst,
|
||||
NotificationProviderInst
|
||||
} from 'naive-ui';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
$loadingBar?: LoadingBarProviderInst;
|
||||
$dialog?: DialogProviderInst;
|
||||
$message?: MessageProviderInst;
|
||||
$notification?: NotificationProviderInst;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user