utils-uniapp 1.1.21 → 1.1.23

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.
@@ -40,16 +40,20 @@ type UniAnyResult = UniRequestResult | UniUploadResult | UniDownloadResult;
40
40
  * @internal
41
41
  */
42
42
  type RequestFailPayload = {
43
+ /** 失败类型标识 */
43
44
  type: 'fail';
45
+ /** uni原始回调结果 */
44
46
  res: UniApp.GeneralCallbackResult;
45
47
  };
46
48
 
47
- /** 标准化后的请求配置 */
49
+ /**
50
+ * 标准化后的请求配置
51
+ */
48
52
  type NormalizeReqConfig = Partial<UniApp.RequestOptions | UniApp.UploadFileOption | UniApp.DownloadFileOption> & {
49
53
  /** 库自定义:请求基础地址,非uni.request原生参数 */
50
54
  baseURL: string;
51
55
  /** 用于取消请求的token */
52
- cancelToken: string
56
+ cancelToken: string;
53
57
  };
54
58
 
55
59
  /**
@@ -97,81 +101,119 @@ export interface CacheConfigInput {
97
101
  * @param ctx.url 完整请求url
98
102
  * @param ctx.config 组装完成即将传给uni的请求参数(request/upload/download)
99
103
  * @param ctx.options normalizeOpts合并后的用户请求扩展配置
100
- * @param ctx.cacheConfig 当前传入的缓存配置
104
+ * @param ctx.cacheConfig 当前待生成的运行时缓存配置
101
105
  */
102
- adapter?: CacheAdapter | null | ((ctx: {
103
- url: string;
104
- config: NormalizeReqConfig;
105
- options: RequestOptions;
106
- cacheConfig: CacheConfig;
107
- }) => CacheAdapter | null);
106
+ adapter?: CacheAdapter | null | ((ctx: { url: string; config: NormalizeReqConfig; options: RequestOptions; cacheConfig: CacheConfig }) => CacheAdapter | null);
108
107
  }
109
108
 
109
+ /**
110
+ * 重载请求函数类型
111
+ * @template T
112
+ */
113
+ type ReloadFn = <T>(...newArgvs: Parameters<RequestInstance>) => RequestPromise<T>;
114
+
110
115
  /**
111
116
  * normalizeOpts 之后内部运行时缓存配置对象【内部类型,不对外导出】
112
117
  * @description adapter 字段由内部派生生成,外部禁止传入、禁止读取使用
113
118
  * @internal
114
119
  */
115
120
  interface CacheConfig {
121
+ /** 是否启用缓存 */
116
122
  readonly enable: boolean;
123
+ /** 最终生成的缓存key */
117
124
  readonly key: string;
125
+ /** 缓存key前缀 */
118
126
  readonly prefix: string;
127
+ /** 缓存有效期,单位秒 */
119
128
  readonly expire: number;
129
+ /** 缓存适配器实例 */
120
130
  readonly adapter: CacheAdapter | null;
121
131
  }
122
132
 
133
+ /** 拦截器返回类型 */
134
+ type InterceptorReturn<T> = Promise<T> | T;
123
135
  /**
124
136
  * 请求前置拦截器【标准化后】
125
- * @param invokeArgs 组装完成即将传给uni的请求参数(原invokeArgs)
126
- * @param options normalizeOpts合并后的完整配置
127
- * @returns 处理后的请求参数
137
+ * @description 若拦截器返回 null / undefined,会自动使用原始 invokeArgs;有返回值则使用拦截器输出,必须保持 NormalizeReqConfig 结构
138
+ * @param ctx 上下文
139
+ * @param ctx.invokeArgs 组装完成即将传给uni的请求参数(原invokeArgs)
140
+ * @param ctx.options normalizeOpts合并后的完整配置
141
+ * @param next 执行下一个拦截器,返回处理后的请求参数
142
+ * @returns 处理后的请求参数;返回 null/undefined 将自动兜底为原始 invokeArgs
128
143
  */
129
144
  type ReqInterceptor = (
130
- invokeArgs: NormalizeReqConfig,
131
- options: RequestOptions
132
- ) => Promise<NormalizeReqConfig> | NormalizeReqConfig;
145
+ ctx: {
146
+ /** 组装完成即将传给uni的请求参数 */
147
+ invokeArgs: NormalizeReqConfig;
148
+ /** normalizeOpts合并后的完整配置 */
149
+ options: RequestOptions;
150
+ },
151
+ next: () => InterceptorReturn<NormalizeReqConfig>
152
+ ) => InterceptorReturn<NormalizeReqConfig>;
133
153
 
134
154
  /**
135
155
  * 响应拦截器【标准化后】
136
- * @param res uni原始响应对象,实际类型为 UniAnyResult
137
- * @param payload 拦截器载荷对象
138
- * @param payload.config 组装完成即将传给uni的请求参数
139
- * @param payload.options normalizeOpts合并后的完整配置
140
- * @param payload.reloadFn 重发当前请求函数,可为null
141
- * @returns 处理后业务数据
156
+ * @description 若拦截器返回 null / undefined,会自动使用原始 res;有返回值则使用拦截器输出作为最终业务数据
157
+ * @param ctx 上下文
158
+ * @param ctx.res uni原始响应对象,实际类型为 UniAnyResult
159
+ * @param ctx.invokeArgs 组装完成即将传给uni的请求参数
160
+ * @param ctx.options normalizeOpts合并后的完整配置
161
+ * @param ctx.reload 重发当前请求函数
162
+ * @param next 执行下一个拦截器,返回处理后业务数据
163
+ * @returns 处理后业务数据;返回 null/undefined 将自动兜底为原始 res
142
164
  */
143
165
  type ResInterceptor = (
144
- res: unknown,
145
- payload: {
146
- config: NormalizeReqConfig;
166
+ ctx: {
167
+ /** uni原始响应对象 */
168
+ res: UniAnyResult;
169
+ /** 组装完成即将传给uni的请求参数 */
170
+ invokeArgs: NormalizeReqConfig;
171
+ /** normalizeOpts合并后的完整配置 */
147
172
  options: RequestOptions;
148
- reloadFn: (() => Promise<unknown>) | null;
149
- }
150
- ) => Promise<unknown> | unknown;
173
+ /** 重发当前请求函数 */
174
+ reload: ReloadFn;
175
+ },
176
+ next: () => InterceptorReturn<any>
177
+ ) => InterceptorReturn<any>;
151
178
 
