refactor(projects): 精简版+动态路由权限初步
This commit is contained in:
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;
|
||||
}
|
||||
Reference in New Issue
Block a user