utils-uniapp 1.1.21 → 1.1.22
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 +48 -43
- package/lib/http/index.js +1 -1
- package/lib/magic/index.d.ts +21 -27
- package/lib/magic/index.js +1 -1
- package/lib/pageStack/index.d.ts +1 -1
- package/package.json +1 -1
package/lib/http/index.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ type NormalizeReqConfig = Partial<UniApp.RequestOptions | UniApp.UploadFileOptio
|
|
|
49
49
|
/** 库自定义:请求基础地址,非uni.request原生参数 */
|
|
50
50
|
baseURL: string;
|
|
51
51
|
/** 用于取消请求的token */
|
|
52
|
-
cancelToken: string
|
|
52
|
+
cancelToken: string;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
/**
|
|
@@ -97,16 +97,13 @@ export interface CacheConfigInput {
|
|
|
97
97
|
* @param ctx.url 完整请求url
|
|
98
98
|
* @param ctx.config 组装完成即将传给uni的请求参数(request/upload/download)
|
|
99
99
|
* @param ctx.options normalizeOpts合并后的用户请求扩展配置
|
|
100
|
-
* @param ctx.cacheConfig
|
|
100
|
+
* @param ctx.cacheConfig 当前待生成的运行时缓存配置
|
|
101
101
|
*/
|
|
102
|
-
adapter?: CacheAdapter | null | ((ctx: {
|
|
103
|
-
url: string;
|
|
104
|
-
config: NormalizeReqConfig;
|
|
105
|
-
options: RequestOptions;
|
|
106
|
-
cacheConfig: CacheConfig;
|
|
107
|
-
}) => CacheAdapter | null);
|
|
102
|
+
adapter?: CacheAdapter | null | ((ctx: { url: string; config: NormalizeReqConfig; options: RequestOptions; cacheConfig: CacheConfig }) => CacheAdapter | null);
|
|
108
103
|
}
|
|
109
104
|
|
|
105
|
+
type ReloadFn = <T>(...newArgvs: Parameters<RequestInstance>) => RequestPromise<T>;
|
|
106
|
+
|
|
110
107
|
/**
|
|
111
108
|
* normalizeOpts 之后内部运行时缓存配置对象【内部类型,不对外导出】
|
|
112
109
|
* @description adapter 字段由内部派生生成,外部禁止传入、禁止读取使用
|
|
@@ -120,52 +117,63 @@ interface CacheConfig {
|
|
|
120
117
|
readonly adapter: CacheAdapter | null;
|
|
121
118
|
}
|
|
122
119
|
|
|
120
|
+
type InterceptorReturn<T> = Promise<T> | T;
|
|
123
121
|
/**
|
|
124
122
|
* 请求前置拦截器【标准化后】
|
|
125
|
-
* @param
|
|
126
|
-
* @param
|
|
123
|
+
* @param ctx 上下文
|
|
124
|
+
* @param ctx.invokeArgs 组装完成即将传给uni的请求参数(原invokeArgs)
|
|
125
|
+
* @param ctx.options normalizeOpts合并后的完整配置
|
|
126
|
+
* @param next 执行下一个拦截器,返回处理后的请求参数
|
|
127
127
|
* @returns 处理后的请求参数
|
|
128
128
|
*/
|
|
129
129
|
type ReqInterceptor = (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
ctx: {
|
|
131
|
+
invokeArgs: NormalizeReqConfig;
|
|
132
|
+
options: RequestOptions;
|
|
133
|
+
},
|
|
134
|
+
next: () => InterceptorReturn<NormalizeReqConfig>
|
|
135
|
+
) => InterceptorReturn<NormalizeReqConfig>;
|
|
133
136
|
|
|
134
137
|
/**
|
|
135
138
|
* 响应拦截器【标准化后】
|
|
136
|
-
* @param
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
139
|
+
* @param ctx 上下文
|
|
140
|
+
* @param ctx res uni原始响应对象,实际类型为 UniAnyResult
|
|
141
|
+
* @param ctx.invokeArgs 组装完成即将传给uni的请求参数
|
|
142
|
+
* @param ctx.options normalizeOpts合并后的完整配置
|
|
143
|
+
* @param ctx.reload 重发当前请求函数
|
|
144
|
+
* @param next 执行下一个拦截器,返回处理后业务数据
|
|
141
145
|
* @returns 处理后业务数据
|
|
142
146
|
*/
|
|
143
147
|
type ResInterceptor = (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
148
|
+
ctx: {
|
|
149
|
+
res: UniAnyResult;
|
|
150
|
+
invokeArgs: NormalizeReqConfig;
|
|
147
151
|
options: RequestOptions;
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
) =>
|
|
152
|
+
reload: ReloadFn;
|
|
153
|
+
},
|
|
154
|
+
next: () => InterceptorReturn<any>
|
|
155
|
+
) => InterceptorReturn<any>;
|
|
151
156
|
|
|
157
|
+
type Err = RequestFailPayload | Error;
|
|
152
158
|
/**
|
|
153
159
|
* 错误拦截器【标准化后】
|
|
154
|
-
* @param
|
|
155
|
-
* @param
|
|
156
|
-
* @param
|
|
157
|
-
* @param
|
|
158
|
-
* @param
|
|
160
|
+
* @param ctx 上下文
|
|
161
|
+
* @param ctx.err 捕获到的异常对象,可能为接口回调失败载荷 RequestFailPayload 或 JS运行异常 Error
|
|
162
|
+
* @param ctx.invokeArgs 组装完成即将传给uni的请求参数
|
|
163
|
+
* @param ctx.options normalizeOpts合并后的完整配置
|
|
164
|
+
* @param ctx.reloadFn 重发当前请求函数
|
|
165
|
+
* @param next 执行下一个拦截器,返回错误载荷
|
|
159
166
|
* @returns 返回非undefined代表错误已接管;返回undefined会继续抛出异常
|
|
160
167
|
*/
|
|
161
168
|
type ErrInterceptor = (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
ctx: {
|
|
170
|
+
err: Err;
|
|
171
|
+
invokeArgs: NormalizeReqConfig;
|
|
165
172
|
options: RequestOptions;
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
) =>
|
|
173
|
+
reload: ReloadFn;
|
|
174
|
+
},
|
|
175
|
+
next: () => InterceptorReturn<Err>
|
|
176
|
+
) => InterceptorReturn<Err>;
|
|
169
177
|
|
|
170
178
|
/**
|
|
171
179
|
* 用户传入拦截器:支持单个函数 / 函数数组,交由 normalizeInterceptor + composeAsync合并
|
|
@@ -264,11 +272,11 @@ export interface UserRequestOpts {
|
|
|
264
272
|
* 运行时 headers 上下文对象
|
|
265
273
|
* 用于 headers 工厂函数回调,提供请求运行时信息,支持业务自定义扩展字段
|
|
266
274
|
* @template T - 业务原始配置泛型,会合并到上下文对象
|
|
267
|
-
* @property
|
|
275
|
+
* @property url - 请求完整地址
|
|
268
276
|
*/
|
|
269
277
|
export type RuntimeHeadersCtx<T = {}> = {
|
|
270
278
|
url: string;
|
|
271
|
-
} & T
|
|
279
|
+
} & T;
|
|
272
280
|
|
|
273
281
|
/**
|
|
274
282
|
* 请求config:uni.request配置,排除内部强制覆盖字段,允许业务扩展
|
|
@@ -347,13 +355,10 @@ export declare const CancelToken: {
|
|
|
347
355
|
* 包装uni异步API为Promise
|
|
348
356
|
* @param type uni接口名称 request | uploadFile | downloadFile
|
|
349
357
|
* @param opts 请求参数,可以传入 cancelToken 用于请求取消
|
|
350
|
-
* @description 返回uni原始成功回调对象;catch捕获为 RequestFailPayload | Error
|
|
358
|
+
* @description resolve 返回uni原始成功回调对象;catch捕获为 RequestFailPayload | Error
|
|
351
359
|
* @returns uni接口回调结果Promise
|
|
352
360
|
*/
|
|
353
|
-
export declare function promisifyRequest(
|
|
354
|
-
type: 'request' | 'uploadFile' | 'downloadFile',
|
|
355
|
-
opts: NormalizeReqConfig
|
|
356
|
-
): Promise<UniAnyResult>;
|
|
361
|
+
export declare function promisifyRequest(type: 'request' | 'uploadFile' | 'downloadFile', opts: NormalizeReqConfig): Promise<UniAnyResult>;
|
|
357
362
|
|
|
358
363
|
/**
|
|
359
364
|
* 底层直接展示loading,不做计数
|
|
@@ -442,7 +447,7 @@ export declare function createUploadFile(
|
|
|
442
447
|
url: string,
|
|
443
448
|
params: {
|
|
444
449
|
filePath: string;
|
|
445
|
-
/** keyName 映射到 uni
|
|
450
|
+
/** keyName 映射到 uni.uploadFile 的 name 字段(后端接收的表单字段名) */
|
|
446
451
|
keyName?: string;
|
|
447
452
|
[key: string]: any;
|
|
448
453
|
},
|
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 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;
|
package/lib/magic/index.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
?
|
|
6
|
-
? Compose<
|
|
7
|
-
? (...args: Parameters<
|
|
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
|
|
15
|
-
?
|
|
16
|
-
? ComposeAsync<
|
|
17
|
-
? (...args: Parameters<
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
package/lib/magic/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 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;
|
package/lib/pageStack/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 禁止使用页面对象引用做相等判断,请使用route/fullPath字符串对比
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export interface PageWrap extends
|
|
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 */
|