179
+ /** 错误类型:接口失败载荷 | JS异常 */
180
+ type Err = RequestFailPayload | Error;
152
181
  /**
153
182
  * 错误拦截器【标准化后】
154
- * @param err 捕获到的异常对象,可能为接口回调失败载荷 RequestFailPayload 或 JS运行异常 Error
155
- * @param payload 拦截器载荷对象
156
- * @param payload.config 组装完成即将传给uni的请求参数
157
- * @param payload.options normalizeOpts合并后的完整配置
158
- * @param payload.reloadFn 重发当前请求函数,可为null
159
- * @returns 返回非undefined代表错误已接管;返回undefined会继续抛出异常
183
+ * @description 若拦截器返回 null / undefined,会自动抛出原始 err;有返回值则使用拦截器输出作为拒绝原因
184
+ * @param ctx 上下文
185
+ * @param ctx.err 捕获到的异常对象,可能为接口回调失败载荷 RequestFailPayload 或 JS运行异常 Error
186
+ * @param ctx.invokeArgs 组装完成即将传给uni的请求参数
187
+ * @param ctx.options normalizeOpts合并后的完整配置
188
+ * @param ctx.reload 重发当前请求函数
189
+ * @param next 执行下一个拦截器,返回错误载荷
190
+ * @returns 错误载荷;返回 null/undefined 将自动兜底为原始 err
160
191
  */
161
192
  type ErrInterceptor = (
162
- err: RequestFailPayload | Error,
163
- payload: {
164
- config: NormalizeReqConfig;
193
+ ctx: {
194
+ /** 捕获到的异常对象 */
195
+ err: Err;
196
+ /** 组装完成即将传给uni的请求参数 */
197
+ invokeArgs: NormalizeReqConfig;
198
+ /** normalizeOpts合并后的完整配置 */
165
199
  options: RequestOptions;
166
- reloadFn: (() => Promise<unknown>) | null;
167
- }
168
- ) => Promise<unknown> | unknown;
200
+ /** 重发当前请求函数 */
201
+ reload: ReloadFn;
202
+ },
203
+ next: () => InterceptorReturn<Err>
204
+ ) => InterceptorReturn<Err>;
169
205
 
170
206
  /**
171
207
  * 用户传入拦截器:支持单个函数 / 函数数组,交由 normalizeInterceptor + composeAsync合并
172
208
  */
173
209
  export type UserReqInterceptor = ReqInterceptor | ReqInterceptor[];
210
+ /**
211
+ * 用户传入响应拦截器:支持单个函数 / 函数数组,交由 normalizeInterceptor + composeAsync合并
212
+ */
174
213
  export type UserResInterceptor = ResInterceptor | ResInterceptor[];
214
+ /**
215
+ * 用户传入错误拦截器:支持单个函数 / 函数数组,交由 normalizeInterceptor + composeAsync合并
216
+ */
175
217
  export type UserErrInterceptor = ErrInterceptor | ErrInterceptor[];
176
218
 
177
219
  /**
@@ -243,15 +285,40 @@ export interface UserRequestOpts {
243
285
  */
244
286
  loading?: boolean;
245
287
  /**
246
- * 请求前置拦截器,支持单个函数或函数数组
288
+ * 请求前置拦截器
289
+ * - 支持单个拦截器函数 / 拦截器函数数组,多个拦截器按顺序链式执行
290
+ * - 拦截器返回 null / undefined 时,自动沿用原始 invokeArgs
291
+ * @param ctx 上下文
292
+ * @param ctx.invokeArgs 组装完成即将传给uni的请求参数
293
+ * @param ctx.options normalizeOpts合并后的完整配置
294
+ * @param next 执行下一个拦截器,返回处理后的请求参数
295
+ * @returns 处理后的请求参数,返回 null/undefined 将自动兜底原始invokeArgs
247
296
  */
248
297
  reqInterceptor?: UserReqInterceptor;
249
298
  /**
250
- * 响应拦截器,支持单个函数或函数数组
299
+ * 响应拦截器
300
+ * - 支持单个拦截器函数 / 拦截器函数数组,多个拦截器按顺序链式执行
301
+ * - 拦截器返回 null / undefined 时,自动沿用原始响应res
302
+ * @param ctx 上下文
303
+ * @param ctx.res uni原始响应对象
304
+ * @param ctx.invokeArgs 组装完成即将传给uni的请求参数
305
+ * @param ctx.options normalizeOpts合并后的完整配置
306
+ * @param ctx.reload 重发当前请求函数
307
+ * @param next 执行下一个拦截器,返回处理后业务数据
308
+ * @returns 处理后业务数据,返回 null/undefined 将自动兜底原始res
251
309
  */
252
310
  resInterceptor?: UserResInterceptor;
253
311
  /**
254
- * 错误拦截器,支持单个函数或函数数组
312
+ * 错误拦截器
313
+ * - 支持单个拦截器函数 / 拦截器函数数组,多个拦截器按顺序链式执行
314
+ * - 拦截器返回 null / undefined 时,自动抛出原始err
315
+ * @param ctx 上下文
316
+ * @param ctx.err 捕获到的异常对象(RequestFailPayload | Error)
317
+ * @param ctx.invokeArgs 组装完成即将传给uni的请求参数
318
+ * @param ctx.options normalizeOpts合并后的完整配置
319
+ * @param ctx.reload 重发当前请求函数
320
+ * @param next 执行下一个拦截器,返回错误载荷
321
+ * @returns 错误载荷,返回 null/undefined 将自动兜底原始err
255
322
  */
256
323
  errInterceptor?: UserErrInterceptor;
257
324
  /**
@@ -264,11 +331,12 @@ export interface UserRequestOpts {
264
331
  * 运行时 headers 上下文对象
265
332
  * 用于 headers 工厂函数回调,提供请求运行时信息,支持业务自定义扩展字段
266
333
  * @template T - 业务原始配置泛型,会合并到上下文对象
267
- * @property {string} url - 请求地址
334
+ * @property url - 请求完整地址
268
335
  */
269
336
  export type RuntimeHeadersCtx<T = {}> = {
337
+ /** 请求完整地址 */
270
338
  url: string;
271
- } & T
339
+ } & T;
272
340
 
273
341
  /**
274
342
  * 请求config:uni.request配置,排除内部强制覆盖字段,允许业务扩展
@@ -279,6 +347,7 @@ export type HttpRequestConfig = Partial<Omit<UniApp.RequestOptions, 'url' | 'hea
279
347
  baseURL?: string;
280
348
  /** 库自定义:headers支持对象或者返回对象的工厂函数 */
281
349
  headers?: Record<string, string> | ((ctx: RuntimeHeadersCtx<HttpRequestConfig>) => Record<string, string>);
350
+ /** 自定义扩展字段 */
282
351
  [key: string]: any;
283
352
  };
284
353
 
@@ -291,6 +360,7 @@ export type UploadConfig = Partial<Omit<UniApp.UploadFileOption, 'url' | 'header
291
360
  baseURL?: string;
292
361
  /** 库自定义:headers支持对象或者返回对象的工厂函数 */
293
362
  headers?: Record<string, string> | ((ctx: RuntimeHeadersCtx<UploadConfig>) => Record<string, string>);
363
+ /** 自定义扩展字段 */
294
364
  [key: string]: any;
295
365
  };
296
366
 
@@ -303,6 +373,7 @@ export type DownloadConfig = Partial<Omit<UniApp.DownloadFileOption, 'url' | 'he
303
373
  baseURL?: string;
