utils-uniapp 1.1.13 → 1.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/http/index.d.ts +91 -33
- package/lib/http/index.js +1 -1
- package/package.json +1 -1
package/lib/http/index.d.ts
CHANGED
|
@@ -22,16 +22,22 @@ export declare const CONTENT_TYPES: Readonly<{
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* uni请求任务对象,依赖uni‑app全局UniApp命名空间
|
|
25
|
+
* @internal
|
|
25
26
|
*/
|
|
26
27
|
type UniTask = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask;
|
|
27
28
|
|
|
29
|
+
/** @internal */
|
|
28
30
|
type UniRequestResult = UniApp.RequestSuccessCallbackResult;
|
|
31
|
+
/** @internal */
|
|
29
32
|
type UniUploadResult = UniApp.UploadFileSuccessCallbackResult;
|
|
30
|
-
|
|
33
|
+
/** @internal */
|
|
34
|
+
type UniDownloadResult = UniApp.DownloadSuccessData;
|
|
35
|
+
/** @internal */
|
|
31
36
|
type UniAnyResult = UniRequestResult | UniUploadResult | UniDownloadResult;
|
|
32
37
|
|
|
33
38
|
/**
|
|
34
39
|
* 请求失败载荷【内部类型,不对外导出】
|
|
40
|
+
* @internal
|
|
35
41
|
*/
|
|
36
42
|
type RequestFailPayload = {
|
|
37
43
|
type: 'fail';
|
|
@@ -45,7 +51,7 @@ export interface CacheAdapter {
|
|
|
45
51
|
/**
|
|
46
52
|
* 获取缓存
|
|
47
53
|
* @param key 缓存key
|
|
48
|
-
* @returns 缓存值,不存在返回undefined
|
|
54
|
+
* @returns 缓存值,不存在返回undefined;调用方需要自行做类型断言
|
|
49
55
|
*/
|
|
50
56
|
get(key: string): unknown;
|
|
51
57
|
|
|
@@ -79,17 +85,24 @@ export interface CacheConfigInput {
|
|
|
79
85
|
/**
|
|
80
86
|
* 缓存适配器实例;enable=true开启缓存时必填
|
|
81
87
|
* 支持直接传入实例,或同步获取实例的函数;禁止async异步函数
|
|
88
|
+
* @param ctx 上下文对象
|
|
89
|
+
* @param ctx.url 完整请求url
|
|
90
|
+
* @param ctx.config 组装完成即将传给uni的请求参数(request/upload/download)
|
|
91
|
+
* @param ctx.options normalizeOpts合并后的用户请求扩展配置
|
|
92
|
+
* @param ctx.cacheConfig 当前传入的缓存配置
|
|
82
93
|
*/
|
|
83
94
|
adapter?: CacheAdapter | null | ((ctx: {
|
|
84
95
|
url: string;
|
|
85
|
-
config:
|
|
86
|
-
options:
|
|
96
|
+
config: Partial<UniApp.RequestOptions | UniApp.UploadFileOption | UniApp.DownloadFileOption>;
|
|
97
|
+
options: RequestOptions;
|
|
98
|
+
cacheConfig: CacheConfig;
|
|
87
99
|
}) => CacheAdapter | null);
|
|
88
100
|
}
|
|
89
101
|
|
|
90
102
|
/**
|
|
91
103
|
* normalizeOpts 之后内部运行时缓存配置对象【内部类型,不对外导出】
|
|
92
104
|
* @description adapter 字段由内部派生生成,外部禁止传入、禁止读取使用
|
|
105
|
+
* @internal
|
|
93
106
|
*/
|
|
94
107
|
interface CacheConfig {
|
|
95
108
|
enable: boolean;
|
|
@@ -101,28 +114,49 @@ interface CacheConfig {
|
|
|
101
114
|
|
|
102
115
|
/**
|
|
103
116
|
* 请求前置拦截器【标准化后】
|
|
104
|
-
* @param
|
|
105
|
-
* @param
|
|
117
|
+
* @param payload 拦截器入参对象
|
|
118
|
+
* @param payload.config 组装完成即将传给uni的请求参数(原invokeArgs)
|
|
119
|
+
* @param payload.opts normalizeOpts合并后的完整配置
|
|
106
120
|
* @returns 处理后的请求参数
|
|
107
121
|
*/
|
|
108
|
-
type ReqInterceptor = (
|
|
122
|
+
type ReqInterceptor = (
|
|
123
|
+
payload: {
|
|
124
|
+
config: Partial<UniApp.RequestOptions | UniApp.UploadFileOption | UniApp.DownloadFileOption>;
|
|
125
|
+
opts: RequestOptions;
|
|
126
|
+
}
|
|
127
|
+
) => Promise<Partial<UniApp.RequestOptions | UniApp.UploadFileOption | UniApp.DownloadFileOption>> | Partial<UniApp.RequestOptions | UniApp.UploadFileOption | UniApp.DownloadFileOption>;
|
|
109
128
|
|
|
110
129
|
/**
|
|
111
130
|
* 响应拦截器【标准化后】
|
|
112
|
-
* @param
|
|
113
|
-
* @param
|
|
114
|
-
* @param
|
|
131
|
+
* @param payload 拦截器入参对象
|
|
132
|
+
* @param payload.res uni原始响应对象,实际类型为 UniAnyResult
|
|
133
|
+
* @param payload.config 组装完成即将传给uni的请求参数
|
|
134
|
+
* @param payload.options normalizeOpts合并后的完整配置
|
|
135
|
+
* @param payload.reloadFn 重发当前请求函数,可为null
|
|
115
136
|
* @returns 处理后业务数据
|
|
116
137
|
*/
|
|
117
|
-
type ResInterceptor = (
|
|
138
|
+
type ResInterceptor = (payload: {
|
|
139
|
+
res: unknown;
|
|
140
|
+
config: Partial<UniApp.RequestOptions | UniApp.UploadFileOption | UniApp.DownloadFileOption>;
|
|
141
|
+
options: RequestOptions;
|
|
142
|
+
reloadFn: (() => Promise<unknown>) | null;
|
|
143
|
+
}) => Promise<unknown> | unknown;
|
|
118
144
|
|
|
119
145
|
/**
|
|
120
146
|
* 错误拦截器【标准化后】
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
147
|
+
* @param payload 拦截器入参对象
|
|
148
|
+
* @param payload.err 捕获到的异常对象,可能为接口回调失败载荷 RequestFailPayload 或 JS运行异常 Error
|
|
149
|
+
* @param payload.config 组装完成即将传给uni的请求参数
|
|
150
|
+
* @param payload.options normalizeOpts合并后的完整配置
|
|
151
|
+
* @param payload.reloadFn 重发当前请求函数,可为null
|
|
123
152
|
* @returns 返回非undefined代表错误已接管;返回undefined会继续抛出异常
|
|
124
153
|
*/
|
|
125
|
-
type ErrInterceptor = (
|
|
154
|
+
type ErrInterceptor = (payload: {
|
|
155
|
+
err: RequestFailPayload | Error;
|
|
156
|
+
config: Partial<UniApp.RequestOptions | UniApp.UploadFileOption | UniApp.DownloadFileOption>;
|
|
157
|
+
options: RequestOptions;
|
|
158
|
+
reloadFn: (() => Promise<unknown>) | null;
|
|
159
|
+
}) => Promise<unknown> | unknown;
|
|
126
160
|
|
|
127
161
|
/**
|
|
128
162
|
* 用户传入拦截器:支持单个函数 / 函数数组,交由 normalizeInterceptor + composeAsync合并
|
|
@@ -133,6 +167,7 @@ export type UserErrInterceptor = ErrInterceptor | ErrInterceptor[];
|
|
|
133
167
|
|
|
134
168
|
/**
|
|
135
169
|
* normalizeOpts标准化之后的请求额外配置对象【内部运行时】
|
|
170
|
+
* @internal
|
|
136
171
|
*/
|
|
137
172
|
interface RequestOptions {
|
|
138
173
|
/**
|
|
@@ -168,7 +203,7 @@ interface RequestOptions {
|
|
|
168
203
|
*/
|
|
169
204
|
errInterceptor: ErrInterceptor;
|
|
170
205
|
/**
|
|
171
|
-
*
|
|
206
|
+
* 允许扩展自定义字段;尽量避免滥用
|
|
172
207
|
*/
|
|
173
208
|
[key: string]: any;
|
|
174
209
|
}
|
|
@@ -211,7 +246,7 @@ export interface UserRequestOpts {
|
|
|
211
246
|
*/
|
|
212
247
|
errInterceptor?: UserErrInterceptor;
|
|
213
248
|
/**
|
|
214
|
-
*
|
|
249
|
+
* 允许扩展自定义字段;尽量避免滥用
|
|
215
250
|
*/
|
|
216
251
|
[key: string]: any;
|
|
217
252
|
}
|
|
@@ -232,7 +267,7 @@ export type HttpRequestConfig = Partial<Omit<UniApp.RequestOptions, 'url' | 'hea
|
|
|
232
267
|
* 上传config:uni.uploadFile配置,排除内部强制覆盖字段
|
|
233
268
|
* @note baseURL 为库自定义字段,非uni.uploadFile原生API字段
|
|
234
269
|
*/
|
|
235
|
-
export type UploadConfig = Partial<Omit<UniApp.
|
|
270
|
+
export type UploadConfig = Partial<Omit<UniApp.UploadFileOption, 'url' | 'header' | 'filePath' | 'name' | 'formData' | 'cancelToken'>> & {
|
|
236
271
|
/** 库自定义:请求基础地址 */
|
|
237
272
|
baseURL?: string;
|
|
238
273
|
/** 库自定义:headers支持对象或者返回对象的工厂函数 */
|
|
@@ -244,7 +279,7 @@ export type UploadConfig = Partial<Omit<UniApp.UploadFileOptions, 'url' | 'heade
|
|
|
244
279
|
* 下载config:uni.downloadFile配置,排除内部强制覆盖字段
|
|
245
280
|
* @note baseURL 为库自定义字段,非uni.downloadFile原生API字段
|
|
246
281
|
*/
|
|
247
|
-
export type DownloadConfig = Partial<Omit<UniApp.
|
|
282
|
+
export type DownloadConfig = Partial<Omit<UniApp.DownloadFileOption, 'url' | 'header' | 'cancelToken'>> & {
|
|
248
283
|
/** 库自定义:请求基础地址 */
|
|
249
284
|
baseURL?: string;
|
|
250
285
|
/** 库自定义:headers支持对象或者返回对象的工厂函数 */
|
|
@@ -273,6 +308,7 @@ export declare const CancelToken: {
|
|
|
273
308
|
/**
|
|
274
309
|
* 根据token终止请求
|
|
275
310
|
* @param token 取消令牌
|
|
311
|
+
* @internal 内部方法,业务请勿直接调用
|
|
276
312
|
*/
|
|
277
313
|
_cancel(token: string): void;
|
|
278
314
|
|
|
@@ -292,10 +328,13 @@ export declare const CancelToken: {
|
|
|
292
328
|
* 包装uni异步API为Promise
|
|
293
329
|
* @param type uni接口名称 request | uploadFile | downloadFile
|
|
294
330
|
* @param opts 请求参数,可以传入 cancelToken 用于请求取消
|
|
295
|
-
* @description
|
|
331
|
+
* @description 返回uni原始成功回调对象;catch捕获为 RequestFailPayload | Error
|
|
296
332
|
* @returns uni接口回调结果Promise
|
|
297
333
|
*/
|
|
298
|
-
export declare function promisifyRequest
|
|
334
|
+
export declare function promisifyRequest(
|
|
335
|
+
type: 'request' | 'uploadFile' | 'downloadFile',
|
|
336
|
+
opts: Partial<UniApp.RequestOptions | UniApp.UploadFileOption | UniApp.DownloadFileOption>
|
|
337
|
+
): Promise<UniAnyResult>;
|
|
299
338
|
|
|
300
339
|
/**
|
|
301
340
|
* 底层直接展示loading,不做计数
|
|
@@ -319,6 +358,14 @@ export declare function startLoading(title?: string): void;
|
|
|
319
358
|
*/
|
|
320
359
|
export declare function endLoading(): void;
|
|
321
360
|
|
|
361
|
+
/**
|
|
362
|
+
* 请求返回Promise扩展类型,携带取消能力
|
|
363
|
+
*/
|
|
364
|
+
export interface RequestPromise<T> extends Promise<T> {
|
|
365
|
+
cancel(): void;
|
|
366
|
+
token: string;
|
|
367
|
+
}
|
|
368
|
+
|
|
322
369
|
/**
|
|
323
370
|
* createRequest返回的请求实例对象,支持泛型T指定响应类型
|
|
324
371
|
*/
|
|
@@ -327,32 +374,32 @@ export interface RequestInstance {
|
|
|
327
374
|
* 基础请求调用
|
|
328
375
|
* @param url 请求地址
|
|
329
376
|
* @param method http方法 get/post/put/delete等
|
|
330
|
-
* @param params
|
|
377
|
+
* @param params 请求body/query参数,库不做类型校验
|
|
331
378
|
* @param [config] 当前请求配置,覆盖实例defaultConfig(baseURL、headers等)
|
|
332
379
|
* @param [options] 当前请求扩展选项,覆盖实例defaultOpts(loading、缓存、拦截器)
|
|
333
|
-
* @returns Promise
|
|
380
|
+
* @returns Promise业务响应数据,附加cancel、token属性
|
|
334
381
|
*/
|
|
335
|
-
<T = any>(url: string, method: string, params: any, config?: HttpRequestConfig, options?: UserRequestOpts):
|
|
382
|
+
<T = any>(url: string, method: string, params: any, config?: HttpRequestConfig, options?: UserRequestOpts): RequestPromise<T>;
|
|
336
383
|
|
|
337
384
|
/**
|
|
338
385
|
* get快捷方法
|
|
339
386
|
* @param url 请求地址
|
|
340
|
-
* @param params
|
|
387
|
+
* @param params 请求body/query参数,库不做类型校验
|
|
341
388
|
* @param [config] 当前请求配置
|
|
342
389
|
* @param [options] 当前请求扩展选项
|
|
343
|
-
* @returns Promise
|
|
390
|
+
* @returns Promise业务响应数据,附加cancel、token属性
|
|
344
391
|
*/
|
|
345
|
-
get<T = any>(url: string, params: any, config?: HttpRequestConfig, options?: UserRequestOpts):
|
|
392
|
+
get<T = any>(url: string, params: any, config?: HttpRequestConfig, options?: UserRequestOpts): RequestPromise<T>;
|
|
346
393
|
|
|
347
394
|
/**
|
|
348
395
|
* post快捷方法
|
|
349
396
|
* @param url 请求地址
|
|
350
|
-
* @param params
|
|
397
|
+
* @param params 请求body/query参数,库不做类型校验
|
|
351
398
|
* @param [config] 当前请求配置
|
|
352
399
|
* @param [options] 当前请求扩展选项
|
|
353
|
-
* @returns Promise
|
|
400
|
+
* @returns Promise业务响应数据,附加cancel、token属性
|
|
354
401
|
*/
|
|
355
|
-
post<T = any>(url: string, params: any, config?: HttpRequestConfig, options?: UserRequestOpts):
|
|
402
|
+
post<T = any>(url: string, params: any, config?: HttpRequestConfig, options?: UserRequestOpts): RequestPromise<T>;
|
|
356
403
|
}
|
|
357
404
|
|
|
358
405
|
/**
|
|
@@ -366,24 +413,34 @@ export declare function createRequest(defaultConfig: HttpRequestConfig, defaultO
|
|
|
366
413
|
/**
|
|
367
414
|
* 创建上传文件实例
|
|
368
415
|
* @param defaultConfig 实例默认配置(baseURL、headers等)
|
|
369
|
-
* @param defaultOpts 实例默认扩展选项
|
|
416
|
+
* @param defaultOpts 实例默认扩展选项(loading、缓存、拦截器)
|
|
370
417
|
* @returns 上传调用函数
|
|
371
418
|
*/
|
|
372
419
|
export declare function createUploadFile(
|
|
373
420
|
defaultConfig: UploadConfig,
|
|
374
421
|
defaultOpts?: UserRequestOpts
|
|
375
|
-
): <T = any>(
|
|
422
|
+
): <T = any>(
|
|
423
|
+
url: string,
|
|
424
|
+
params: {
|
|
425
|
+
filePath: string;
|
|
426
|
+
/** keyName 映射到 uni uploadFile 的 name 字段 */
|
|
427
|
+
keyName?: string;
|
|
428
|
+
[key: string]: any;
|
|
429
|
+
},
|
|
430
|
+
config?: UploadConfig,
|
|
431
|
+
options?: UserRequestOpts
|
|
432
|
+
) => RequestPromise<T>;
|
|
376
433
|
|
|
377
434
|
/**
|
|
378
435
|
* 创建下载文件实例
|
|
379
436
|
* @param defaultConfig 实例默认配置(baseURL、headers等)
|
|
380
|
-
* @param defaultOpts 实例默认扩展选项
|
|
437
|
+
* @param defaultOpts 实例默认扩展选项(loading、缓存、拦截器)
|
|
381
438
|
* @returns 下载调用函数
|
|
382
439
|
*/
|
|
383
440
|
export declare function createDownloadFile(
|
|
384
441
|
defaultConfig: DownloadConfig,
|
|
385
442
|
defaultOpts?: UserRequestOpts
|
|
386
|
-
): <T = any>(url: string, params?: Record<string, any>, config?: DownloadConfig, options?: UserRequestOpts) =>
|
|
443
|
+
): <T = any>(url: string, params?: Record<string, any>, config?: DownloadConfig, options?: UserRequestOpts) => RequestPromise<T>;
|
|
387
444
|
|
|
388
445
|
export type {
|
|
389
446
|
CacheAdapter,
|
|
@@ -393,6 +450,7 @@ export type {
|
|
|
393
450
|
UserErrInterceptor,
|
|
394
451
|
UserRequestOpts,
|
|
395
452
|
RequestInstance,
|
|
453
|
+
RequestPromise,
|
|
396
454
|
HttpRequestConfig,
|
|
397
455
|
UploadConfig,
|
|
398
456
|
DownloadConfig
|
package/lib/http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../_rollupPluginBabelHelpers-fa19b5b2.js"),H=require("../object/index.js"),U=require("../magic/index.js");var M=["cancelToken"],G=["headers"],J=["adapter"],x=["keyName","filePath"],S=Object.freeze({JSON:"application/json;charset=UTF-8",TEXT:"text/plain;charset=UTF-8",FORM_URLENCODED:"application/x-www-form-urlencoded;charset=UTF-8",FORM_DATA:"multipart/form-data"}),C=Object.seal(function(){var e=Object.create(null);function o(a){var r=e[a];typeof(r==null?void 0:r.abort)=="function"&&r.abort()}return Object.seal({add:function(r,n){e[r]=n},delete:function(r){Reflect.deleteProperty(e,r)},_cancel:o,cancelAll:function(){Object.values(e).forEach(function(r){typeof(r==null?void 0:r.abort)=="function"&&r.abort()}),Object.keys(e).forEach(function(r){return delete e[r]})},source:function(){var r="".concat(Date.now(),"-").concat(U.getRandomStr(16));return{token:r,cancel:function(){return o(r)}}}})}());function w(e,o){return new Promise(function(a,r){var n=o.cancelToken,c=t._objectWithoutProperties(o,M),l=uni[e](t._objectSpread2(t._objectSpread2({},c),{},{success:function(i){if(i.statusCode>=200&&i.statusCode<300)return a(i);var f=new Error("HTTP status ".concat(i.statusCode));r(Object.assign(f,{type:"fail",res:i}))},fail:function(i){var f=new Error(i.errMsg||"request fail");r(Object.assign(f,{type:"fail",res:i}))},complete:function(){n&&C.delete(n)}}));n&&C.add(n,l)})}var T=0,O=!1;function D(e){O||(O=!0,uni.showLoading({title:e,mask:!0}))}function W(){O&&(O=!1,uni.hideLoading())}function z(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"加载中...";T++,T===1&&D(e)}function $(){T>0&&T--,T===0&&W()}function N(e,o){return function(a,r,n,c){return e(a,o,r,n,c)}}function I(e){return typeof e=="function"?e:function(){return e||{}}}function E(e){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=I(o.headers)(),n=I(a.headers)(),c=t._objectSpread2(t._objectSpread2(t._objectSpread2({},o),a),{},{headers:t._objectSpread2(t._objectSpread2({},r),n)}),l=c.headers,s=t._objectWithoutProperties(c,G),i=e.startsWith("http")?e:c.baseURL?"".concat(c.baseURL.replace(/\/+$/,""),"/").concat(e.replace(/^\/+/,"")):e;return{urlRes:i,headers:l,configRes:s}}function P(e){return typeof e=="function"?[e]:Array.isArray(e)?e.filter(function(o){return typeof o=="function"}):[]}function Y(e){var o=e.url,a=e.invokeArgs,r=a===void 0?{}:a,n=e.options,c=n===void 0?{}:n,l=e.cacheConfig,s=l===void 0?{}:l,i=s.adapter,f=t._objectWithoutProperties(s,J),d=t._objectSpread2({enable:!1,key:"",prefix:"api",expire:60*60,adapter:null},f);if(!d.key){var v=(d.prefix||"api").replace(/:$/,"");d.key="".concat(v,":").concat(o)}if(d.enable&&(typeof i=="function"&&(i=i({url:o,config:r,options:c,cacheConfig:d})),!(i&&typeof i.get=="function"&&typeof i.set=="function")))throw new Error("开启缓存(cacheConfig.enable=true)时,请在cacheConfig传入对应adapter的适配器,适配器必须实现 get(key)、set(key,value,expire) 方法");return Object.freeze(t._objectSpread2(t._objectSpread2({},d),{},{adapter:i}))}function F(e){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=t._objectSpread2(t._objectSpread2({qs:!0,showError:!0,cacheConfig:{},loadingText:e,loading:!0,reqInterceptor:function(c){return c},resInterceptor:function(c){return c},errInterceptor:function(){}},o),a);return["reqInterceptor","resInterceptor","errInterceptor"].forEach(function(n){var c=[].concat(t._toConsumableArray(P(o[n])),t._toConsumableArray(P(a[n])));r[n]=c.length?U.composeAsync.apply(void 0,t._toConsumableArray(c)):function(l){return l}}),r}function q(e,o){var a=Array.from(o);return function(){return e.apply(void 0,t._toConsumableArray(H.cloneDeepWithDescriptors(a)))}}function L(e,o,a,r,n){return A.apply(this,arguments)}function A(){return A=t._asyncToGenerator(t._regenerator().m(function e(o,a,r,n,c){var l,s,i,f,d,v,h;return t._regenerator().w(function(u){for(;;)switch(u.p=u.n){case 0:return l=null,n.loading&&(z(n.loadingText),l=function(){$(),l=null}),u.p=1,u.n=2,n.reqInterceptor({config:r,opts:n});case 2:return s=u.v,u.n=3,o(a,s);case 3:return i=u.v,u.n=4,n.resInterceptor({res:i,config:r,options:n,reloadFn:c});case 4:return f=u.v,u.a(2,f);case 5:return u.p=5,h=u.v,u.n=6,n.errInterceptor({err:h,config:r,options:n,reloadFn:c});case 6:if(d=u.v,d===void 0){u.n=7;break}return u.a(2,d);case 7:return u.a(2,Promise.reject(h));case 8:return u.p=8,(v=l)===null||v===void 0||v(),u.f(8);case 9:return u.a(2)}},e,null,[[1,5,8,9]])})),A.apply(this,arguments)}function B(e,o){function a(r,n,c,l,s){var i=C.source(),f=q(a,arguments),d=E(r,e,l),v=d.urlRes,h=d.headers,u=d.configRes,g=F("加载中...",o,s),k=n.toUpperCase()==="GET",R=k?S.JSON:g.qs?S.FORM_URLENCODED:S.JSON,m=t._objectSpread2({cancelToken:i.token,method:n,url:v,data:c,header:t._objectSpread2({"Content-Type":R},h)},u),p=Y({url:r,invokeArgs:m,options:g,cacheConfig:t._objectSpread2(t._objectSpread2({},o.cacheConfig),s==null?void 0:s.cacheConfig)}),b=p.enable;if(b){var _=p.adapter.get(p.key);if(_)return Promise.resolve(_)}var y=L(w,"request",m,t._objectSpread2(t._objectSpread2({},g),{},{cacheConfig:p}),f).then(function(j){return b&&p.adapter.set(p.key,j,p.expire),j});return y.cancel=i.cancel,y.token=i.token,y}return a.get=N(a,"get"),a.post=N(a,"post"),a}function V(e,o){return function a(r,n,c,l){var s=C.source(),i=q(a,arguments),f=E(r,e,c),d=f.urlRes,v=f.headers,h=f.configRes,u=F("上传中...",o,l),g=t._objectSpread2({keyName:"file"},n),k=g.keyName,R=k===void 0?"file":k,m=g.filePath,p=t._objectWithoutProperties(g,x);function b(j){return j?!!(j.startsWith("wxfile://tmp")||j.startsWith("http://tmp")||j.startsWith("http://temp")||j.startsWith("blob:")||j.startsWith("_doc/")):!1}if(!b(m))return Promise.resolve({data:m});var _=t._objectSpread2({cancelToken:s.token,url:d,filePath:m,name:R,formData:p,header:t._objectSpread2({},v)},h),y=L(w,"uploadFile",_,u,i);return y.cancel=s.cancel,y.token=s.token,y}}function X(e,o){return function a(r,n,c,l){var s=C.source(),i=q(a,arguments),f=E(r,e,c),d=f.urlRes,v=f.headers,h=f.configRes,u=F("下载中...",o,l),g=d;if(n&&t._typeof(n)==="object"&&!Array.isArray(n)){var k=Object.entries(n).filter(function(p){var b=t._slicedToArray(p,2),_=b[1];return _!=null&&_!==""}).map(function(p){var b=t._slicedToArray(p,2),_=b[0],y=b[1];return"".concat(encodeURIComponent(_),"=").concat(encodeURIComponent(y))}).join("&");k&&(g+=(g.includes("?")?"&":"?")+k)}var R=t._objectSpread2({cancelToken:s.token,url:g,header:t._objectSpread2({},v)},h),m=L(w,"downloadFile",R,u,i);return m.cancel=s.cancel,m.token=s.token,m}}exports.CONTENT_TYPES=S;exports.CancelToken=C;exports.createDownloadFile=X;exports.createRequest=B;exports.createUploadFile=V;exports.endLoading=$;exports.hideLoading=W;exports.promisifyRequest=w;exports.showLoading=D;exports.startLoading=z;
|