refactor(projects): 请求适配器函数范型重构、优化请求相关的命名

This commit is contained in:
Soybean
2022-07-28 13:19:50 +08:00
parent 02992dc02d
commit 7f9c98ab8d
11 changed files with 77 additions and 54 deletions

10
src/typings/env.d.ts vendored
View File

@ -8,10 +8,12 @@ type ServiceEnvType = 'dev' | 'test' | 'prod';
/** 后台服务的环境配置 */
interface ServiceEnvConfig {
/** 匹配路径的正则字符串, 用于拦截地址转发代理(任意以 /开头 + 字符串, 单个/不起作用) */
pattern: '/proxy-pattrn';
/** 请求地址 */
url: string;
/** 代理标识, 用于拦截地址转发代理(和后端请求路径中有无该路径没有关系) */
proxy: '/proxy-flag';
/** 另一个后端请求地址(有多个不同的后端服务时) */
secondUrl: string;
}
interface ImportMetaEnv {
@ -31,8 +33,8 @@ interface ImportMetaEnv {
readonly VITE_AUTH_ROUTE_MODE: 'static' | 'dynamic';
/** 路由首页的路径 */
readonly VITE_ROUTE_HOME_PATH: Exclude<AuthRoute.RoutePath, '/' | '/not-found-page' | '/:pathMatch(.*)*'>;
/** vite环境类型 */
readonly VITE_ENV_TYPE?: ServiceEnvType;
/** 后端服务的环境类型 */
readonly VITE_SERVICE_ENV?: ServiceEnvType;
/** 开启请求代理 */
readonly VITE_HTTP_PROXY?: 'Y' | 'N';
/** 是否开启打包文件大小结果分析 */

View File

@ -70,6 +70,20 @@ declare namespace Service {
/** 自定义的请求结果 */
type RequestResult<T = any> = SuccessResult<T> | FailedResult;
/** 多个请求数据结果 */
type MultiRequestResult<T extends any[]> = T extends [infer First, ...infer Rest]
? First extends any
? Rest extends any[]
? [Service.RequestResult<First>, ...MultiRequestResult<Rest>]
: [Service.RequestResult<First>]
: Rest extends any[]
? MultiRequestResult<Rest>
: []
: [];
/** 请求结果的适配器函数 */
type ServiceAdapter<T = any, A extends any[] = any> = (...args: A) => T;
/** mock示例接口类型后端接口返回的数据的类型 */
interface MockServiceResult<T = any> {
/** 状态码 */