press-next
Version:
Vue3 组件库,支持 Composition API
88 lines (81 loc) • 2.28 kB
text/typescript
/**
* 初始化网络请求管理类接口
* @property requestFactory 生成请求实例的工厂
*/
export interface INetworkManagerOptions {
requestFactory: any;
}
/**
* 网络参数接口
*/
export interface IBaseRequestParam {
// 请求地址
url: string;
// 请求数据
reqData?: object;
// 出现错误时是否显示toast
showMsgToast?: boolean;
// 其它数据
extra?: any;
// @deprecated 是否旧cgi,兼容旧框架接口
oldCGI?: boolean;
// @deprecated 接口命令字,兼容旧框架接口
command?: string;
// 自定义请求中header字段,仅用于web端
headers?: object;
// 自定义请求中dataType字段,仅用于小程序
dataType?: string;
// 自定义请求中header字段,仅用于小程序
header?: object;
// 请求方法:post, get,默认不填是post
method?: string;
}
/**
* 请求接口
*/
export interface IBaseRequestOptions {
// 拦截器 - 请求数据前
requestInterceptors: IInterceptor[];
// 拦截器 - 返回数据后
responseInterceptors: IInterceptor[];
// 拦截器 - 网络错误
errorInterceptors: IInterceptor[];
// 其它数据
extra?: any;
}
/**
* 拦截接口
*/
export interface IInterceptor {
/**
* 拦截处理,根据返回值决定是否执行后续的拦截器
* @param param 输入数据(请求前处理时是请求参数,返回处理时是后台返回数据)
* @param extra 其它参数
* @return [
* boolean: 是否拦截后续拦截器处理 true拦断,false不拦断
* any: 处理后的数据,会传给下个拦截器
* ]
*/
interceptor(param: any, extra?: any): Promise<[boolean, any]> | [boolean, any];
}
export interface INetworkConfig {
// 后台cgi域名,由自定义函数实现
apiDomain?: Function;
svrDomain?: {
// 开发环境域名
dev: string;
// 测试环境域名
test: string;
// 正式环境域名
prod: string;
};
dataErrorHandler?: Function;
}
export enum ErrorCode {
NeedLogin = 100000, // 未登录或者登录态过期无法续期
NeedTestPermission = 100006, // 不在测试环境白名单,需要申请白名单权限
}
export enum NetworkAddInterceptorType {
Head = 1, // 加在队列头
Tail = 2, // 加在队列尾
}