utils-uniapp 1.1.6 → 1.1.8
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/cache/index.d.ts +128 -0
- package/lib/cache/index.js +1 -0
- package/lib/fs/index.js +1 -1
- package/lib/getLocation/index.js +1 -1
- package/lib/http/index.d.ts +181 -118
- package/lib/http/index.js +1 -1
- package/lib/index-1b48ae95.js +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -1
- package/lib/magic/index.d.ts +0 -29
- package/lib/magic/index.js +1 -1
- package/lib/pageStack/index.d.ts +42 -20
- package/lib/pageStack/index.js +1 -1
- package/package.json +1 -1
- package/lib/index-4975afce.js +0 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 存储介质模式类型
|
|
3
|
+
* - local:uni本地存储 / localStorage
|
|
4
|
+
* - session:会话存储,小程序/App自动降级为local
|
|
5
|
+
*/
|
|
6
|
+
type StorageMode = 'session' | 'local';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 底层存储适配器接口,抹平uni‑storage与sessionStorage API差异
|
|
10
|
+
*/
|
|
11
|
+
interface IStorageAdapter {
|
|
12
|
+
/**
|
|
13
|
+
* 设置存储键值
|
|
14
|
+
* @param key 存储原始key
|
|
15
|
+
* @param value 存储序列化对象
|
|
16
|
+
*/
|
|
17
|
+
set(key: string, value: any): void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 获取存储值
|
|
21
|
+
* @param key 存储原始key
|
|
22
|
+
* @returns 解析后的值,不存在返回null
|
|
23
|
+
*/
|
|
24
|
+
get(key: string): any | null;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 删除单个key
|
|
28
|
+
* @param key 存储原始key
|
|
29
|
+
*/
|
|
30
|
+
remove(key: string): void;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 获取存储介质下全部key列表
|
|
34
|
+
* @returns key字符串数组
|
|
35
|
+
*/
|
|
36
|
+
keys(): string[];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 清空整个存储介质(实例层不直接暴露给业务调用)
|
|
40
|
+
*/
|
|
41
|
+
clear(): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* StorageCache实例构造配置项
|
|
46
|
+
*/
|
|
47
|
+
interface StorageCacheOptions {
|
|
48
|
+
/** 存储介质模式,默认local */
|
|
49
|
+
mode?: StorageMode;
|
|
50
|
+
/** 缓存版本号,版本不匹配自动丢弃旧缓存,默认v1 */
|
|
51
|
+
version?: string | number;
|
|
52
|
+
/** 实例隔离前缀,内部自动追加下划线分隔,默认空字符串 */
|
|
53
|
+
prefix?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 多端缓存工具类
|
|
58
|
+
* 特性:过期控制、版本校验、实例key隔离前缀;适配uni‑app、H5‑sessionStorage
|
|
59
|
+
* 注意:
|
|
60
|
+
* 1. 业务传入key为业务key,内部自动拼接实例prefix
|
|
61
|
+
* 2. clear仅删除本实例前缀key,无prefix时不执行删除
|
|
62
|
+
* 3. removeByPrefix仅允许带实例隔离前缀的实例调用,全局实例禁止使用
|
|
63
|
+
*/
|
|
64
|
+
export declare class StorageCache {
|
|
65
|
+
/**
|
|
66
|
+
* 构造函数,创建 StorageCache 缓存实例
|
|
67
|
+
* @param options 实例配置对象,可选,默认空对象{}
|
|
68
|
+
*/
|
|
69
|
+
constructor(options?: StorageCacheOptions);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 设置缓存,支持过期
|
|
73
|
+
* @param key 业务缓存key
|
|
74
|
+
* @param data 缓存数据
|
|
75
|
+
* @param expire 过期时间,单位秒;<=0永不过期,默认3600
|
|
76
|
+
* @returns true成功,false异常失败
|
|
77
|
+
*/
|
|
78
|
+
set(key: string, data: any, expire?: number): boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 获取缓存,自动校验格式、版本、过期,失效自动删除
|
|
82
|
+
* @param key 业务缓存key
|
|
83
|
+
* @param defaultValue 兜底返回值
|
|
84
|
+
* @returns 缓存数据或defaultValue
|
|
85
|
+
*/
|
|
86
|
+
get<T = any>(key: string, defaultValue?: T | null): T | null;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 缓存续期,重置时间戳,沿用原有expire时长
|
|
90
|
+
* @param key 业务缓存key
|
|
91
|
+
* @returns true续期成功;false不存在/过期/版本不匹配/异常
|
|
92
|
+
*/
|
|
93
|
+
renew(key: string): boolean;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 删除单个业务缓存
|
|
97
|
+
* @param key 业务缓存key
|
|
98
|
+
* @returns boolean
|
|
99
|
+
*/
|
|
100
|
+
remove(key: string): boolean;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 清空本实例全部缓存;仅删除实例前缀下key,无prefix时不做任何删除
|
|
104
|
+
* @returns boolean
|
|
105
|
+
*/
|
|
106
|
+
clear(): boolean;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 按业务key前缀批量删除;无实例隔离前缀直接返回false,禁止调用
|
|
110
|
+
* @param prefix 业务key前缀,不需要携带实例内部前缀
|
|
111
|
+
* @returns boolean
|
|
112
|
+
*/
|
|
113
|
+
removeByPrefix(prefix: string): boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 全局默认local缓存实例,无实例隔离前缀,直接操作原始key
|
|
118
|
+
* @type {StorageCache}
|
|
119
|
+
*/
|
|
120
|
+
export declare const localCache: StorageCache;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 全局默认session缓存实例,无实例隔离前缀;小程序/App自动降级为local
|
|
124
|
+
* @type {StorageCache}
|
|
125
|
+
*/
|
|
126
|
+
export declare const sessionCache: StorageCache;
|
|
127
|
+
|
|
128
|
+
export default StorageCache;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var w=(i,t,r)=>{if(!t.has(i))throw TypeError("Cannot "+r)};var n=(i,t,r)=>(w(i,t,"read from private field"),r?r.call(i):t.get(i)),g=(i,t,r)=>{if(t.has(i))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(i):t.set(i,r)},y=(i,t,r,s)=>(w(i,t,"write to private field"),s?s.call(i,r):t.set(i,r),r);var l=(i,t,r)=>(w(i,t,"access private method"),r);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var o,h,c,d,p,u,m;const v=class v{constructor(){g(this,u);g(this,o,void 0);g(this,h,void 0);g(this,c,void 0);var a;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{mode:r="local",version:s="v1",prefix:e=""}=t;y(this,o,l(a=v,d,p).call(a,r)),y(this,h,String(s)),y(this,c,e?e+"_":""),Object.seal(this)}set(t,r){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:3600;try{let e=Number(s);Number.isFinite(e)||(e=0);const a=e>0?Math.round(e)*1e3:e,S=l(this,u,m).call(this,t);return n(this,o).set(S,{time:Date.now(),expire:a,version:n(this,h),data:r}),!0}catch(e){return console.error(`设置缓存[${t}]失败:`,e),!1}}get(t){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null;try{const s=l(this,u,m).call(this,t),e=n(this,o).get(s);return!e||typeof e!="object"||Array.isArray(e)||!("time"in e)||!("expire"in e)||!("version"in e)?(e&&n(this,o).remove(s),r):e.version!==n(this,h)?(n(this,o).remove(s),r):e.expire>0&&Date.now()-e.time>=e.expire?(n(this,o).remove(s),r):e.data}catch(s){return console.error(`获取缓存[${t}]失败:`,s),r}}renew(t){try{const r=l(this,u,m).call(this,t),s=n(this,o).get(r);if(!s||typeof s!="object"||Array.isArray(s)||!("time"in s)||!("expire"in s)||!("version"in s))return!1;if(s.version!==n(this,h))return n(this,o).remove(r),!1;if(s.expire>0){if(Date.now()-s.time>=s.expire)return n(this,o).remove(r),!1;s.time=Date.now(),n(this,o).set(r,s)}return!0}catch(r){return console.error(`续期缓存[${t}]失败:`,r),!1}}remove(t){try{const r=l(this,u,m).call(this,t);return n(this,o).remove(r),!0}catch(r){return console.error(`删除缓存[${t}]失败:`,r),!1}}clear(){try{return n(this,o).keys().forEach(r=>{n(this,c)&&r.startsWith(n(this,c))&&n(this,o).remove(r)}),!0}catch(t){return console.error("清空实例缓存失败:",t),!1}}removeByPrefix(t){if(!t)return!1;if(!n(this,c))return console.warn("StorageCache: 当前实例无隔离前缀,禁止调用removeByPrefix,避免误删"),!1;try{const r=l(this,u,m).call(this,t);return n(this,o).keys().forEach(e=>{e.startsWith(r)&&n(this,o).remove(e)}),!0}catch(r){return console.error(`按前缀删除缓存[${t}]失败:`,r),!1}}};o=new WeakMap,h=new WeakMap,c=new WeakMap,d=new WeakSet,p=function(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"local";const r=typeof window<"u"&&window.sessionStorage,s={set(e,a){uni.setStorageSync(e,a)},get(e){return uni.getStorageSync(e)},remove(e){uni.removeStorageSync(e)},keys(){try{return uni.getStorageInfoSync().keys||[]}catch(e){return console.error("uni getStorageInfoSync error",e),[]}},clear(){uni.clearStorageSync()}};return r&&t==="session"?{set(e,a){try{window.sessionStorage.setItem(e,JSON.stringify(a))}catch(S){console.error("sessionStorage set error",S)}},get(e){const a=window.sessionStorage.getItem(e);if(a===null)return null;try{return JSON.parse(a)}catch{return window.sessionStorage.removeItem(e),null}},remove(e){window.sessionStorage.removeItem(e)},keys(){return Object.keys(window.sessionStorage)},clear(){window.sessionStorage.clear()}}:s},u=new WeakSet,m=function(t){return n(this,c)+t},g(v,d);let f=v;const x=new f,I=new f({mode:"session"});exports.StorageCache=f;exports.default=f;exports.localCache=x;exports.sessionCache=I;
|
package/lib/fs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../index-1b48ae95.js"),I=require("../http/index.js");require("../object/index.js");const x=I.createDownloadFile(),u=uni.getFileSystemManager(),P=["ascii","base64","binary","hex","ucs2","ucs-2","utf16le","utf-16le","utf-8","utf8","latin1"];function A(){return`data:image/${arguments.length>0&&arguments[0]!==void 0?arguments[0]:"png"};base64,`}function y(r){let{filePath:n,encoding:t,sync:e,opts:i={}}=r;if(!P.includes(t))throw"编码不符合";if(e===!0)try{return u.readFileSync(n,t,i.position,i.length)}catch(a){return console.error(a),null}return new Promise(function(a,s){u.readFile({filePath:n,encoding:t,...i,success(o){a(o)},fail:s})})}y.sync=function(r){return y({...r,sync:!0})};function g(r){let{filePath:n,data:t,encoding:e,sync:i,opts:a}=r;if(e=e||"binary",!P.includes(e))throw"编码不符合";if(i===!0)try{return u.writeFileSync(n,t,e),{tempFilePath:n,unlink:()=>u.unlinkSync(n)}}catch(s){return console.error(s),null}return new Promise(function(s,o){u.writeFile({filePath:n,encoding:e,data:t,...a,success(f){if(f.errMsg!=="writeFile:ok")return o(new Error(f.errMsg));s({tempFilePath:n,unlink:()=>u.unlinkSync(n)})},fail:o})})}g.sync=function(r){return g({...r,sync:!0})};function M(r){let{arraybuffer:n,fileType:t,method:e,canvasId:i,width:a,height:s,ctx:o,sync:f}=r;if(typeof n!="object"||n.toString().slice(8,-1)!=="ArrayBuffer")return reject(new Error("ArrayBuffer must be a ArrayBuffer"));if(e=e||"canvas",t=t||"png",e==="fs"){const d=wx.env.USER_DATA_PATH+"/"+Date.now()+"."+t;return g({filePath:d,data:n,sync:f})}if(e==="canvas")return new Promise(function(d,l){if(!["canvas","fs"].includes(e))return l(new Error("method must be canvas | fs"));const F=`data:image/${t};base64,${uni.arrayBufferToBase64(n)}`;if(typeof i!="string")return l(new Error("canvasId must be a string [#id]"));const w=uni.createSelectorQuery();o&&w.in(o),w.select(i).fields({node:!0,size:!0}).exec(function(){var b=v._asyncToGenerator(function*(c){if(c=c[0],!c)return l(new Error("No canvas nodes were obtained"));a=a||c.width,s=s||c.height;const m=c.node;if(!m)return l(new Error("No canvas instances were obtained"));const p=m.getContext("2d"),h=m.createImage();yield new Promise(T=>{h.onload=T,h.src=F}).catch(l),p.clearRect(0,0,a,s),p.drawImage(h,0,0,a,s),uni.canvasToTempFilePath({canvas:m,width:a,height:s,fileType:t,success:d,fail:l})});return function(c){return b.apply(this,arguments)}}())})}const S=uni.canIUse("chooseMedia");function B(r){return r={count:1,...r},new Promise((n,t)=>{S?uni.chooseMedia({...r,mediaType:"image",sizeType:["original","compressed"],success(e){if(e.errMsg=="chooseMedia:ok"&&e.tempFiles[0]){const i=e.tempFiles.map(a=>a.tempFilePath);n(i)}else t(e.errMsg)},fail(e){t(e)}}):uni.chooseImage({count:r.count,success(e){n(e.tempFilePaths)},fail(e){t(e)}})})}function E(r){return new Promise((n,t)=>{x(r).then(e=>{uni.saveImageToPhotosAlbum({filePath:e.tempFilePath,success:i=>{uni.showToast({icon:"none",title:"保存成功"}),n(i)},fail:i=>{t(i)}})})})}exports.$fs=u;exports.chooseImg=B;exports.getArraybufferTempPath=M;exports.getImgBase64Prefix=A;exports.readFile=y;exports.saveImageToPhotosAlbum=E;exports.writeFile=g;
|
package/lib/getLocation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../index-1b48ae95.js"),g="/packageOther/pages/errorPage/errorPage",m={altitude:!0,type:"gcj02"},d={check:!1,errorPage:{path:g,message:"定位失败",type:2,enabled:!0}};function a(e,n){try{return e()}catch(o){console.warn(n||"执行失败",o);return}}function w(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;const n=k(e);return new Promise((o,r)=>{const{success:l,fail:i,...t}=n.locationParams||{},c={...m,...t,success:o,fail:u=>{N(u,n,r)}};uni.getLocation(c)})}function k(e){return typeof e=="boolean"?{check:e,locationParams:{},errorPage:{...d.errorPage},onLocationFail:null,onNetworkFail:null}:e&&typeof e=="object"&&!Array.isArray(e)?{check:e.check!==!1,locationParams:e.locationParams||{},errorPage:{...d.errorPage,...e.errorPage||{}},onLocationFail:e.onLocationFail||null,onNetworkFail:e.onNetworkFail||null}:{check:d.check,locationParams:{},errorPage:{...d.errorPage},onLocationFail:null,onNetworkFail:null}}function N(e,n,o){a(()=>{var r;return(r=n.onLocationFail)===null||r===void 0?void 0:r.call(n,e)},"onLocationFail 回调执行失败"),n.check&&F(n),o(e)}function F(e){uni.getNetworkType({success:n=>{n.networkType==="none"?f(e,new Error("无网络连接")):P(e.errorPage)},fail:n=>{console.warn("网络检测失败",n),f(e,n),P(e.errorPage)}})}function f(e,n){if(typeof e.onNetworkFail=="function")a(()=>e.onNetworkFail(n),"onNetworkFail 回调执行失败");else{const o=(n==null?void 0:n.errMsg)||(n==null?void 0:n.message)||"网络连接异常";a(()=>{uni.showToast({title:o,icon:"none"})},"显示提示失败")}}function P(e){if((e==null?void 0:e.enabled)===!1)return;const n=v();if(!n){console.warn("无法获取当前页面");return}if(L(n))return;const o=y(n,e);a(()=>{uni.redirectTo({url:o})},"跳转错误页面失败")}function v(){try{const e=getCurrentPages();return e&&e.length>0?e[e.length-1]:null}catch(e){return console.warn("获取当前页面失败",e),null}}function L(e){const n=(e==null?void 0:e.route)||"",o=g.replace("/","");return n===o||n.startsWith(o+"/")}function y(e,n){var o;const{path:r,message:l,type:i}=n||{},t={url:(e==null||(o=e.$page)===null||o===void 0?void 0:o.fullPath)||"",message:l||"定位失败",type:i||2};return`${r||g}${h.toQueryString(t)}`}function E(e){let{latitude:n,longitude:o,name:r="",address:l=""}=e;return new Promise((i,t)=>{const c=Number(n),u=Number(o);if(isNaN(c)||isNaN(u)){const s=new Error("经纬度参数无效");a(()=>{uni.showToast({icon:"none",title:"位置信息不完整"})}),t(s);return}uni.openLocation({latitude:c,longitude:u,name:r||"",address:l||"",success:i,fail:s=>{a(()=>{uni.showToast({icon:"none",title:s.errMsg||"打开地图失败"})}),t(s)}})})}exports.getLocation=w;exports.openLocation=E;
|
package/lib/http/index.d.ts
CHANGED
|
@@ -1,98 +1,84 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* 依赖说明:需要安装 @types/uni‑app,提供 UniApp.* 命名空间类型
|
|
2
3
|
* 请求Content‑Type常量
|
|
3
4
|
*/
|
|
4
5
|
export declare const CONTENT_TYPES: Readonly<{
|
|
5
|
-
/** json格式 */
|
|
6
|
+
/** json格式 application/json;charset=UTF-8 */
|
|
6
7
|
JSON: string;
|
|
7
|
-
/** 纯文本 */
|
|
8
|
+
/** 纯文本 text/plain;charset=UTF-8 */
|
|
8
9
|
TEXT: string;
|
|
9
|
-
/** url编码表单 */
|
|
10
|
+
/** url编码表单 application/x-www-form-urlencoded;charset=UTF-8 */
|
|
10
11
|
FORM_URLENCODED: string;
|
|
11
|
-
/** 文件上传表单 */
|
|
12
|
+
/** 文件上传表单 multipart/form‑data */
|
|
12
13
|
FORM_DATA: string;
|
|
13
14
|
}>;
|
|
14
15
|
|
|
15
16
|
/** uni请求任务对象,依赖uni‑app全局UniApp命名空间 */
|
|
16
17
|
type UniTask = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask;
|
|
17
18
|
|
|
18
|
-
/**
|
|
19
|
-
* 请求取消控制器(仿axios CancelToken)
|
|
20
|
-
*/
|
|
21
|
-
export declare const CancelToken: {
|
|
22
|
-
caches: Record<string, UniTask | undefined>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 注册任务
|
|
26
|
-
* @param token 唯一取消令牌
|
|
27
|
-
* @param task uni请求task对象
|
|
28
|
-
*/
|
|
29
|
-
add(token: string, task: UniTask): void;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 移除任务缓存
|
|
33
|
-
* @param token 唯一取消令牌
|
|
34
|
-
*/
|
|
35
|
-
delete(token: string): void;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @internal 内部私有,请勿外部调用
|
|
39
|
-
* @param token
|
|
40
|
-
*/
|
|
41
|
-
_cancel(token: string): void;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 取消全部请求
|
|
45
|
-
*/
|
|
46
|
-
cancelAll(): void;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 创建token与取消函数
|
|
50
|
-
* @returns { token:string, cancel:()=>void }
|
|
51
|
-
*/
|
|
52
|
-
source(): { token: string; cancel: () => void };
|
|
53
|
-
};
|
|
54
|
-
|
|
55
19
|
type UniRequestResult = UniApp.RequestSuccessCallbackResult;
|
|
56
20
|
type UniUploadResult = UniApp.UploadFileSuccessCallbackResult;
|
|
57
21
|
type UniDownloadResult = UniApp.DownloadFileSuccessCallbackResult;
|
|
58
22
|
type UniAnyResult = UniRequestResult | UniUploadResult | UniDownloadResult;
|
|
59
23
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
24
|
+
export type RequestFailPayload = {
|
|
25
|
+
type: 'fail';
|
|
26
|
+
res: UniApp.GeneralCallbackResult;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export interface CacheAdapter {
|
|
30
|
+
get(key: string): unknown;
|
|
31
|
+
set(key: string, value: unknown, expire: number): void;
|
|
32
|
+
}
|
|
67
33
|
|
|
68
34
|
/**
|
|
69
|
-
*
|
|
70
|
-
* @param title loading提示文本,默认:加载中...
|
|
35
|
+
* 外部传入缓存配置入参(仅调用方使用)
|
|
71
36
|
*/
|
|
72
|
-
export
|
|
37
|
+
export interface CacheConfigInput {
|
|
38
|
+
key?: string;
|
|
39
|
+
prefix?: string;
|
|
40
|
+
mode?: 'local' | 'session';
|
|
41
|
+
expire?: number;
|
|
42
|
+
localAdapter?: CacheAdapter | null;
|
|
43
|
+
sessionAdapter?: CacheAdapter | null;
|
|
44
|
+
}
|
|
73
45
|
|
|
74
46
|
/**
|
|
75
|
-
*
|
|
47
|
+
* normalizeOpts 之后内部运行时缓存配置对象
|
|
76
48
|
*/
|
|
77
|
-
export
|
|
49
|
+
export interface CacheConfig {
|
|
50
|
+
/** 缓存key;默认仅由url生成,**不包含请求参数**,同URL不同参数需手动指定key */
|
|
51
|
+
key: string;
|
|
52
|
+
/** 缓存key前缀 */
|
|
53
|
+
prefix: string;
|
|
54
|
+
/** 缓存模式 */
|
|
55
|
+
mode: 'local' | 'session';
|
|
56
|
+
/** 过期时间,单位秒 */
|
|
57
|
+
expire: number;
|
|
58
|
+
/**
|
|
59
|
+
* ⚠️ adapter 为内部运行时派生字段,**外部禁止传入、禁止访问**;
|
|
60
|
+
* 开启 isCache:true,必须传入 CacheConfigInput 对应模式的适配器,否则运行时抛出异常
|
|
61
|
+
*/
|
|
62
|
+
adapter: CacheAdapter | null;
|
|
63
|
+
[key: string]: unknown;
|
|
64
|
+
}
|
|
78
65
|
|
|
79
|
-
// -------------------- 拦截器类型定义(运行时标准化后) --------------------
|
|
80
66
|
/**
|
|
81
67
|
* 请求前置拦截器【标准化后】
|
|
82
68
|
* @param invokeArgs 组装完成即将传给uni的请求参数
|
|
83
69
|
* @param opts normalizeOpts合并后的完整配置
|
|
84
70
|
* @returns 处理后的请求参数
|
|
85
71
|
*/
|
|
86
|
-
type ReqInterceptor = (invokeArgs: Record<string,
|
|
72
|
+
export type ReqInterceptor = (invokeArgs: Record<string, unknown>, opts: RequestOptions) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
87
73
|
|
|
88
74
|
/**
|
|
89
75
|
* 响应拦截器【标准化后】
|
|
90
76
|
* @param res uni原始响应对象
|
|
91
77
|
* @param opts normalizeOpts合并后的完整配置
|
|
92
|
-
* @param reloadFn
|
|
78
|
+
* @param reloadFn 重发当前请求函数,可为null
|
|
93
79
|
* @returns 处理后业务数据
|
|
94
80
|
*/
|
|
95
|
-
type ResInterceptor = (res:
|
|
81
|
+
export type ResInterceptor = (res: unknown, opts: RequestOptions, reloadFn: (() => Promise<unknown>) | null) => Promise<unknown> | unknown;
|
|
96
82
|
|
|
97
83
|
/**
|
|
98
84
|
* 错误拦截器【标准化后】
|
|
@@ -100,66 +86,56 @@ type ResInterceptor = (res: UniAnyResult, opts: NormalizeOpts, reloadFn: () => P
|
|
|
100
86
|
* @param opts normalizeOpts合并后的完整配置
|
|
101
87
|
* @returns 返回非undefined代表错误已接管;返回undefined会继续抛出异常
|
|
102
88
|
*/
|
|
103
|
-
type ErrInterceptor = (err:
|
|
89
|
+
export type ErrInterceptor = (err: RequestFailPayload | Error, opts: RequestOptions) => Promise<unknown> | unknown;
|
|
104
90
|
|
|
105
91
|
/**
|
|
106
92
|
* 用户传入拦截器:支持单个函数 / 函数数组,交由 normalizeInterceptor + composeAsync合并
|
|
107
93
|
*/
|
|
108
|
-
type UserReqInterceptor = ReqInterceptor | ReqInterceptor[];
|
|
109
|
-
type UserResInterceptor = ResInterceptor | ResInterceptor[];
|
|
110
|
-
type UserErrInterceptor = ErrInterceptor | ErrInterceptor[];
|
|
111
|
-
|
|
112
|
-
// 导出拦截器类型别名,供业务直接 import type 使用
|
|
113
|
-
export type { ReqInterceptor, ResInterceptor, ErrInterceptor, UserReqInterceptor, UserResInterceptor, UserErrInterceptor };
|
|
94
|
+
export type UserReqInterceptor = ReqInterceptor | ReqInterceptor[];
|
|
95
|
+
export type UserResInterceptor = ResInterceptor | ResInterceptor[];
|
|
96
|
+
export type UserErrInterceptor = ErrInterceptor | ErrInterceptor[];
|
|
114
97
|
|
|
115
98
|
/**
|
|
116
99
|
* normalizeOpts标准化之后的请求额外配置对象【内部运行时】
|
|
117
100
|
*/
|
|
118
|
-
export interface
|
|
119
|
-
/**
|
|
101
|
+
export interface RequestOptions {
|
|
102
|
+
/** 是否使用表单编码 */
|
|
120
103
|
qs: boolean;
|
|
121
|
-
/**
|
|
104
|
+
/** 是否展示错误提示 */
|
|
122
105
|
showError: boolean;
|
|
123
|
-
/**
|
|
106
|
+
/** 是否开启缓存;开启时cacheConfig必须提供对应mode的适配器 */
|
|
124
107
|
isCache: boolean;
|
|
125
|
-
/**
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
cacheKey: string;
|
|
129
|
-
/** 缓存过期时间,单位秒(s), 默认1小时过期 */
|
|
130
|
-
cacheExpire: number;
|
|
131
|
-
/** loading提示文案 */
|
|
108
|
+
/** 缓存配置;adapter为内部运行时派生字段,外部请勿传入、请勿访问;开启isCache:true,必须传入对应模式的适配器,否则运行时抛出异常 */
|
|
109
|
+
cacheConfig: CacheConfig;
|
|
110
|
+
/** loading提示文字 */
|
|
132
111
|
loadingText: string;
|
|
133
112
|
/** 是否开启loading */
|
|
134
113
|
loading: boolean;
|
|
135
|
-
/**
|
|
114
|
+
/** 请求拦截器 */
|
|
136
115
|
reqInterceptor: ReqInterceptor;
|
|
137
|
-
/**
|
|
116
|
+
/** 响应拦截器 */
|
|
138
117
|
resInterceptor: ResInterceptor;
|
|
139
|
-
/**
|
|
118
|
+
/** 错误拦截器 */
|
|
140
119
|
errInterceptor: ErrInterceptor;
|
|
141
120
|
/** 允许扩展自定义字段 */
|
|
142
|
-
[key: string]:
|
|
121
|
+
[key: string]: unknown;
|
|
143
122
|
}
|
|
144
123
|
|
|
145
124
|
/**
|
|
146
125
|
* 业务侧传入配置【外部用户参数,支持拦截器数组】
|
|
147
|
-
* 经过内部 normalizeOpts 之后转换为
|
|
126
|
+
* 经过内部 normalizeOpts 之后转换为 RequestOptions
|
|
127
|
+
* @description isCache 设置为 true 时,cacheConfig 需要传入对应 mode 的适配器 localAdapter / sessionAdapter,否则运行时抛出异常
|
|
148
128
|
*/
|
|
149
129
|
export interface UserRequestOpts {
|
|
150
|
-
/**
|
|
130
|
+
/** 是否使用表单编码 */
|
|
151
131
|
qs?: boolean;
|
|
152
|
-
/**
|
|
132
|
+
/** 是否展示错误提示 */
|
|
153
133
|
showError?: boolean;
|
|
154
|
-
/**
|
|
134
|
+
/** 是否开启缓存;开启时cacheConfig必须提供对应mode的适配器(localAdapter/sessionAdapter) */
|
|
155
135
|
isCache?: boolean;
|
|
156
|
-
/**
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
cacheKey?: string;
|
|
160
|
-
/** 缓存过期时间,单位秒(s), 默认1小时过期 */
|
|
161
|
-
cacheExpire?: number;
|
|
162
|
-
/** loading提示文案 */
|
|
136
|
+
/** 缓存配置,用户传入部分字段即可;isCache=true必须传入对应mode适配器 */
|
|
137
|
+
cacheConfig?: Partial<CacheConfigInput>;
|
|
138
|
+
/** loading提示文字 */
|
|
163
139
|
loadingText?: string;
|
|
164
140
|
/** 是否开启loading */
|
|
165
141
|
loading?: boolean;
|
|
@@ -170,68 +146,155 @@ export interface UserRequestOpts {
|
|
|
170
146
|
/** 错误拦截器,支持单个函数或函数数组 */
|
|
171
147
|
errInterceptor?: UserErrInterceptor;
|
|
172
148
|
/** 允许扩展自定义字段 */
|
|
173
|
-
[key: string]:
|
|
149
|
+
[key: string]: unknown;
|
|
174
150
|
}
|
|
175
151
|
|
|
152
|
+
/**
|
|
153
|
+
* 请求取消控制器(仿axios CancelToken)
|
|
154
|
+
* 注意:当前实现token由请求内部source生成,**不支持外部传入自定义cancelToken**
|
|
155
|
+
*/
|
|
156
|
+
export declare const CancelToken: {
|
|
157
|
+
caches: Record<string, UniTask>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 注册请求任务
|
|
161
|
+
* @param token 取消令牌
|
|
162
|
+
* @param task uni请求task对象
|
|
163
|
+
*/
|
|
164
|
+
add(token: string, task: UniTask): void;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 移除任务缓存
|
|
168
|
+
* @param token 取消令牌
|
|
169
|
+
*/
|
|
170
|
+
delete(token: string): void;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 根据token终止请求
|
|
174
|
+
* @param token 取消令牌
|
|
175
|
+
*/
|
|
176
|
+
_cancel(token: string): void;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 取消全部缓存中的请求
|
|
180
|
+
*/
|
|
181
|
+
cancelAll(): void;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 创建token与取消函数
|
|
185
|
+
* @returns {{token:string, cancel:()=>void}}
|
|
186
|
+
*/
|
|
187
|
+
source(): { token: string; cancel: () => void };
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 包装uni异步API为Promise
|
|
193
|
+
* @param type uni接口名称 request | uploadFile | downloadFile
|
|
194
|
+
* @param opts 请求参数,可以传入 cancelToken 用于请求取消
|
|
195
|
+
* @description 泛型仅为类型断言,运行时不会做类型转换
|
|
196
|
+
* @returns uni接口回调结果Promise
|
|
197
|
+
*/
|
|
198
|
+
export declare function promisifyRequest<T = UniAnyResult>(type: 'request' | 'uploadFile' | 'downloadFile', opts: Record<string, unknown>): Promise<T>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 底层展示loading
|
|
202
|
+
* @param {string} title loading提示文字
|
|
203
|
+
*/
|
|
204
|
+
export declare function showLoading(title: string): void;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 底层隐藏loading
|
|
208
|
+
*/
|
|
209
|
+
export declare function hideLoading(): void;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 开启loading计数,计数>0时展示loading
|
|
213
|
+
* @param [title='加载中...'] loading提示文案
|
|
214
|
+
*/
|
|
215
|
+
export declare function startLoading(title?: string): void;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 关闭loading计数,计数归0则隐藏loading
|
|
219
|
+
*/
|
|
220
|
+
export declare function endLoading(): void;
|
|
221
|
+
|
|
176
222
|
/**
|
|
177
223
|
* createRequest返回的请求实例对象
|
|
178
224
|
*/
|
|
179
|
-
interface RequestInstance {
|
|
225
|
+
export interface RequestInstance {
|
|
180
226
|
/**
|
|
181
|
-
* 基础请求方法
|
|
182
227
|
* @param url 请求地址
|
|
183
|
-
* @param method
|
|
184
|
-
* @param params
|
|
185
|
-
* @param config
|
|
186
|
-
* @param options
|
|
228
|
+
* @param method get/post等http方法
|
|
229
|
+
* @param params 请求参数
|
|
230
|
+
* @param [config] 当前请求配置,覆盖defaultConfig
|
|
231
|
+
* @param [options] 当前请求扩展选项,覆盖defaultOpts
|
|
232
|
+
* @returns {Promise<unknown>}
|
|
187
233
|
*/
|
|
188
|
-
(url: string, method: string, params?:
|
|
234
|
+
(url: string, method: string, params?: unknown, config?: Record<string, unknown>, options?: UserRequestOpts): Promise<unknown>;
|
|
189
235
|
|
|
190
236
|
/**
|
|
191
237
|
* get快捷方法
|
|
192
238
|
* @param url 请求地址
|
|
193
|
-
* @param params
|
|
194
|
-
* @param config
|
|
195
|
-
* @param options
|
|
239
|
+
* @param params 请求参数
|
|
240
|
+
* @param [config] 当前请求配置
|
|
241
|
+
* @param [options] 当前请求扩展选项
|
|
196
242
|
*/
|
|
197
|
-
get(url: string, params?:
|
|
243
|
+
get(url: string, params?: unknown, config?: Record<string, unknown>, options?: UserRequestOpts): Promise<unknown>;
|
|
198
244
|
|
|
199
245
|
/**
|
|
200
246
|
* post快捷方法
|
|
201
247
|
* @param url 请求地址
|
|
202
|
-
* @param params
|
|
203
|
-
* @param config
|
|
204
|
-
* @param options
|
|
248
|
+
* @param params 请求参数
|
|
249
|
+
* @param [config] 当前请求配置
|
|
250
|
+
* @param [options] 当前请求扩展选项
|
|
205
251
|
*/
|
|
206
|
-
post(url: string, params?:
|
|
252
|
+
post(url: string, params?: unknown, config?: Record<string, unknown>, options?: UserRequestOpts): Promise<unknown>;
|
|
207
253
|
}
|
|
208
254
|
|
|
209
255
|
/**
|
|
210
256
|
* 创建常规http请求实例(get/post)
|
|
211
|
-
* @param defaultConfig
|
|
212
|
-
* @param defaultOpts
|
|
213
|
-
* @returns RequestInstance
|
|
257
|
+
* @param defaultConfig 实例默认配置(baseURL、headers等)
|
|
258
|
+
* @param defaultOpts 实例默认扩展选项(loading、缓存、拦截器)
|
|
259
|
+
* @returns {RequestInstance}
|
|
214
260
|
*/
|
|
215
|
-
export declare function createRequest(defaultConfig: Record<string,
|
|
261
|
+
export declare function createRequest(defaultConfig: Record<string, unknown>, defaultOpts?: UserRequestOpts): RequestInstance;
|
|
216
262
|
|
|
217
263
|
/**
|
|
218
264
|
* 创建上传文件实例
|
|
219
|
-
* @param defaultConfig
|
|
220
|
-
* @param defaultOpts
|
|
265
|
+
* @param defaultConfig 实例默认配置(baseURL、headers等)
|
|
266
|
+
* @param defaultOpts 实例默认扩展选项
|
|
221
267
|
* @returns 上传函数
|
|
222
268
|
*/
|
|
223
269
|
export declare function createUploadFile(
|
|
224
|
-
defaultConfig: Record<string,
|
|
270
|
+
defaultConfig: Record<string, unknown>,
|
|
225
271
|
defaultOpts?: UserRequestOpts
|
|
226
|
-
): (url: string, params: { filePath: string; keyName?: string; [key: string]:
|
|
272
|
+
): (url: string, params: { filePath: string; keyName?: string; [key: string]: unknown }, config?: Record<string, unknown>, options?: UserRequestOpts) => Promise<unknown>;
|
|
227
273
|
|
|
228
274
|
/**
|
|
229
275
|
* 创建下载文件实例
|
|
230
|
-
* @param defaultConfig
|
|
231
|
-
* @param defaultOpts
|
|
276
|
+
* @param defaultConfig 实例默认配置(baseURL、headers等)
|
|
277
|
+
* @param defaultOpts 实例默认扩展选项
|
|
232
278
|
* @returns 下载函数
|
|
233
279
|
*/
|
|
234
280
|
export declare function createDownloadFile(
|
|
235
|
-
defaultConfig: Record<string,
|
|
281
|
+
defaultConfig: Record<string, unknown>,
|
|
236
282
|
defaultOpts?: UserRequestOpts
|
|
237
|
-
): (url: string, params?: Record<string,
|
|
283
|
+
): (url: string, params?: Record<string, unknown>, config?: Record<string, unknown>, options?: UserRequestOpts) => Promise<unknown>;
|
|
284
|
+
|
|
285
|
+
// 导出全部业务可用类型
|
|
286
|
+
export type {
|
|
287
|
+
ReqInterceptor,
|
|
288
|
+
ResInterceptor,
|
|
289
|
+
ErrInterceptor,
|
|
290
|
+
UserReqInterceptor,
|
|
291
|
+
UserResInterceptor,
|
|
292
|
+
UserErrInterceptor,
|
|
293
|
+
CacheAdapter,
|
|
294
|
+
CacheConfigInput,
|
|
295
|
+
CacheConfig,
|
|
296
|
+
RequestFailPayload,
|
|
297
|
+
RequestOptions,
|
|
298
|
+
UserRequestOpts,
|
|
299
|
+
RequestInstance
|
|
300
|
+
};
|
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 w=require("../index-1b48ae95.js"),P=require("../object/index.js"),k=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"}),y={caches:Object.create(null),add(e,t){this.caches[e]=t},delete(e){Reflect.deleteProperty(this.caches,e)},_cancel(e){const t=this.caches[e];typeof(t==null?void 0:t.abort)=="function"&&t.abort()},cancelAll(){Object.values(this.caches).forEach(e=>{typeof(e==null?void 0:e.abort)=="function"&&e.abort()}),this.caches=Object.create(null)},source(){const e=`${Date.now()}-${w.getRandomStr(16)}`;return{token:e,cancel:()=>this._cancel(e)}}};function O(e,t){return new Promise((r,n)=>{const i=uni[e]({...t,success(o){if(o.statusCode>=200&&o.statusCode<300)return r(o);n({type:"fail",res:o})},fail(o){n({type:"fail",res:o})},complete(){t.cancelToken&&y.delete(t.cancelToken)}});t.cancelToken&&y.add(t.cancelToken,i)})}let R=0,x=!1;function U(e){x||(x=!0,uni.showLoading({title:e,mask:!0}))}function D(){x&&(x=!1,uni.hideLoading())}function L(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"加载中...";R++,R===1&&U(e)}function N(){R>0&&R--,R===0&&D()}function j(e,t){return function(r,n,i,o){return e(r,t,n,i,o)}}function A(e){return typeof e=="function"?e:()=>e||{}}function F(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n=A(t.headers)(),i=A(r.headers)(),o={...t,...r,headers:{...n,...i}},{headers:s,...u}=o;return{urlRes:e.startsWith("http")?e:o.baseURL?o.baseURL+e:e,headers:s,configRes:u}}function I(e){return typeof e=="function"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="function"):[]}function q(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n={qs:!0,showError:!0,isCache:!1,cacheConfig:{},loadingText:e.loadingText,loading:!0,reqInterceptor:a=>a,resInterceptor:a=>a,errInterceptor:()=>{},...t,...r},i={...t.cacheConfig,...r.cacheConfig},{localAdapter:o,sessionAdapter:s,...u}=i,c={key:"",prefix:"api",mode:"local",expire:60*60,...u};if(!c.key){const a=(c.prefix||"api").replace(/:$/,"");c.key=`${a}:${e.url}`}if(c.adapter=c.mode==="session"?s:o,Object.defineProperty(c,"adapter",{writable:!1,configurable:!1}),n.cacheConfig=c,n.isCache){const a=c.adapter;if(!(a&&typeof a.get=="function"&&typeof a.set=="function"))throw new Error("开启缓存(isCache=true)时,请在cacheConfig传入对应mode的适配器,适配器必须实现 get(key)、set(key,value,expire) 方法")}return["reqInterceptor","resInterceptor","errInterceptor"].forEach(a=>{const l=[...I(t[a]),...I(r[a])];n[a]=l.length?w.composeAsync(...l):g=>g}),n}function E(e,t){const r=Array.from(t);return()=>e(...P.cloneDeepWithDescriptors(r))}function _(e,t,r,n,i){return v.apply(this,arguments)}function v(){return v=w._asyncToGenerator(function*(e,t,r,n,i){let o;n.loading&&(L(n.loadingText),o=()=>{N(),o=null});try{var s;const c=yield n.reqInterceptor(r,n),a=yield e(t,c);return(s=o)===null||s===void 0||s(),yield n.resInterceptor(a,n,i)}catch(c){var u;(u=o)===null||u===void 0||u();const a=yield n.errInterceptor(c,n);return a!==void 0?a:Promise.reject(c)}}),v.apply(this,arguments)}function S(e,t){function r(n,i,o,s,u){const c=y.source(),a=E(r,arguments),l=q({url:n,loadingText:"加载中..."},t,u),{urlRes:g,headers:C,configRes:h}=F(n,e,s),f=l.isCache,d=l.cacheConfig;if(f){const T=d.adapter.get(d.key);if(T)return Promise.resolve(T)}const m=i.toUpperCase()==="GET"?k.JSON:l.qs?k.FORM_URLENCODED:k.JSON,b={cancelToken:c.token,method:i,url:g,data:o,header:{"Content-Type":m,...C},...h};return _(O,"request",b,l,a).then(T=>(f&&d.adapter.set(d.key,T,d.expire),T))}return r.get=j(r,"get"),r.post=j(r,"post"),r}function $(e,t){return function r(n,i,o,s){const u=y.source(),c=E(r,arguments),a=q({loadingText:"上传中..."},t,s),{urlRes:l,headers:g,configRes:C}=F(n,e,o),{keyName:h="file",filePath:f,...d}={keyName:"file",...i};if(!f||!f.startsWith("http://tmp")&&!f.startsWith("wxfile://tmp"))return Promise.resolve({data:f});const p={cancelToken:u.token,url:l,filePath:f,name:h,formData:d,header:{...g},...C};return _(O,"uploadFile",p,a,c)}}function z(e,t){return function r(n,i,o,s){const u=y.source(),c=E(r,arguments),a=q({loadingText:"下载中..."},t,s),{urlRes:l,headers:g,configRes:C}=F(n,e,o);let h=l;if(i&&typeof i=="object"){const d=Object.entries(i).filter(p=>{let[,m]=p;return m!=null&&m!==""}).map(p=>{let[m,b]=p;return`${encodeURIComponent(m)}=${encodeURIComponent(b)}`}).join("&");d&&(h+=(h.includes("?")?"&":"?")+d)}const f={cancelToken:u.token,url:h,header:{...g},...C};return _(O,"downloadFile",f,a,c)}}exports.CONTENT_TYPES=k;exports.CancelToken=y;exports.createDownloadFile=z;exports.createRequest=S;exports.createUploadFile=$;exports.endLoading=N;exports.hideLoading=D;exports.promisifyRequest=O;exports.showLoading=U;exports.startLoading=L;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function S(e,o,u,n,r,t,a){try{var i=e[t](a),s=i.value}catch(f){return void u(f)}i.done?o(s):Promise.resolve(s).then(n,r)}function h(e){return function(){var o=this,u=arguments;return new Promise(function(n,r){var t=e.apply(o,u);function a(s){S(t,n,r,a,i,"next",s)}function i(s){S(t,n,r,a,i,"throw",s)}a(void 0)})}}function C(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];if(o.some(n=>typeof n!="function"))throw new TypeError("compose 参数必须是函数");return o.length===0?function(){for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];return r.length===1?r[0]:r}:o.reduce((n,r)=>function(){for(var t=this,a=arguments.length,i=new Array(a),s=0;s<a;s++)i[s]=arguments[s];return r.call(this,function(){for(var f=arguments.length,m=new Array(f),c=0;c<f;c++)m[c]=arguments[c];return n.apply(t,m.concat(i))},...i)})}function I(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];if(o.some(n=>typeof n!="function"))throw new TypeError("composeAsync 参数必须是函数");return o.length===0?h(function*(){for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];return r.length===1?r[0]:r}):o.reduce((n,r)=>h(function*(){for(var t=this,a=arguments.length,i=new Array(a),s=0;s<a;s++)i[s]=arguments[s];return r.call(this,h(function*(){for(var f=arguments.length,m=new Array(f),c=0;c<f;c++)m[c]=arguments[c];return n.apply(t,m.concat(i))}),...i)}))}function R(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];if(o.some(n=>typeof n!="function"))throw new TypeError("pipe 参数必须是函数");return o.length===0?function(){for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];return r.length===1?r[0]:r}:o.reduce((n,r)=>function(){for(var t=this,a=arguments.length,i=new Array(a),s=0;s<a;s++)i[s]=arguments[s];return n.call(this,function(){for(var f=arguments.length,m=new Array(f),c=0;c<f;c++)m[c]=arguments[c];return r.apply(t,m.concat(i))},...i)})}function y(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];if(o.some(n=>typeof n!="function"))throw new TypeError("pipeAsync 参数必须是函数");return o.length===0?h(function*(){for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];return r.length===1?r[0]:r}):o.reduce((n,r)=>h(function*(){for(var t=this,a=arguments.length,i=new Array(a),s=0;s<a;s++)i[s]=arguments[s];return n.call(this,h(function*(){for(var f=arguments.length,m=new Array(f),c=0;c<f;c++)m[c]=arguments[c];return r.apply(t,m.concat(i))}),...i)}))}function x(e,o){let u=null;n.stop=()=>u&&clearTimeout(u);function n(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];n.stop(),u=setTimeout(()=>{e.apply(this,t)},o)}return n}function T(e,o){let u=null,n=[];r.stop=()=>{if(u){var t;(t=n.shift())===null||t===void 0||t("cancel"),clearTimeout(u)}};function r(){for(var t=arguments.length,a=new Array(t),i=0;i<t;i++)a[i]=arguments[i];return new Promise((s,f)=>{r.stop(),n.push(f),u=setTimeout(()=>{s(e.apply(this,a))},o)})}return r}function U(e){let o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,n;return u?function(){if(!n){n=!0;for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];typeof e=="function"&&e.apply(this,t),setTimeout(()=>{n=!1},o)}}:function(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];n||(n=!0,setTimeout(()=>{n=!1,typeof e=="function"&&e.apply(this,t)},o))}}function Q(e){return encodeURIComponent(JSON.stringify(e||{}))}function b(e){return JSON.parse(decodeURIComponent(e||"{}"))}function v(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{silent:u=!1,decodePlus:n=!0,strict:r=!1}=o,t={};if(typeof e!="string")return t;function a(c,g){let l=c;n&&(l=l.replace(/\+/g," "));try{return decodeURIComponent(l)}catch(d){return u||console.warn(`Failed to decode ${g?"key":"value"}: ${l}`,d),r?null:(g&&(l=l.replace(/%[0-9a-f]{2}/gi,"")),l)}}const i=e.split("#")[0],s=i.indexOf("?"),f=s>=0?i.slice(s+1):i;if(!f)return t;const m=f.split("&");for(let c=0;c<m.length;c++){const g=m[c];if(!g)continue;const l=g.indexOf("=");let d,P;l===-1?(d=g,P=""):(d=g.slice(0,l),P=g.slice(l+1));const p=a(d,!0);if(p===null)continue;const w=a(P,!1);if(w===null||!p)continue;const A=t[p];A===void 0?t[p]=w:Array.isArray(A)?A.push(w):t[p]=[A,w]}return t}function M(e){return typeof window>"u"?{}:v(window.location.search,e)}function O(e){if(typeof window>"u")return{};const o=window.location.hash,u=o.indexOf("?");if(u===-1)return{};const n=o.substring(u);return v(n,e)}function E(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,o=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),e.toString()].join(o)}function j(e){return e.replace(/([^-])([^-]*)/g,function(o,u,n){return u.toLocaleUpperCase()+n.toLocaleLowerCase()}).replace(/-/g,"")}function F(e,o){e=e.split("."),o=o.split(".");const u=Math.max(e.length,o.length);for(;e.length<u;)e.push("0");for(;o.length<u;)o.push("0");for(let n=0;n<u;n++){const r=parseInt(e[n]),t=parseInt(o[n]);if(r>t)return 1;if(r<t)return-1}return 0}function $(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function q(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,o=arguments.length>1?arguments[1]:void 0;e=e||32,o||(o="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");const u=o.length;let n="";for(let r=0;r<e;r++)n+=o.charAt(Math.floor(Math.random()*u));return n}function L(e){let o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;if(!e||typeof e!="object")return"";const u=[];Object.keys(e).forEach(r=>{const t=e[r];if(t==null)return;const a=encodeURIComponent(r);if(Array.isArray(t)){t.forEach(s=>{const f=encodeURIComponent(s);u.push(`${a}=${f}`)});return}let i=t;typeof i=="object"&&i!==null&&(i=JSON.stringify(i)),u.push(`${a}=${encodeURIComponent(i)}`)});const n=u.join("&");return o&&n?`?${n}`:n}function V(e){const o=e.scene;return o&&(e={fromCode:!0,...e,...v(o)}),e}exports._asyncToGenerator=h;exports.compareVersion=F;exports.compose=C;exports.composeAsync=I;exports.debounce=x;exports.debouncePromise=T;exports.decodeURIParams=b;exports.encodeURIParams=Q;exports.getOnLoadParams=V;exports.getPascalCase=j;exports.getQueryParams=v;exports.getQueryParamsFromHash=O;exports.getQueryParamsFromSearch=M;exports.getRandom=E;exports.getRandomStr=q;exports.pipe=R;exports.pipeAsync=y;exports.randomColor=$;exports.throttle=U;exports.toQueryString=L;
|
package/lib/index.d.ts
CHANGED
package/lib/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 d=require("./aliPay/index.js"),r=require("./array/index.js"),n=require("./cache/index.js"),g=require("./date/index.js"),o=require("./fs/index.js"),c=require("./getLocation/index.js"),a=require("./http/index.js"),e=require("./index-1b48ae95.js"),s=require("./object/index.js"),t=require("./pageStack/index.js"),i=require("./validate/index.js"),l=require("./index-9456b3d9.js"),P=require("./lodash");Object.assign(exports,P);exports.alipaySubmit=d.alipaySubmit;exports.exchangeArrP=r.exchangeArrP;exports.filterTree=r.filterTree;exports.findTreeItem=r.findTreeItem;exports.flatWithKey=r.flatWithKey;exports.getTreePath=r.getTreePath;exports.groupBy=r.groupBy;exports.reverseForEach=r.reverseForEach;exports.treeItemSetParent=r.treeItemSetParent;exports.StorageCache=n.StorageCache;exports.localCache=n.localCache;exports.sessionCache=n.sessionCache;exports.dateFormat=g.dateFormat;exports.getDate=g.getDate;exports.$fs=o.$fs;exports.chooseImg=o.chooseImg;exports.getArraybufferTempPath=o.getArraybufferTempPath;exports.getImgBase64Prefix=o.getImgBase64Prefix;exports.readFile=o.readFile;exports.saveImageToPhotosAlbum=o.saveImageToPhotosAlbum;exports.writeFile=o.writeFile;exports.getLocation=c.getLocation;exports.openLocation=c.openLocation;exports.CONTENT_TYPES=a.CONTENT_TYPES;exports.CancelToken=a.CancelToken;exports.createDownloadFile=a.createDownloadFile;exports.createRequest=a.createRequest;exports.createUploadFile=a.createUploadFile;exports.endLoading=a.endLoading;exports.hideLoading=a.hideLoading;exports.promisifyRequest=a.promisifyRequest;exports.showLoading=a.showLoading;exports.startLoading=a.startLoading;exports.compareVersion=e.compareVersion;exports.compose=e.compose;exports.composeAsync=e.composeAsync;exports.debounce=e.debounce;exports.debouncePromise=e.debouncePromise;exports.decodeURIParams=e.decodeURIParams;exports.encodeURIParams=e.encodeURIParams;exports.getOnLoadParams=e.getOnLoadParams;exports.getPascalCase=e.getPascalCase;exports.getQueryParams=e.getQueryParams;exports.getQueryParamsFromHash=e.getQueryParamsFromHash;exports.getQueryParamsFromSearch=e.getQueryParamsFromSearch;exports.getRandom=e.getRandom;exports.getRandomStr=e.getRandomStr;exports.pipe=e.pipe;exports.pipeAsync=e.pipeAsync;exports.randomColor=e.randomColor;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;exports.cloneDeepWithDescriptors=s.cloneDeepWithDescriptors;exports.getRawType=s.getRawType;exports.hasOwnProperty=s.hasOwnProperty;exports.backToRoute=t.backToRoute;exports.findPageByFullPath=t.findPageByFullPath;exports.findPageByRoute=t.findPageByRoute;exports.getCurrentPage=t.getCurrentPage;exports.getCurrentPageOptions=t.getCurrentPageOptions;exports.getCurrentRoute=t.getCurrentRoute;exports.getPageStack=t.getPageStack;exports.getPageVm=t.getPageVm;exports.getPrevPage=t.getPrevPage;exports.getPrevRoute=t.getPrevRoute;exports.isExternal=i.isExternal;exports.validDate=i.validDate;exports.validIDCard=i.validIDCard;exports.validPhone=i.validPhone;exports.validPostalCode=i.validPostalCode;exports.validURL=i.validURL;exports.wx=l.index;
|
package/lib/magic/index.d.ts
CHANGED
|
@@ -180,32 +180,3 @@ export declare function toQueryString(
|
|
|
180
180
|
*/
|
|
181
181
|
export function getOnLoadParams<T extends Record<string, any>>(e: T & { scene?: string }): T & { fromCode?: boolean } & Record<string, any>;
|
|
182
182
|
|
|
183
|
-
/**
|
|
184
|
-
* 设置uni‑app本地缓存,支持过期时间控制
|
|
185
|
-
* @param key 缓存存储键名
|
|
186
|
-
* @param data 需要存储的数据,可以为任意可序列化类型
|
|
187
|
-
* @param expire 过期时长,单位:秒;<=0代表永不过期;非法数字自动降级永不过期;默认 3600(1小时)
|
|
188
|
-
* @returns true写入成功;false写入发生异常失败
|
|
189
|
-
*/
|
|
190
|
-
export function setCache(key: string, data: any, expire?: number): boolean;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* 读取本地缓存;自动判断过期,过期自动删除并返回null
|
|
194
|
-
* @param key 缓存存储键名
|
|
195
|
-
* @returns 缓存有效返回存储data;缓存不存在/结构异常/已过期返回null
|
|
196
|
-
*/
|
|
197
|
-
export function getCache(key: string): any | null;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 缓存续期,重置过期计时;永不过期缓存不会写入存储,直接返回true
|
|
201
|
-
* @param key 缓存存储键名
|
|
202
|
-
* @returns true:缓存有效;false:缓存不存在/结构损坏/已经过期
|
|
203
|
-
*/
|
|
204
|
-
export function renewCache(key: string): boolean;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* 删除指定key本地缓存
|
|
208
|
-
* @param key 缓存存储键名
|
|
209
|
-
* @returns true删除成功;false删除异常失败
|
|
210
|
-
*/
|
|
211
|
-
export function removeCache(key: string): boolean;
|
package/lib/magic/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index-1b48ae95.js");exports.compareVersion=e.compareVersion;exports.compose=e.compose;exports.composeAsync=e.composeAsync;exports.debounce=e.debounce;exports.debouncePromise=e.debouncePromise;exports.decodeURIParams=e.decodeURIParams;exports.encodeURIParams=e.encodeURIParams;exports.getOnLoadParams=e.getOnLoadParams;exports.getPascalCase=e.getPascalCase;exports.getQueryParams=e.getQueryParams;exports.getQueryParamsFromHash=e.getQueryParamsFromHash;exports.getQueryParamsFromSearch=e.getQueryParamsFromSearch;exports.getRandom=e.getRandom;exports.getRandomStr=e.getRandomStr;exports.pipe=e.pipe;exports.pipeAsync=e.pipeAsync;exports.randomColor=e.randomColor;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;
|
package/lib/pageStack/index.d.ts
CHANGED
|
@@ -1,57 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 注意:fullPath / navUrl 基于页面onLoad的options,页面运行时动态修改url参数不会自动刷新,需要重新调用工具函数获取
|
|
3
|
+
* 禁止使用页面对象引用做相等判断,请使用route/fullPath字符串对比
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface PageWrap extends UniApp.PageInstance {
|
|
7
|
+
/** 不带开头斜杠 pages/xxx/xxx?a=1,用于路由匹配对比;基于onLoad options */
|
|
8
|
+
fullPath: string | null;
|
|
9
|
+
/** 带开头斜杠 /pages/xxx/xxx?a=1,可直接用于uni.navigateTo url;基于onLoad options */
|
|
10
|
+
navUrl: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
/**
|
|
2
14
|
* 获取当前页面实例
|
|
3
|
-
* @returns
|
|
15
|
+
* @returns 当前页面对象,栈空/异常返回 null
|
|
4
16
|
*/
|
|
5
|
-
export declare function getCurrentPage():
|
|
17
|
+
export declare function getCurrentPage(): PageWrap | null;
|
|
6
18
|
|
|
7
19
|
/**
|
|
8
20
|
* 获取上一页页面实例
|
|
9
21
|
* @returns 上一页实例,无则 null
|
|
10
22
|
*/
|
|
11
|
-
export declare function getPrevPage():
|
|
23
|
+
export declare function getPrevPage(): PageWrap | null;
|
|
12
24
|
|
|
13
25
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @returns
|
|
26
|
+
* 获取完整页面栈副本(每项均为包装对象,带fullPath、navUrl;避免外部修改原生页面栈数组)
|
|
27
|
+
* @returns PageWrap数组
|
|
16
28
|
*/
|
|
17
|
-
export declare function getPageStack():
|
|
29
|
+
export declare function getPageStack(): PageWrap[];
|
|
18
30
|
|
|
19
31
|
/**
|
|
20
|
-
* 获取当前页面路由(不带 query
|
|
21
|
-
* @returns
|
|
32
|
+
* 获取当前页面路由(不带 query 参数,返回格式 pages/xxx/xxx)
|
|
33
|
+
* @returns 路由字符串或null
|
|
22
34
|
*/
|
|
23
35
|
export declare function getCurrentRoute(): string | null;
|
|
24
36
|
|
|
25
37
|
/**
|
|
26
38
|
* 获取当前页面 onLoad options 参数
|
|
27
|
-
* @returns
|
|
39
|
+
* @returns options 对象或null
|
|
28
40
|
*/
|
|
29
|
-
export declare function getCurrentPageOptions(): Record<string, string | undefined> | null;
|
|
41
|
+
export declare function getCurrentPageOptions(): Record<string, string | number | boolean | undefined> | null;
|
|
30
42
|
|
|
31
43
|
/**
|
|
32
44
|
* 获取上一页路由
|
|
33
|
-
* @returns
|
|
45
|
+
* @returns 路由字符串或null
|
|
34
46
|
*/
|
|
35
47
|
export declare function getPrevRoute(): string | null;
|
|
36
48
|
|
|
37
49
|
/**
|
|
38
50
|
* 根据路由在页面栈中查找页面对象
|
|
39
51
|
* @param route 页面路由,支持带/不带开头 /
|
|
40
|
-
* @returns
|
|
52
|
+
* @returns PageWrap|null
|
|
53
|
+
*/
|
|
54
|
+
export declare function findPageByRoute(route: string): PageWrap | null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 根据fullPath查找页面栈
|
|
58
|
+
* @param fullPath 不带前置斜杠 pages/xxx/xxx?a=1
|
|
59
|
+
* @returns PageWrap|null
|
|
41
60
|
*/
|
|
42
|
-
export declare function
|
|
61
|
+
export declare function findPageByFullPath(fullPath: string): PageWrap | null;
|
|
43
62
|
|
|
44
63
|
/**
|
|
45
|
-
*
|
|
64
|
+
* 回退到指定路由页面,封装uni.navigateBack为Promise
|
|
65
|
+
* ⚠️ reLaunch兜底会清空全部页面栈,请谨慎开启
|
|
66
|
+
* ⚠️ delta超出页面栈层数时,原生会直接回退到首页,工具无法拦截
|
|
67
|
+
* ⚠️ uni.reLaunch 极少触发fail回调,路由错误也不会进入fail;reLaunch场景统一返回false
|
|
46
68
|
* @param targetRoute 目标页面路由,支持带/不带 /
|
|
47
|
-
* @param useReLaunchFallback
|
|
48
|
-
* @returns true
|
|
69
|
+
* @param useReLaunchFallback 找不到页面是否使用reLaunch兜底跳转,默认false
|
|
70
|
+
* @returns true=navigateBack成功;false=未找到/使用兜底跳转/异常
|
|
49
71
|
*/
|
|
50
72
|
export declare function backToRoute(targetRoute: string, useReLaunchFallback?: boolean): Promise<boolean>;
|
|
51
73
|
|
|
52
74
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param pageIns
|
|
55
|
-
* @returns Vue
|
|
75
|
+
* 安全获取页面的Vue组件$vm实例
|
|
76
|
+
* @param pageIns 包装页面对象
|
|
77
|
+
* @returns Vue组件实例,页面销毁/不存在返回null;业务建议自行做类型断言
|
|
56
78
|
*/
|
|
57
|
-
export declare function getPageVm(pageIns:
|
|
79
|
+
export declare function getPageVm(pageIns: PageWrap | null | undefined): any | null;
|
package/lib/pageStack/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("../index-1b48ae95.js");function c(t){if(!t)return null;let n=null,e=null;try{const{route:u,options:r}=t;if(u){const l=P.toQueryString(r??{});n=l?`${u}?${l}`:u,e=`/${n}`}}catch{n=null,e=null}return{...t,fullPath:n,navUrl:e}}function i(){try{const t=getCurrentPages();return t.length?c(t[t.length-1]):null}catch{return null}}function o(){try{const t=getCurrentPages();return t.length<2?null:c(t[t.length-2])}catch{return null}}function a(){try{return getCurrentPages().map(t=>c(t)).filter(Boolean)}catch{return[]}}function d(){try{var t;const n=i();return(t=n==null?void 0:n.route)!==null&&t!==void 0?t:null}catch{return null}}function h(){try{var t;const n=i();return(t=n==null?void 0:n.options)!==null&&t!==void 0?t:null}catch{return null}}function y(){try{var t;const n=o();return(t=n==null?void 0:n.route)!==null&&t!==void 0?t:null}catch{return null}}function g(t){return typeof t!="string"?"":t.replace(/^\/+/,"")}function v(t){try{var n;const e=a(),u=g(t);return u&&(n=e.find(r=>r.route===u))!==null&&n!==void 0?n:null}catch{return null}}function R(t){try{var n;const e=a();return t&&(n=e.find(u=>u.fullPath===t))!==null&&n!==void 0?n:null}catch{return null}}function m(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;return new Promise(e=>{try{const u=a(),r=g(t);if(!r){e(!1);return}const l=u.findIndex(s=>s.route===r);if(l===u.length-1){e(!0);return}if(l===-1){n?uni.reLaunch({url:`/${r}`,success:()=>e(!1),fail:()=>e(!1)}):e(!1);return}const f=u.length-1-l;uni.navigateBack({delta:f,success:()=>e(!0),fail:()=>e(!1)})}catch{e(!1)}})}function C(t){try{var n;return t&&(n=t.$vm)!==null&&n!==void 0?n:null}catch{return null}}exports.backToRoute=m;exports.findPageByFullPath=R;exports.findPageByRoute=v;exports.getCurrentPage=i;exports.getCurrentPageOptions=h;exports.getCurrentRoute=d;exports.getPageStack=a;exports.getPageVm=C;exports.getPrevPage=o;exports.getPrevRoute=y;
|
package/package.json
CHANGED
package/lib/index-4975afce.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function C(n,e,u,t,o,r,a){try{var i=n[r](a),c=i.value}catch(f){return void u(f)}i.done?e(c):Promise.resolve(c).then(t,o)}function h(n){return function(){var e=this,u=arguments;return new Promise(function(t,o){var r=n.apply(e,u);function a(c){C(r,t,o,a,i,"next",c)}function i(c){C(r,t,o,a,i,"throw",c)}a(void 0)})}}function y(){for(var n=arguments.length,e=new Array(n),u=0;u<n;u++)e[u]=arguments[u];if(e.some(t=>typeof t!="function"))throw new TypeError("compose 参数必须是函数");return e.length===0?function(){for(var t=arguments.length,o=new Array(t),r=0;r<t;r++)o[r]=arguments[r];return o.length===1?o[0]:o}:e.reduce((t,o)=>function(){for(var r=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return o.call(this,function(){for(var f=arguments.length,l=new Array(f),s=0;s<f;s++)l[s]=arguments[s];return t.apply(r,l.concat(i))},...i)})}function x(){for(var n=arguments.length,e=new Array(n),u=0;u<n;u++)e[u]=arguments[u];if(e.some(t=>typeof t!="function"))throw new TypeError("composeAsync 参数必须是函数");return e.length===0?h(function*(){for(var t=arguments.length,o=new Array(t),r=0;r<t;r++)o[r]=arguments[r];return o.length===1?o[0]:o}):e.reduce((t,o)=>h(function*(){for(var r=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return o.call(this,h(function*(){for(var f=arguments.length,l=new Array(f),s=0;s<f;s++)l[s]=arguments[s];return t.apply(r,l.concat(i))}),...i)}))}function P(){for(var n=arguments.length,e=new Array(n),u=0;u<n;u++)e[u]=arguments[u];if(e.some(t=>typeof t!="function"))throw new TypeError("pipe 参数必须是函数");return e.length===0?function(){for(var t=arguments.length,o=new Array(t),r=0;r<t;r++)o[r]=arguments[r];return o.length===1?o[0]:o}:e.reduce((t,o)=>function(){for(var r=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return t.call(this,function(){for(var f=arguments.length,l=new Array(f),s=0;s<f;s++)l[s]=arguments[s];return o.apply(r,l.concat(i))},...i)})}function I(){for(var n=arguments.length,e=new Array(n),u=0;u<n;u++)e[u]=arguments[u];if(e.some(t=>typeof t!="function"))throw new TypeError("pipeAsync 参数必须是函数");return e.length===0?h(function*(){for(var t=arguments.length,o=new Array(t),r=0;r<t;r++)o[r]=arguments[r];return o.length===1?o[0]:o}):e.reduce((t,o)=>h(function*(){for(var r=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return t.call(this,h(function*(){for(var f=arguments.length,l=new Array(f),s=0;s<f;s++)l[s]=arguments[s];return o.apply(r,l.concat(i))}),...i)}))}function R(n,e){let u=null;t.stop=()=>u&&clearTimeout(u);function t(){for(var o=arguments.length,r=new Array(o),a=0;a<o;a++)r[a]=arguments[a];t.stop(),u=setTimeout(()=>{n.apply(this,r)},e)}return t}function b(n,e){let u=null,t=[];o.stop=()=>{if(u){var r;(r=t.shift())===null||r===void 0||r("cancel"),clearTimeout(u)}};function o(){for(var r=arguments.length,a=new Array(r),i=0;i<r;i++)a[i]=arguments[i];return new Promise((c,f)=>{o.stop(),t.push(f),u=setTimeout(()=>{c(n.apply(this,a))},e)})}return o}function T(n){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,t;return u?function(){if(!t){t=!0;for(var o=arguments.length,r=new Array(o),a=0;a<o;a++)r[a]=arguments[a];typeof n=="function"&&n.apply(this,r),setTimeout(()=>{t=!1},e)}}:function(){for(var o=arguments.length,r=new Array(o),a=0;a<o;a++)r[a]=arguments[a];t||(t=!0,setTimeout(()=>{t=!1,typeof n=="function"&&n.apply(this,r)},e))}}function U(n){return encodeURIComponent(JSON.stringify(n||{}))}function E(n){return JSON.parse(decodeURIComponent(n||"{}"))}function A(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{silent:u=!1,decodePlus:t=!0,strict:o=!1}=e,r={};if(typeof n!="string")return r;function a(s,g){let m=s;t&&(m=m.replace(/\+/g," "));try{return decodeURIComponent(m)}catch(d){return u||console.warn(`Failed to decode ${g?"key":"value"}: ${m}`,d),o?null:(g&&(m=m.replace(/%[0-9a-f]{2}/gi,"")),m)}}const i=n.split("#")[0],c=i.indexOf("?"),f=c>=0?i.slice(c+1):i;if(!f)return r;const l=f.split("&");for(let s=0;s<l.length;s++){const g=l[s];if(!g)continue;const m=g.indexOf("=");let d,S;m===-1?(d=g,S=""):(d=g.slice(0,m),S=g.slice(m+1));const p=a(d,!0);if(p===null)continue;const w=a(S,!1);if(w===null||!p)continue;const v=r[p];v===void 0?r[p]=w:Array.isArray(v)?v.push(w):r[p]=[v,w]}return r}function M(n){return typeof window>"u"?{}:A(window.location.search,n)}function Q(n){if(typeof window>"u")return{};const e=window.location.hash,u=e.indexOf("?");if(u===-1)return{};const t=e.substring(u);return A(t,n)}function $(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=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(e)}function O(n){return n.replace(/([^-])([^-]*)/g,function(e,u,t){return u.toLocaleUpperCase()+t.toLocaleLowerCase()}).replace(/-/g,"")}function j(n,e){n=n.split("."),e=e.split(".");const u=Math.max(n.length,e.length);for(;n.length<u;)n.push("0");for(;e.length<u;)e.push("0");for(let t=0;t<u;t++){const o=parseInt(n[t]),r=parseInt(e[t]);if(o>r)return 1;if(o<r)return-1}return 0}function F(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function D(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,e=arguments.length>1?arguments[1]:void 0;n=n||32,e||(e="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");const u=e.length;let t="";for(let o=0;o<n;o++)t+=e.charAt(Math.floor(Math.random()*u));return t}function N(n){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;if(!n||typeof n!="object")return"";const u=[];Object.keys(n).forEach(o=>{const r=n[o];if(r==null)return;const a=encodeURIComponent(o);if(Array.isArray(r)){r.forEach(c=>{const f=encodeURIComponent(c);u.push(`${a}=${f}`)});return}let i=r;typeof i=="object"&&i!==null&&(i=JSON.stringify(i)),u.push(`${a}=${encodeURIComponent(i)}`)});const t=u.join("&");return e&&t?`?${t}`:t}function q(n){const e=n.scene;return e&&(n={fromCode:!0,...n,...A(e)}),n}function L(n,e){let u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:3600;try{let t=Number(u);Number.isFinite(t)||(t=0);const o=t>0?Math.round(t)*1e3:t;return uni.setStorageSync(n,{time:Date.now(),expire:o,data:e}),!0}catch(t){return console.error(`设置缓存[${n}]失败:`,t),!1}}function V(n){try{const e=uni.getStorageSync(n);return!e||typeof e!="object"||Array.isArray(e)||!("time"in e)||!("expire"in e)?(e&&uni.removeStorageSync(n),null):e.expire>0&&Date.now()-e.time>=e.expire?(uni.removeStorageSync(n),null):e.data}catch(e){return console.error(`获取缓存[${n}]失败:`,e),null}}function G(n){try{const e=uni.getStorageSync(n);if(!e||typeof e!="object"||Array.isArray(e)||!("time"in e)||!("expire"in e))return!1;if(e.expire>0){if(Date.now()-e.time>=e.expire)return uni.removeStorageSync(n),!1;e.time=Date.now(),uni.setStorageSync(n,e)}return!0}catch(e){return console.error(`续期缓存[${n}]失败:`,e),!1}}function H(n){try{return uni.removeStorageSync(n),!0}catch(e){return console.error(`删除缓存[${n}]失败:`,e),!1}}exports._asyncToGenerator=h;exports.compareVersion=j;exports.compose=y;exports.composeAsync=x;exports.debounce=R;exports.debouncePromise=b;exports.decodeURIParams=E;exports.encodeURIParams=U;exports.getCache=V;exports.getOnLoadParams=q;exports.getPascalCase=O;exports.getQueryParams=A;exports.getQueryParamsFromHash=Q;exports.getQueryParamsFromSearch=M;exports.getRandom=$;exports.getRandomStr=D;exports.pipe=P;exports.pipeAsync=I;exports.randomColor=F;exports.removeCache=H;exports.renewCache=G;exports.setCache=L;exports.throttle=T;exports.toQueryString=N;
|