304
374
  /** 库自定义:headers支持对象或者返回对象的工厂函数 */
305
375
  headers?: Record<string, string> | ((ctx: RuntimeHeadersCtx<DownloadConfig>) => Record<string, string>);
376
+ /** 自定义扩展字段 */
306
377
  [key: string]: any;
307
378
  };
308
379
 
@@ -347,13 +418,10 @@ export declare const CancelToken: {
347
418
  * 包装uni异步API为Promise
348
419
  * @param type uni接口名称 request | uploadFile | downloadFile
349
420
  * @param opts 请求参数,可以传入 cancelToken 用于请求取消
350
- * @description 返回uni原始成功回调对象;catch捕获为 RequestFailPayload | Error
421
+ * @description resolve 返回uni原始成功回调对象;catch捕获为 RequestFailPayload | Error
351
422
  * @returns uni接口回调结果Promise
352
423
  */
353
- export declare function promisifyRequest(
354
- type: 'request' | 'uploadFile' | 'downloadFile',
355
- opts: NormalizeReqConfig
356
- ): Promise<UniAnyResult>;
424
+ export declare function promisifyRequest(type: 'request' | 'uploadFile' | 'downloadFile', opts: NormalizeReqConfig): Promise<UniAnyResult>;
357
425
 
358
426
  /**
359
427
  * 底层直接展示loading,不做计数
@@ -381,7 +449,9 @@ export declare function endLoading(): void;
381
449
  * 请求返回Promise扩展类型,携带取消能力
382
450
  */
383
451
  export interface RequestPromise<T> extends Promise<T> {
452
+ /** 取消当前请求 */
384
453
  cancel(): void;
454
+ /** 当前请求的取消令牌 */
385
455
  token: string;
386
456
  }
387
457
 
@@ -441,9 +511,11 @@ export declare function createUploadFile(
441
511
  ): <T = any>(
442
512
  url: string,
443
513
  params: {
514
+ /** 文件本地路径 */
444
515
  filePath: string;
445
- /** keyName 映射到 uni uploadFile 的 name 字段 */
516
+ /** keyName 映射到 uni.uploadFile 的 name 字段(后端接收的表单字段名) */
446
517
  keyName?: string;
518
+ /** 额外表单参数 */
447
519
  [key: string]: any;
448
520
  },
449
521
  config?: UploadConfig,
package/lib/http/index.js CHANGED
@@ -1 +1 @@
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"],T=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"}),k=Object.seal(function(){var e=Object.create(null);function o(a){var n=e[a];typeof(n==null?void 0:n.abort)=="function"&&n.abort()}return Object.seal({add:function(n,r){e[n]=r},delete:function(n){Reflect.deleteProperty(e,n)},_cancel:o,cancelAll:function(){Object.values(e).forEach(function(n){typeof(n==null?void 0:n.abort)=="function"&&n.abort()}),Object.keys(e).forEach(function(n){return delete e[n]})},source:function(){var n="".concat(Date.now(),"-").concat(U.getRandomStr(16));return{token:n,cancel:function(){return o(n)}}}})}());function w(e,o){return new Promise(function(a,n){var r=o.cancelToken,u=t._objectWithoutProperties(o,M),l=uni[e](t._objectSpread2(t._objectSpread2({},u),{},{success:function(i){if(i.statusCode>=200&&i.statusCode<300)return a(i);var f=new Error("HTTP status ".concat(i.statusCode));n(Object.assign(f,{type:"fail",res:i}))},fail:function(i){var f=new Error(i.errMsg||"request fail");n(Object.assign(f,{type:"fail",res:i}))},complete:function(){r&&k.delete(r)}}));r&&k.add(r,l)})}var S=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]:"加载中...";S++,S===1&&D(e)}function $(){S>0&&S--,S===0&&W()}function N(e,o){return function(a,n,r,u){return e(a,o,n,r,u)}}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]:{},n=t._objectSpread2(t._objectSpread2({},o),a);n.headers;var r=t._objectWithoutProperties(n,G),u=I(o.headers)(t._objectSpread2({url:e},r)),l=I(a.headers)(t._objectSpread2(t._objectSpread2({url:e},r),{},{headers:t._objectSpread2({},u)})),s=t._objectSpread2(t._objectSpread2({},u),l),i=e.startsWith("http")?e:r.baseURL?"".concat(r.baseURL.replace(/\/+$/,""),"/").concat(e.replace(/^\/+/,"")):e;return{urlRes:i,headers:s,configRes:r}}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,n=a===void 0?{}:a,r=e.options,u=r===void 0?{}:r,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:n,options:u,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]:{},n=t._objectSpread2(t._objectSpread2({qs:!0,showError:!0,cacheConfig:{},loadingText:e,loading:!0,reqInterceptor:function(u){return u},resInterceptor:function(u){return u},errInterceptor:function(){}},o),a);return["reqInterceptor","resInterceptor","errInterceptor"].forEach(function(r){var u=[].concat(t._toConsumableArray(P(o[r])),t._toConsumableArray(P(a[r])));n[r]=u.length?U.composeAsync.apply(void 0,t._toConsumableArray(u)):function(l){return l}}),n}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,n,r){return A.apply(this,arguments)}function A(){return A=t._asyncToGenerator(t._regenerator().m(function e(o,a,n,r,u){var l,s,i,f,d,v,h;return t._regenerator().w(function(c){for(;;)switch(c.p=c.n){case 0:return l=null,r.loading&&(z(r.loadingText),l=function(){$(),l=null}),c.p=1,c.n=2,r.reqInterceptor(n,r);case 2:return s=c.v,c.n=3,o(a,s);case 3:return i=c.v,c.n=4,r.resInterceptor(i,{config:n,options:r,reloadFn:u});case 4:return f=c.v,c.a(2,f);case 5:return c.p=5,h=c.v,c.n=6,r.errInterceptor(h,{config:n,options:r,reloadFn:u});case 6:if(d=c.v,d===void 0){c.n=7;break}return c.a(2,d);case 7:return c.a(2,Promise.reject(h));case 8:return c.p=8,(v=l)===null||v===void 0||v(),c.f(8);case 9:return c.a(2)}},e,null,[[1,5,8,9]])})),A.apply(this,arguments)}function B(e,o){function a(n,r,u,l,s){var i=k.source(),f=q(a,arguments),d=E(n,e,l),v=d.urlRes,h=d.headers,c=d.configRes,g=F("加载中...",o,s),C=r.toUpperCase()==="GET",R=C?T.JSON:g.qs?T.FORM_URLENCODED:T.JSON,m=t._objectSpread2({cancelToken:i.token,method:r,url:v,data:u,header:t._objectSpread2({"Content-Type":R},h)},c),p=Y({url:n,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(n,r,u,l){var s=k.source(),i=q(a,arguments),f=E(n,e,u),d=f.urlRes,v=f.headers,h=f.configRes,c=F("上传中...",o,l),g=t._objectSpread2({keyName:"file"},r),C=g.keyName,R=C===void 0?"file":C,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",_,c,i);return y.cancel=s.cancel,y.token=s.token,y}}function X(e,o){return function a(n,r,u,l){var s=k.source(),i=q(a,arguments),f=E(n,e,u),d=f.urlRes,v=f.headers,h=f.configRes,c=F("下载中...",o,l),g=d;if(r&&t._typeof(r)==="object"&&!Array.isArray(r)){var C=Object.entries(r).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("&");C&&(g+=(g.includes("?")?"&":"?")+C)}var R=t._objectSpread2({cancelToken:s.token,url:g,header:t._objectSpread2({},v)},h),m=L(w,"downloadFile",R,c,i);return m.cancel=s.cancel,m.token=s.token,m}}exports.CONTENT_TYPES=T;exports.CancelToken=k;exports.createDownloadFile=X;exports.createRequest=B;exports.createUploadFile=V;exports.endLoading=$;exports.hideLoading=W;exports.promisifyRequest=w;exports.showLoading=D;exports.startLoading=z;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../_rollupPluginBabelHelpers-fa19b5b2.js"),$=require("../object/index.js"),G=require("../magic/index.js");var H=["cancelToken"],M=["headers"],J=["adapter"],Y=["keyName","filePath"];function B(){for(var t=arguments.length,c=new Array(t),i=0;i<t;i++)c[i]=arguments[i];if(c.some(function(r){return typeof r!="function"}))throw new TypeError("composeAsync 参数必须是函数");return c.length===0?n._asyncToGenerator(n._regenerator().m(function r(){var e,a,s,u=arguments;return n._regenerator().w(function(o){for(;;)switch(o.n){case 0:for(e=u.length,a=new Array(e),s=0;s<e;s++)a[s]=u[s];return o.a(2,a.length===1?a[0]:a)}},r)})):c.reduce(function(r,e){return n._asyncToGenerator(n._regenerator().m(function a(){var s=this,u,o,f,d=arguments;return n._regenerator().w(function(p){for(;;)switch(p.n){case 0:for(u=d.length,o=new Array(u),f=0;f<u;f++)o[f]=d[f];return p.a(2,e.call.apply(e,[this].concat(o,[n._asyncToGenerator(n._regenerator().m(function h(){return n._regenerator().w(function(l){for(;;)switch(l.n){case 0:return l.a(2,r.apply(s,o))}},h)}))])))}},a,this)}))},n._asyncToGenerator(n._regenerator().m(function r(){var e,a,s,u=arguments;return n._regenerator().w(function(o){for(;;)switch(o.n){case 0:for(e=u.length,a=new Array(e),s=0;s<e;s++)a[s]=u[s];return o.a(2,a.length===1?a[0]:a)}},r)})))}var R=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 t=Object.create(null);function c(i){var r=t[i];typeof(r==null?void 0:r.abort)=="function"&&r.abort()}return Object.seal({add:function(r,e){t[r]=e},delete:function(r){Reflect.deleteProperty(t,r)},_cancel:c,cancelAll:function(){Object.values(t).forEach(function(r){typeof(r==null?void 0:r.abort)=="function"&&r.abort()}),Object.keys(t).forEach(function(r){return delete t[r]})},source:function(){var r="".concat(Date.now(),"-").concat(G.getRandomStr(16));return{token:r,cancel:function(){return c(r)}}}})}());function A(t,c){return new Promise(function(i,r){var e=c.cancelToken,a=n._objectWithoutProperties(c,H),s=uni[t](n._objectSpread2(n._objectSpread2({},a),{},{success:function(o){if(o.statusCode>=200&&o.statusCode<300)return i(o);var f=Object.assign(new Error("HTTP status ".concat(o.statusCode)),{type:"fail",res:o});r(f)},fail:function(o){var f=Object.assign(new Error(o.errMsg||"request fail"),{type:"fail",res:o});r(f)},complete:function(){e&&C.delete(e)}}));e&&C.add(e,s)})}var T=0,S=!1;function U(t){S||(S=!0,uni.showLoading({title:t,mask:!0}))}function D(){S&&(S=!1,uni.hideLoading())}function W(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"加载中...";T++,T===1&&U(t)}function z(){T>0&&T--,T===0&&D()}function N(t,c){return function(i,r,e,a){return t(i,c,r,e,a)}}function I(t){return typeof t=="function"?t:function(){return t||{}}}function E(t){var c=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=n._objectSpread2(n._objectSpread2({},c),i);r.headers;var e=n._objectWithoutProperties(r,M),a=I(c.headers)(n._objectSpread2({url:t},e)),s=I(i.headers)(n._objectSpread2(n._objectSpread2({url:t},e),{},{headers:n._objectSpread2({},a)})),u=n._objectSpread2(n._objectSpread2({},a),s),o=t.startsWith("http")?t:e.baseURL?"".concat(e.baseURL.replace(/\/+$/,""),"/").concat(t.replace(/^\/+/,"")):t;return{urlRes:o,headers:u,configRes:e}}function P(t){return typeof t=="function"?[t]:Array.isArray(t)?t.filter(function(c){return typeof c=="function"}):[]}function V(t){var c=t.url,i=t.invokeArgs,r=i===void 0?{}:i,e=t.options,a=e===void 0?{}:e,s=t.cacheConfig,u=s===void 0?{}:s,o=u.adapter,f=n._objectWithoutProperties(u,J),d=n._objectSpread2({enable:!1,key:"",prefix:"api",expire:60*60,adapter:null},f);if(!d.key){var p=(d.prefix||"api").replace(/:$/,"");d.key="".concat(p,":").concat(c)}if(d.enable&&(typeof o=="function"&&(o=o({url:c,config:r,options:a,cacheConfig:d})),!(o&&typeof o.get=="function"&&typeof o.set=="function")))throw new Error("开启缓存(cacheConfig.enable=true)时,请在cacheConfig传入对应adapter的适配器,适配器必须实现 get(key)、set(key,value,expire) 方法");return Object.freeze(n._objectSpread2(n._objectSpread2({},d),{},{adapter:o}))}function q(t){var c=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=n._objectSpread2(n._objectSpread2({qs:!0,showError:!0,cacheConfig:{},loadingText:t,loading:!0,reqInterceptor:function(a){return a.invokeArgs},resInterceptor:function(a){return a.res},errInterceptor:function(a){return a.err}},c),i);return["reqInterceptor","resInterceptor","errInterceptor"].forEach(function(e){var a=[].concat(n._toConsumableArray(P(c[e])),n._toConsumableArray(P(i[e])));a.length&&(r[e]=B.apply(void 0,n._toConsumableArray(a)))}),r}function F(t,c){var i=Array.from(c);return function(){for(var r=arguments.length,e=new Array(r),a=0;a<r;a++)e[a]=arguments[a];return t.apply(void 0,n._toConsumableArray($.cloneDeepWithDescriptors(e.length?e:i)))}}function L(t,c,i,r,e){return O.apply(this,arguments)}function O(){return O=n._asyncToGenerator(n._regenerator().m(function t(c,i,r,e,a){var s,u,o,f,d,p,h;return n._regenerator().w(function(l){for(;;)switch(l.p=l.n){case 0:return s=null,e.loading&&(W(e.loadingText),s=function(){z(),s=null}),l.p=1,l.n=2,e.reqInterceptor({invokeArgs:r,options:e});case 2:return u=l.v,l.n=3,c(i,u!=null?u:r);case 3:return o=l.v,l.n=4,e.resInterceptor({res:o,invokeArgs:r,options:e,reload:a});case 4:return f=l.v,l.a(2,f!=null?f:o);case 5:return l.p=5,h=l.v,l.n=6,e.errInterceptor({err:h,invokeArgs:r,options:e,reload:a});case 6:return d=l.v,l.a(2,Promise.reject(d!=null?d:h));case 7:return l.p=7,(p=s)===null||p===void 0||p(),l.f(7);case 8:return l.a(2)}},t,null,[[1,5,7,8]])})),O.apply(this,arguments)}function X(t,c){function i(r,e,a,s,u){var o=C.source(),f=F(i,arguments),d=E(r,t,s),p=d.urlRes,h=d.headers,l=d.configRes,v=q("加载中...",c,u),w=e.toUpperCase()==="GET",k=w?R.JSON:v.qs?R.FORM_URLENCODED:R.JSON,m=n._objectSpread2({cancelToken:o.token,method:e,url:p,data:a,header:n._objectSpread2({"Content-Type":k},h)},l),g=V({url:r,invokeArgs:m,options:v,cacheConfig:n._objectSpread2(n._objectSpread2({},c.cacheConfig),u==null?void 0:u.cacheConfig)}),_=g.enable;if(_){var b=g.adapter.get(g.key);if(b)return Promise.resolve(b)}var y=L(A,"request",m,n._objectSpread2(n._objectSpread2({},v),{},{cacheConfig:g}),f).then(function(j){return _&&g.adapter.set(g.key,j,g.expire),j});return y.cancel=o.cancel,y.token=o.token,y}return i.get=N(i,"get"),i.post=N(i,"post"),i}function x(t,c){return function i(r,e,a,s){var u=C.source(),o=F(i,arguments),f=E(r,t,a),d=f.urlRes,p=f.headers,h=f.configRes,l=q("上传中...",c,s),v=n._objectSpread2({keyName:"file"},e),w=v.keyName,k=w===void 0?"file":w,m=v.filePath,g=n._objectWithoutProperties(v,Y);function _(j){return j?!!(j.startsWith("wxfile://tmp")||j.startsWith("http://tmp")||j.startsWith("http://temp")||j.startsWith("blob:")||j.startsWith("_doc/")):!1}if(!_(m))return Promise.resolve({data:m});var b=n._objectSpread2({cancelToken:u.token,url:d,filePath:m,name:k,formData:g,header:n._objectSpread2({},p)},h),y=L(A,"uploadFile",b,l,o);return y.cancel=u.cancel,y.token=u.token,y}}function K(t,c){return function i(r,e,a,s){var u=C.source(),o=F(i,arguments),f=E(r,t,a),d=f.urlRes,p=f.headers,h=f.configRes,l=q("下载中...",c,s),v=d;if(e&&n._typeof(e)==="object"&&!Array.isArray(e)){var w=Object.entries(e).filter(function(g){var _=n._slicedToArray(g,2),b=_[1];return b!=null&&b!==""}).map(function(g){var _=n._slicedToArray(g,2),b=_[0],y=_[1];return"".concat(encodeURIComponent(b),"=").concat(encodeURIComponent(y))}).join("&");w&&(v+=(v.includes("?")?"&":"?")+w)}var k=n._objectSpread2({cancelToken:u.token,url:v,header:n._objectSpread2({},p)},h),m=L(A,"downloadFile",k,l,o);return m.cancel=u.cancel,m.token=u.token,m}}exports.CONTENT_TYPES=R;exports.CancelToken=C;exports.createDownloadFile=K;exports.createRequest=X;exports.createUploadFile=x;exports.endLoading=z;exports.hideLoading=D;exports.promisifyRequest=A;exports.showLoading=U;exports.startLoading=W;
@@ -1,20 +1,25 @@
1
+ type AnyFn<T = any> = (...args: any[]) => T;
2
+ type FirstFn = (next: <T>(e: T) => T, ...args: any[]) => any;
3
+ type NextFn = (next: AnyFn, ...args: any[]) => any;
4
+ type DropFirst<T extends readonly any[]> = T extends [any, ...infer Rest] ? Rest : [];
5
+ type DropRes<T extends AnyFn> = T extends (...args: infer A) => infer P ? (...argvs: DropFirst<A>) => P : never;
1
6
  // 基础组合类型
2
7
  type Compose<T extends any[]> = T extends [infer F]
3
8
  ? F
4
- : T extends [infer F, ...infer R]
5
- ? F extends (...args: any[]) => any
6
- ? Compose<R> extends (...args: any[]) => any
7
- ? (...args: Parameters<Compose<R>>) => ReturnType<F>
9
+ : T extends [...infer Left, infer Last]
10
+ ? Last extends NextFn
11
+ ? Compose<Left> extends AnyFn
12
+ ? (...args: DropFirst<Parameters<Extract<Last, AnyFn>>>) => ReturnType<Compose<Left>>
8
13
  : never
9
14
  : never
10
15
  : never;
11
16
 
12
17
  type ComposeAsync<T extends any[]> = T extends [infer F]
13
18
  ? F
14
- : T extends [infer F, ...infer R]
15
- ? F extends (...args: any[]) => any
16
- ? ComposeAsync<R> extends (...args: any[]) => any
17
- ? (...args: Parameters<ComposeAsync<R>>) => Promise<Awaited<ReturnType<F>>>
19
+ : T extends [...infer Left, infer Last]
20
+ ? Last extends AnyFn
21
+ ? ComposeAsync<Left> extends AnyFn
22
+ ? (...args: DropFirst<Parameters<Extract<Last, AnyFn>>>) => Promise<Awaited<ReturnType<Extract<Compose<Left>, AnyFn>>>>
18
23
  : never
19
24
  : never
20
25
  : never;
@@ -26,16 +31,16 @@ type Pipe<T extends any[]> = Compose<Reverse<T>>;
26
31
  type PipeAsync<T extends any[]> = ComposeAsync<Reverse<T>>;
27
32
 
28
33
  /** 同步 compose - 支持任意数量函数 */
29
- export function compose<T extends any[]>(...fns: T): T extends [] ? <U>(arg: U) => U : Compose<T>;
34
+ export function compose<T extends [FirstFn, ...NextFn[]]>(...fns: T): T extends [] ? <U>(arg: U) => U : Compose<T>;
30
35
 
31
36
  /** 异步 compose - 支持任意数量函数 */
32
- export function composeAsync<T extends any[]>(...fns: T): T extends [] ? <U>(arg: U) => Promise<U> : ComposeAsync<T>;
37
+ export function composeAsync<T extends [FirstFn, ...NextFn[]]>(...fns: T): T extends [] ? <U>(arg: U) => Promise<U> : ComposeAsync<T>;
33
38
 
34
39
  /** 同步 pipe - 支持任意数量函数 */
35
- export function pipe<T extends any[]>(...fns: T): T extends [] ? <U>(arg: U) => U : Pipe<T>;
40
+ export function pipe<T extends [...NextFn[], FirstFn]>(...fns: T): T extends [] ? <U>(arg: U) => U : Pipe<T>;
36
41
 
37
42
  /** 异步 pipe - 支持任意数量函数 */
38
- export function pipeAsync<T extends any[]>(...fns: T): T extends [] ? <U>(arg: U) => Promise<U> : PipeAsync<T>;
43
+ export function pipeAsync<T extends [...NextFn[], FirstFn]>(...fns: T): T extends [] ? <U>(arg: U) => Promise<U> : PipeAsync<T>;
39
44
 
40
45
  /**
41
46
  * 防抖
@@ -101,19 +106,14 @@ export interface GetQueryParamsOptions {
101
106
  * @param options 配置选项
102
107
  * @returns 解析结果
103
108
  */
104
- export declare function getQueryParams(
105
- str?: string,
106
- options?: GetQueryParamsOptions
107
- ): Record<string, string | string[]>;
109
+ export declare function getQueryParams(str?: string, options?: GetQueryParamsOptions): Record<string, string | string[]>;
108
110
 
109
111
  /**
110
112
  * 从当前页面 URL 的 search 部分解析参数(仅浏览器环境)
111
113
  * @param options 同 getQueryParams 的 options
112
114
  * @returns 解析结果
113
115
  */
114
- export declare function getQueryParamsFromSearch(
115
- options?: GetQueryParamsOptions
116
- ): Record<string, string | string[]>;
116
+ export declare function getQueryParamsFromSearch(options?: GetQueryParamsOptions): Record<string, string | string[]>;
117
117
 
118
118
  /**
119
119
  * 从当前页面 URL 的 hash 部分解析参数(仅浏览器环境)
@@ -126,9 +126,7 @@ export declare function getQueryParamsFromSearch(
126
126
  * @param options 同 getQueryParams 的 options
127
127
  * @returns 解析结果
128
128
  */
129
- export declare function getQueryParamsFromHash(
130
- options?: GetQueryParamsOptions
131
- ): Record<string, string | string[]>;
129
+ export declare function getQueryParamsFromHash(options?: GetQueryParamsOptions): Record<string, string | string[]>;
132
130
 
133
131
  /**
134
132
  * 生成随机标识串(时间戳与随机数拼接)
@@ -169,14 +167,10 @@ export function getRandomStr(len?: number, $chars?: string): string;
169
167
  * @param addQuestionMark 是否添加开头问号 ?
170
168
  * @returns query串
171
169
  */
172
- export declare function toQueryString(
173
- params: Record<string, any>,
174
- addQuestionMark?: boolean
175
- ): string;
170
+ export declare function toQueryString(params: Record<string, any>, addQuestionMark?: boolean): string;
176
171
 
177
172
  /**
178
173
  * 获取页面onLoad参数(自动解析小程序扫码scene)
179
174
  * @param { Record<string,any> } e onLoad参数
180
175
  */
181
176
  export function getOnLoadParams<T extends Record<string, any>>(e: T & { scene?: string }): T & { fromCode?: boolean } & Record<string, any>;
182
-
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../_rollupPluginBabelHelpers-fa19b5b2.js");function U(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("compose 参数必须是函数");return t.length===0?function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];return a.length===1?a[0]:a}:t.reduce(function(r,a){return function(){for(var e=this,i=arguments.length,u=new Array(i),c=0;c<i;c++)u[c]=arguments[c];return a.call.apply(a,[this,function(){for(var s=arguments.length,g=new Array(s),l=0;l<s;l++)g[l]=arguments[l];return r.apply(e,g.concat(u))}].concat(u))}})}function M(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("composeAsync 参数必须是函数");return t.length===0?f._asyncToGenerator(f._regenerator().m(function r(){var a,e,i,u=arguments;return f._regenerator().w(function(c){for(;;)switch(c.n){case 0:for(a=u.length,e=new Array(a),i=0;i<a;i++)e[i]=u[i];return c.a(2,e.length===1?e[0]:e)}},r)})):t.reduce(function(r,a){return f._asyncToGenerator(f._regenerator().m(function e(){var i=this,u,c,s,g=arguments;return f._regenerator().w(function(l){for(;;)switch(l.n){case 0:for(u=g.length,c=new Array(u),s=0;s<u;s++)c[s]=g[s];return l.a(2,a.call.apply(a,[this,f._asyncToGenerator(f._regenerator().m(function y(){var d,h,m,p=arguments;return f._regenerator().w(function(v){for(;;)switch(v.n){case 0:for(d=p.length,h=new Array(d),m=0;m<d;m++)h[m]=p[m];return v.a(2,r.apply(i,h.concat(c)))}},y)}))].concat(c)))}},e,this)}))})}function O(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("pipe 参数必须是函数");return t.length===0?function(){for(var r=arguments.length,a=new Array(r),e=0;e<r;e++)a[e]=arguments[e];return a.length===1?a[0]:a}:t.reduce(function(r,a){return function(){for(var e=this,i=arguments.length,u=new Array(i),c=0;c<i;c++)u[c]=arguments[c];return r.call.apply(r,[this,function(){for(var s=arguments.length,g=new Array(s),l=0;l<s;l++)g[l]=arguments[l];return a.apply(e,g.concat(u))}].concat(u))}})}function Q(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("pipeAsync 参数必须是函数");return t.length===0?f._asyncToGenerator(f._regenerator().m(function r(){var a,e,i,u=arguments;return f._regenerator().w(function(c){for(;;)switch(c.n){case 0:for(a=u.length,e=new Array(a),i=0;i<a;i++)e[i]=u[i];return c.a(2,e.length===1?e[0]:e)}},r)})):t.reduce(function(r,a){return f._asyncToGenerator(f._regenerator().m(function e(){var i=this,u,c,s,g=arguments;return f._regenerator().w(function(l){for(;;)switch(l.n){case 0:for(u=g.length,c=new Array(u),s=0;s<u;s++)c[s]=g[s];return l.a(2,r.call.apply(r,[this,f._asyncToGenerator(f._regenerator().m(function y(){var d,h,m,p=arguments;return f._regenerator().w(function(v){for(;;)switch(v.n){case 0:for(d=p.length,h=new Array(d),m=0;m<d;m++)h[m]=p[m];return v.a(2,a.apply(i,h.concat(c)))}},y)}))].concat(c)))}},e,this)}))})}function j(n,t){var o=null;r.stop=function(){return o&&clearTimeout(o)};function r(){for(var a=this,e=arguments.length,i=new Array(e),u=0;u<e;u++)i[u]=arguments[u];r.stop(),o=setTimeout(function(){n.apply(a,i)},t)}return r}function E(n,t){var o=null,r=[];a.stop=function(){if(o){var e;(e=r.shift())===null||e===void 0||e("cancel"),clearTimeout(o)}};function a(){for(var e=this,i=arguments.length,u=new Array(i),c=0;c<i;c++)u[c]=arguments[c];return new Promise(function(s,g){a.stop(),r.push(g),o=setTimeout(function(){s(n.apply(e,u))},t)})}return a}function G(n){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r;return o?function(){if(!r){r=!0;for(var a=arguments.length,e=new Array(a),i=0;i<a;i++)e[i]=arguments[i];typeof n=="function"&&n.apply(this,e),setTimeout(function(){r=!1},t)}}:function(){for(var a=this,e=arguments.length,i=new Array(e),u=0;u<e;u++)i[u]=arguments[u];r||(r=!0,setTimeout(function(){r=!1,typeof n=="function"&&n.apply(a,i)},t))}}function F(n){return encodeURIComponent(JSON.stringify(n||{}))}function H(n){return JSON.parse(decodeURIComponent(n||"{}"))}function T(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=t.silent,r=o===void 0?!1:o,a=t.decodePlus,e=a===void 0?!0:a,i=t.strict,u=i===void 0?!1:i,c={};if(typeof n!="string")return c;function s(b,R){var w=b;e&&(w=w.replace(/\+/g," "));try{return decodeURIComponent(w)}catch(I){return r||console.warn("Failed to decode ".concat(R?"key":"value",": ").concat(w),I),u?null:(R&&(w=w.replace(/%[0-9a-f]{2}/gi,"")),w)}}var g=n.split("#")[0],l=g.indexOf("?"),y=l>=0?g.slice(l+1):g;if(!y)return c;for(var d=y.split("&"),h=0;h<d.length;h++){var m=d[h];if(m){var p=m.indexOf("="),v=void 0,C=void 0;p===-1?(v=m,C=""):(v=m.slice(0,p),C=m.slice(p+1));var A=s(v,!0);if(A!==null){var P=s(C,!1);if(P!==null&&A){var S=c[A];S===void 0?c[A]=P:Array.isArray(S)?S.push(P):c[A]=[S,P]}}}}return c}function L(n){return typeof window=="undefined"?{}:T(window.location.search,n)}function J(n){if(typeof window=="undefined")return{};var t=window.location.hash,o=t.indexOf("?");if(o===-1)return{};var r=t.substring(o);return T(r,n)}function N(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"-";return[Date.now().toString(),Math.random().toString(16).slice(2,10),Math.random().toString(16).slice(7),n.toString()].join(t)}function q(n){return n.replace(/([^-])([^-]*)/g,function(t,o,r){return o.toLocaleUpperCase()+r.toLocaleLowerCase()}).replace(/-/g,"")}function B(n,t){n=n.split("."),t=t.split(".");for(var o=Math.max(n.length,t.length);n.length<o;)n.push("0");for(;t.length<o;)t.push("0");for(var r=0;r<o;r++){var a=parseInt(n[r]),e=parseInt(t[r]);if(a>e)return 1;if(a<e)return-1}return 0}function D(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function V(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,t=arguments.length>1?arguments[1]:void 0;n=n||32,t||(t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");for(var o=t.length,r="",a=0;a<n;a++)r+=t.charAt(Math.floor(Math.random()*o));return r}function $(n){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;if(!n||f._typeof(n)!=="object")return"";var o=[];Object.keys(n).forEach(function(a){var e=n[a];if(e!=null){var i=encodeURIComponent(a);if(Array.isArray(e)){e.forEach(function(c){var s=encodeURIComponent(c);o.push("".concat(i,"=").concat(s))});return}var u=e;f._typeof(u)==="object"&&u!==null&&(u=JSON.stringify(u)),o.push("".concat(i,"=").concat(encodeURIComponent(u)))}});var r=o.join("&");return t&&r?"?".concat(r):r}function z(n){var t=n.scene;return t&&(n=f._objectSpread2(f._objectSpread2({fromCode:!0},n),T(t))),n}exports.compareVersion=B;exports.compose=U;exports.composeAsync=M;exports.debounce=j;exports.debouncePromise=E;exports.decodeURIParams=H;exports.encodeURIParams=F;exports.getOnLoadParams=z;exports.getPascalCase=q;exports.getQueryParams=T;exports.getQueryParamsFromHash=J;exports.getQueryParamsFromSearch=L;exports.getRandom=N;exports.getRandomStr=V;exports.pipe=O;exports.pipeAsync=Q;exports.randomColor=D;exports.throttle=G;exports.toQueryString=$;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../_rollupPluginBabelHelpers-fa19b5b2.js");function U(){for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("compose 参数必须是函数");return a.length===0?function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return e.length===1?e[0]:e}:a.reduce(function(r,e){return function(){for(var n=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return e.call.apply(e,[this,function(){for(var f=arguments.length,g=new Array(f),l=0;l<f;l++)g[l]=arguments[l];return r.apply(n,g.concat(i))}].concat(i))}},function(r){return r})}function M(){for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("composeAsync 参数必须是函数");return a.length===0?s._asyncToGenerator(s._regenerator().m(function r(){var e,n,u,i=arguments;return s._regenerator().w(function(c){for(;;)switch(c.n){case 0:for(e=i.length,n=new Array(e),u=0;u<e;u++)n[u]=i[u];return c.a(2,n.length===1?n[0]:n)}},r)})):a.reduce(function(r,e){return s._asyncToGenerator(s._regenerator().m(function n(){var u=this,i,c,f,g=arguments;return s._regenerator().w(function(l){for(;;)switch(l.n){case 0:for(i=g.length,c=new Array(i),f=0;f<i;f++)c[f]=g[f];return l.a(2,e.call.apply(e,[this,s._asyncToGenerator(s._regenerator().m(function y(){var p,h,m,d=arguments;return s._regenerator().w(function(v){for(;;)switch(v.n){case 0:for(p=d.length,h=new Array(p),m=0;m<p;m++)h[m]=d[m];return v.a(2,r.apply(u,h.concat(c)))}},y)}))].concat(c)))}},n,this)}))},function(){var r=s._asyncToGenerator(s._regenerator().m(function e(n){return s._regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.a(2,n)}},e)}));return function(e){return r.apply(this,arguments)}}())}function O(){for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("pipe 参数必须是函数");return a.length===0?function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return e.length===1?e[0]:e}:a.reverse().reduce(function(r,e){return function(){for(var n=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return e.call.apply(e,[this,function(){for(var f=arguments.length,g=new Array(f),l=0;l<f;l++)g[l]=arguments[l];return r.apply(n,g.concat(i))}].concat(i))}},function(r){return r})}function Q(){for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("pipeAsync 参数必须是函数");return a.length===0?s._asyncToGenerator(s._regenerator().m(function r(){var e,n,u,i=arguments;return s._regenerator().w(function(c){for(;;)switch(c.n){case 0:for(e=i.length,n=new Array(e),u=0;u<e;u++)n[u]=i[u];return c.a(2,n.length===1?n[0]:n)}},r)})):a.reverse().reduce(function(r,e){return s._asyncToGenerator(s._regenerator().m(function n(){var u=this,i,c,f,g=arguments;return s._regenerator().w(function(l){for(;;)switch(l.n){case 0:for(i=g.length,c=new Array(i),f=0;f<i;f++)c[f]=g[f];return l.a(2,e.call.apply(e,[this,s._asyncToGenerator(s._regenerator().m(function y(){var p,h,m,d=arguments;return s._regenerator().w(function(v){for(;;)switch(v.n){case 0:for(p=d.length,h=new Array(p),m=0;m<p;m++)h[m]=d[m];return v.a(2,r.apply(u,h.concat(c)))}},y)}))].concat(c)))}},n,this)}))},function(){var r=s._asyncToGenerator(s._regenerator().m(function e(n){return s._regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.a(2,n)}},e)}));return function(e){return r.apply(this,arguments)}}())}function j(t,a){var o=null;r.stop=function(){return o&&clearTimeout(o)};function r(){for(var e=this,n=arguments.length,u=new Array(n),i=0;i<n;i++)u[i]=arguments[i];r.stop(),o=setTimeout(function(){t.apply(e,u)},a)}return r}function G(t,a){var o=null,r=[];e.stop=function(){if(o){var n;(n=r.shift())===null||n===void 0||n("cancel"),clearTimeout(o)}};function e(){for(var n=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return new Promise(function(f,g){e.stop(),r.push(g),o=setTimeout(function(){f(t.apply(n,i))},a)})}return e}function E(t){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r;return o?function(){if(!r){r=!0;for(var e=arguments.length,n=new Array(e),u=0;u<e;u++)n[u]=arguments[u];typeof t=="function"&&t.apply(this,n),setTimeout(function(){r=!1},a)}}:function(){for(var e=this,n=arguments.length,u=new Array(n),i=0;i<n;i++)u[i]=arguments[i];r||(r=!0,setTimeout(function(){r=!1,typeof t=="function"&&t.apply(e,u)},a))}}function F(t){return encodeURIComponent(JSON.stringify(t||{}))}function H(t){return JSON.parse(decodeURIComponent(t||"{}"))}function S(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=a.silent,r=o===void 0?!1:o,e=a.decodePlus,n=e===void 0?!0:e,u=a.strict,i=u===void 0?!1:u,c={};if(typeof t!="string")return c;function f(b,R){var w=b;n&&(w=w.replace(/\+/g," "));try{return decodeURIComponent(w)}catch(I){return r||console.warn("Failed to decode ".concat(R?"key":"value",": ").concat(w),I),i?null:(R&&(w=w.replace(/%[0-9a-f]{2}/gi,"")),w)}}var g=t.split("#")[0],l=g.indexOf("?"),y=l>=0?g.slice(l+1):g;if(!y)return c;for(var p=y.split("&"),h=0;h<p.length;h++){var m=p[h];if(m){var d=m.indexOf("="),v=void 0,C=void 0;d===-1?(v=m,C=""):(v=m.slice(0,d),C=m.slice(d+1));var A=f(v,!0);if(A!==null){var P=f(C,!1);if(P!==null&&A){var T=c[A];T===void 0?c[A]=P:Array.isArray(T)?T.push(P):c[A]=[T,P]}}}}return c}function L(t){return typeof window=="undefined"?{}:S(window.location.search,t)}function _(t){if(typeof window=="undefined")return{};var a=window.location.hash,o=a.indexOf("?");if(o===-1)return{};var r=a.substring(o);return S(r,t)}function J(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"-";return[Date.now().toString(),Math.random().toString(16).slice(2,10),Math.random().toString(16).slice(7),t.toString()].join(a)}function N(t){return t.replace(/([^-])([^-]*)/g,function(a,o,r){return o.toLocaleUpperCase()+r.toLocaleLowerCase()}).replace(/-/g,"")}function q(t,a){t=t.split("."),a=a.split(".");for(var o=Math.max(t.length,a.length);t.length<o;)t.push("0");for(;a.length<o;)a.push("0");for(var r=0;r<o;r++){var e=parseInt(t[r]),n=parseInt(a[r]);if(e>n)return 1;if(e<n)return-1}return 0}function B(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function D(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,a=arguments.length>1?arguments[1]:void 0;t=t||32,a||(a="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");for(var o=a.length,r="",e=0;e<t;e++)r+=a.charAt(Math.floor(Math.random()*o));return r}function V(t){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;if(!t||s._typeof(t)!=="object")return"";var o=[];Object.keys(t).forEach(function(e){var n=t[e];if(n!=null){var u=encodeURIComponent(e);if(Array.isArray(n)){n.forEach(function(c){var f=encodeURIComponent(c);o.push("".concat(u,"=").concat(f))});return}var i=n;s._typeof(i)==="object"&&i!==null&&(i=JSON.stringify(i)),o.push("".concat(u,"=").concat(encodeURIComponent(i)))}});var r=o.join("&");return a&&r?"?".concat(r):r}function $(t){var a=t.scene;return a&&(t=s._objectSpread2(s._objectSpread2({fromCode:!0},t),S(a))),t}exports.compareVersion=q;exports.compose=U;exports.composeAsync=M;exports.debounce=j;exports.debouncePromise=G;exports.decodeURIParams=H;exports.encodeURIParams=F;exports.getOnLoadParams=$;exports.getPascalCase=N;exports.getQueryParams=S;exports.getQueryParamsFromHash=_;exports.getQueryParamsFromSearch=L;exports.getRandom=J;exports.getRandomStr=D;exports.pipe=O;exports.pipeAsync=Q;exports.randomColor=B;exports.throttle=E;exports.toQueryString=V;
@@ -3,7 +3,7 @@
3
3
  * 禁止使用页面对象引用做相等判断,请使用route/fullPath字符串对比
4
4
  */
5
5
 
6
- export interface PageWrap extends UniApp.PageInstance {
6
+ export interface PageWrap extends Page.PageInstance<AnyObject, {}> {
7
7
  /** 不带开头斜杠 pages/xxx/xxx?a=1,用于路由匹配对比;基于onLoad options */
8
8
  fullPath: string | null;
9
9
  /** 带开头斜杠 /pages/xxx/xxx?a=1,可直接用于uni.navigateTo url;基于onLoad options */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-uniapp",
3
- "version": "1.1.21",
3
+ "version": "1.1.23",
4
4
  "description": "aubyn's utils for uniapp",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",