utils-uniapp 1.1.2 → 1.1.5

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/fs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../index-b81565a7.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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../index-4975afce.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;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../index-b81565a7.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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../index-4975afce.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;
@@ -63,10 +63,7 @@ type UniAnyResult = UniRequestResult | UniUploadResult | UniDownloadResult;
63
63
  * @param opts 请求参数,可以传入 cancelToken 用于请求取消
64
64
  * @returns uni接口回调结果Promise
65
65
  */
66
- export declare function promisifyRequest<T = UniAnyResult>(
67
- type: 'request' | 'uploadFile' | 'downloadFile',
68
- opts: Record<string, any>
69
- ): Promise<T>;
66
+ export declare function promisifyRequest<T = UniAnyResult>(type: 'request' | 'uploadFile' | 'downloadFile', opts: Record<string, any>): Promise<T>;
70
67
 
71
68
  /**
72
69
  * 开启loading计数
@@ -125,7 +122,9 @@ export interface NormalizeOpts {
125
122
  showError: boolean;
126
123
  /** 是否开启接口缓存 */
127
124
  isCache: boolean;
128
- /** 缓存key名称 */
125
+ /** 缓存key前缀;不传/空字符串/undefined默认使用api;设置cacheKey时此配置无效 */
126
+ cachePrefix?: string;
127
+ /** 完整缓存key,传入则完全覆盖,优先级高于cachePrefix */
129
128
  cacheKey: string;
130
129
  /** 缓存过期时间,单位ms */
131
130
  cacheExpire: number;
@@ -148,16 +147,29 @@ export interface NormalizeOpts {
148
147
  * 经过内部 normalizeOpts 之后转换为 NormalizeOpts
149
148
  */
150
149
  export interface UserRequestOpts {
150
+ /** post请求是否使用urlencoded表单格式 */
151
151
  qs?: boolean;
152
+ /** 是否开启默认错误弹窗提示 */
152
153
  showError?: boolean;
154
+ /** 是否开启接口缓存 */
153
155
  isCache?: boolean;
156
+ /** 缓存key前缀;不传/空字符串/undefined默认使用api;设置cacheKey时此配置无效 */
157
+ cachePrefix?: string;
158
+ /** 完整缓存key,传入则完全覆盖,优先级高于cachePrefix */
154
159
  cacheKey?: string;
160
+ /** 缓存过期时间,单位ms */
155
161
  cacheExpire?: number;
162
+ /** loading提示文案 */
156
163
  loadingText?: string;
164
+ /** 是否开启loading */
157
165
  loading?: boolean;
166
+ /** 请求前置拦截器,支持单个函数或函数数组 */
158
167
  reqInterceptor?: UserReqInterceptor;
168
+ /** 响应拦截器,支持单个函数或函数数组 */
159
169
  resInterceptor?: UserResInterceptor;
170
+ /** 错误拦截器,支持单个函数或函数数组 */
160
171
  errInterceptor?: UserErrInterceptor;
172
+ /** 允许扩展自定义字段 */
161
173
  [key: string]: any;
162
174
  }
163
175
 
@@ -200,10 +212,7 @@ interface RequestInstance {
200
212
  * @param defaultOpts 全局默认扩展配置 loading、缓存、拦截器等,拦截器支持数组
201
213
  * @returns RequestInstance 请求实例
202
214
  */
203
- export declare function createRequest(
204
- defaultConfig: Record<string, any>,
205
- defaultOpts?: UserRequestOpts
206
- ): RequestInstance;
215
+ export declare function createRequest(defaultConfig: Record<string, any>, defaultOpts?: UserRequestOpts): RequestInstance;
207
216
 
208
217
  /**
209
218
  * 创建上传文件实例
@@ -214,12 +223,7 @@ export declare function createRequest(
214
223
  export declare function createUploadFile(
215
224
  defaultConfig: Record<string, any>,
216
225
  defaultOpts?: UserRequestOpts
217
- ): (
218
- url: string,
219
- params: { filePath: string; keyName?: string; [key: string]: any },
220
- config?: Record<string, any>,
221
- options?: UserRequestOpts
222
- ) => Promise<any>;
226
+ ): (url: string, params: { filePath: string; keyName?: string; [key: string]: any }, config?: Record<string, any>, options?: UserRequestOpts) => Promise<any>;
223
227
 
224
228
  /**
225
229
  * 创建下载文件实例
@@ -230,9 +234,4 @@ export declare function createUploadFile(
230
234
  export declare function createDownloadFile(
231
235
  defaultConfig: Record<string, any>,
232
236
  defaultOpts?: UserRequestOpts
233
- ): (
234
- url: string,
235
- params?: Record<string, any>,
236
- config?: Record<string, any>,
237
- options?: UserRequestOpts
238
- ) => Promise<any>;
237
+ ): (url: string, params?: Record<string, any>, config?: Record<string, any>, options?: UserRequestOpts) => Promise<any>;
package/lib/http/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("../index-b81565a7.js"),A=require("../object/index.js"),O=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"}),m={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()}-${C.getRandomStr(16)}`;return{token:e,cancel:()=>this._cancel(e)}}};function b(e,t){return new Promise((o,n)=>{const c=uni[e]({...t,success(r){if(r.statusCode>=200&&r.statusCode<300)return o(r);n({type:"fail",res:r})},fail(r){n({type:"fail",res:r})},complete(){t.cancelToken&&m.delete(t.cancelToken)}});t.cancelToken&&m.add(t.cancelToken,c)})}let R=0,v=!1;function N(e){v||(v=!0,uni.showLoading({title:e,mask:!0}))}function S(){v&&(v=!1,uni.hideLoading())}function j(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"加载中...";R++,R===1&&N(e)}function D(){R>0&&R--,R===0&&S()}function _(e,t){return function(o,n,c,r){return e(o,t,n,c,r)}}function w(e){return typeof e=="function"?e:()=>e||{}}function k(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n=w(t.headers)(),c=w(o.headers)(),r={...t,...o,headers:{...n,...c}},{headers:a,...s}=r;return{urlRes:e.startsWith("http")?e:r.baseURL?r.baseURL+e:e,headers:a,configRes:s}}function U(e){return typeof e=="function"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="function"):[]}function F(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n={qs:!0,showError:!0,isCache:!1,cacheKey:`api:${e.url}`,cacheExpire:1e3*60*60*1,loadingText:e.loadingText,loading:!0,reqInterceptor:c=>c,resInterceptor:c=>c,errInterceptor:()=>{},...t,...o};return["reqInterceptor","resInterceptor","errInterceptor"].forEach(c=>{const r=[...U(t[c]),...U(o[c])];n[c]=r.length?C.composeAsync(...r):a=>a}),n}function q(e,t){const o=Array.from(t);return()=>e(...A.cloneDeepWithDescriptors(o))}function E(e,t,o,n,c){return x.apply(this,arguments)}function x(){return x=C._asyncToGenerator(function*(e,t,o,n,c){let r;n.loading&&(j(n.loadingText),r=()=>{D(),r=null});try{var a;const u=yield n.reqInterceptor(o,n),l=yield e(t,u);return(a=r)===null||a===void 0||a(),yield n.resInterceptor(l,n,c)}catch(u){var s;(s=r)===null||s===void 0||s();const l=yield n.errInterceptor(u,n);return l!==void 0?l:Promise.reject(u)}}),x.apply(this,arguments)}function L(e,t){function o(n,c,r,a,s){const u=m.source(),l=q(o,arguments),i=F({url:n,loadingText:"加载中..."},t,s),{urlRes:y,headers:T,configRes:g}=k(n,e,a);if(i.isCache){const d=C.getCache(i.cacheKey);if(d)return Promise.resolve(d)}const p=c.toUpperCase()==="GET"?O.JSON:i.qs?O.FORM_URLENCODED:O.JSON,h={cancelToken:u.token,method:c,url:y,data:r,header:{"Content-Type":p,...T},...g};return E(b,"request",h,i,l).then(d=>(i.isCache&&C.setCache(i.cacheKey,d,i.cacheExpire),d))}return o.get=_(o,"get"),o.post=_(o,"post"),o}function P(e,t){return function o(n,c,r,a){const s=m.source(),u=q(o,arguments),l=F({loadingText:"上传中..."},t,a),{urlRes:i,headers:y,configRes:T}=k(n,e,r),{keyName:g="file",filePath:f,...p}={keyName:"file",...c};if(!f||!f.startsWith("http://tmp")&&!f.startsWith("wxfile://tmp"))return Promise.resolve({data:f});const h={cancelToken:s.token,url:i,filePath:f,name:g,formData:p,header:{...y},...T};return E(b,"uploadFile",h,l,u)}}function z(e,t){return function o(n,c,r,a){const s=m.source(),u=q(o,arguments),l=F({loadingText:"下载中..."},t,a),{urlRes:i,headers:y,configRes:T}=k(n,e,r);let g=i;if(c&&typeof c=="object"){const p=Object.entries(c).filter(h=>{let[,d]=h;return d!=null&&d!==""}).map(h=>{let[d,I]=h;return`${encodeURIComponent(d)}=${encodeURIComponent(I)}`}).join("&");p&&(g+=(g.includes("?")?"&":"?")+p)}const f={cancelToken:s.token,url:g,header:{...y},...T};return E(b,"downloadFile",f,l,u)}}exports.CONTENT_TYPES=O;exports.CancelToken=m;exports.createDownloadFile=z;exports.createRequest=L;exports.createUploadFile=P;exports.endLoading=D;exports.promisifyRequest=b;exports.startLoading=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("../index-4975afce.js"),A=require("../object/index.js"),O=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"}),m={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()}-${C.getRandomStr(16)}`;return{token:e,cancel:()=>this._cancel(e)}}};function x(e,t){return new Promise((c,n)=>{const r=uni[e]({...t,success(o){if(o.statusCode>=200&&o.statusCode<300)return c(o);n({type:"fail",res:o})},fail(o){n({type:"fail",res:o})},complete(){t.cancelToken&&m.delete(t.cancelToken)}});t.cancelToken&&m.add(t.cancelToken,r)})}let R=0,v=!1;function N(e){v||(v=!0,uni.showLoading({title:e,mask:!0}))}function P(){v&&(v=!1,uni.hideLoading())}function j(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"加载中...";R++,R===1&&N(e)}function D(){R>0&&R--,R===0&&P()}function _(e,t){return function(c,n,r,o){return e(c,t,n,r,o)}}function w(e){return typeof e=="function"?e:()=>e||{}}function k(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n=w(t.headers)(),r=w(c.headers)(),o={...t,...c,headers:{...n,...r}},{headers:a,...s}=o;return{urlRes:e.startsWith("http")?e:o.baseURL?o.baseURL+e:e,headers:a,configRes:s}}function U(e){return typeof e=="function"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="function"):[]}function F(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n={qs:!0,showError:!0,isCache:!1,cacheExpire:1e3*60*60*1,loadingText:e.loadingText,loading:!0,reqInterceptor:r=>r,resInterceptor:r=>r,errInterceptor:()=>{},...t,...c};if(!n.cacheKey){const r=(n.cachePrefix||"api").replace(/:$/,"");n.cacheKey=`${r}:${e.url}`}return["reqInterceptor","resInterceptor","errInterceptor"].forEach(r=>{const o=[...U(t[r]),...U(c[r])];n[r]=o.length?C.composeAsync(...o):a=>a}),n}function q(e,t){const c=Array.from(t);return()=>e(...A.cloneDeepWithDescriptors(c))}function E(e,t,c,n,r){return b.apply(this,arguments)}function b(){return b=C._asyncToGenerator(function*(e,t,c,n,r){let o;n.loading&&(j(n.loadingText),o=()=>{D(),o=null});try{var a;const u=yield n.reqInterceptor(c,n),l=yield e(t,u);return(a=o)===null||a===void 0||a(),yield n.resInterceptor(l,n,r)}catch(u){var s;(s=o)===null||s===void 0||s();const l=yield n.errInterceptor(u,n);return l!==void 0?l:Promise.reject(u)}}),b.apply(this,arguments)}function S(e,t){function c(n,r,o,a,s){const u=m.source(),l=q(c,arguments),i=F({url:n,loadingText:"加载中..."},t,s),{urlRes:y,headers:T,configRes:h}=k(n,e,a);if(i.isCache){const d=C.getCache(i.cacheKey);if(d)return Promise.resolve(d)}const p=r.toUpperCase()==="GET"?O.JSON:i.qs?O.FORM_URLENCODED:O.JSON,g={cancelToken:u.token,method:r,url:y,data:o,header:{"Content-Type":p,...T},...h};return E(x,"request",g,i,l).then(d=>(i.isCache&&C.setCache(i.cacheKey,d,i.cacheExpire),d))}return c.get=_(c,"get"),c.post=_(c,"post"),c}function L(e,t){return function c(n,r,o,a){const s=m.source(),u=q(c,arguments),l=F({loadingText:"上传中..."},t,a),{urlRes:i,headers:y,configRes:T}=k(n,e,o),{keyName:h="file",filePath:f,...p}={keyName:"file",...r};if(!f||!f.startsWith("http://tmp")&&!f.startsWith("wxfile://tmp"))return Promise.resolve({data:f});const g={cancelToken:s.token,url:i,filePath:f,name:h,formData:p,header:{...y},...T};return E(x,"uploadFile",g,l,u)}}function $(e,t){return function c(n,r,o,a){const s=m.source(),u=q(c,arguments),l=F({loadingText:"下载中..."},t,a),{urlRes:i,headers:y,configRes:T}=k(n,e,o);let h=i;if(r&&typeof r=="object"){const p=Object.entries(r).filter(g=>{let[,d]=g;return d!=null&&d!==""}).map(g=>{let[d,I]=g;return`${encodeURIComponent(d)}=${encodeURIComponent(I)}`}).join("&");p&&(h+=(h.includes("?")?"&":"?")+p)}const f={cancelToken:s.token,url:h,header:{...y},...T};return E(x,"downloadFile",f,l,u)}}exports.CONTENT_TYPES=O;exports.CancelToken=m;exports.createDownloadFile=$;exports.createRequest=S;exports.createUploadFile=L;exports.endLoading=D;exports.promisifyRequest=x;exports.startLoading=j;
@@ -1 +1 @@
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 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("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 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("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 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("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 T(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 b(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 Q(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 $(n){return typeof window>"u"?{}:A(window.location.search,n)}function M(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 O(){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 j(n){return n.replace(/([^-])([^-]*)/g,function(e,u,t){return u.toLocaleUpperCase()+t.toLocaleLowerCase()}).replace(/-/g,"")}function E(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 D(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function F(){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 q(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 L(n){const e=n.scene;return e&&(n={fromCode:!0,...n,...A(e)}),n}function V(n,e){let u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:36e5;try{return uni.setStorageSync(n,{time:Date.now(),expire:u,data:e}),!0}catch(t){return console.error(`设置缓存[${n}]失败:`,t),!1}}function G(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):Date.now()-e.time>=e.expire?(uni.removeStorageSync(n),null):e.data}catch(e){return console.error(`获取缓存[${n}]失败:`,e),null}}function H(n){try{const e=uni.getStorageSync(n);return!e||typeof e!="object"||Array.isArray(e)||!("time"in e)||!("expire"in e)?!1:Date.now()-e.time>=e.expire?(uni.removeStorageSync(n),!1):(e.time=Date.now(),uni.setStorageSync(n,e),!0)}catch(e){return console.error(`续期缓存[${n}]失败:`,e),!1}}function J(n){try{return uni.removeStorageSync(n),!0}catch(e){return console.error(`删除缓存[${n}]失败:`,e),!1}}exports._asyncToGenerator=h;exports.compareVersion=E;exports.compose=y;exports.composeAsync=P;exports.debounce=R;exports.debouncePromise=T;exports.decodeURIParams=Q;exports.encodeURIParams=U;exports.getCache=G;exports.getOnLoadParams=L;exports.getPascalCase=j;exports.getQueryParams=A;exports.getQueryParamsFromHash=M;exports.getQueryParamsFromSearch=$;exports.getRandom=O;exports.getRandomStr=F;exports.pipe=I;exports.pipeAsync=x;exports.randomColor=D;exports.removeCache=J;exports.renewCache=H;exports.setCache=V;exports.throttle=b;exports.toQueryString=q;
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;
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./aliPay/index.js"),a=require("./array/index.js"),s=require("./date/index.js"),o=require("./fs/index.js"),g=require("./getLocation/index.js"),r=require("./http/index.js"),e=require("./index-b81565a7.js"),n=require("./object/index.js"),t=require("./pageStack/index.js"),i=require("./validate/index.js"),d=require("./index-9456b3d9.js"),m=require("./lodash");Object.assign(exports,m);exports.alipaySubmit=c.alipaySubmit;exports.exchangeArrP=a.exchangeArrP;exports.filterTree=a.filterTree;exports.findTreeItem=a.findTreeItem;exports.flatWithKey=a.flatWithKey;exports.getTreePath=a.getTreePath;exports.groupBy=a.groupBy;exports.reverseForEach=a.reverseForEach;exports.treeItemSetParent=a.treeItemSetParent;exports.dateFormat=s.dateFormat;exports.getDate=s.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=g.getLocation;exports.openLocation=g.openLocation;exports.CONTENT_TYPES=r.CONTENT_TYPES;exports.CancelToken=r.CancelToken;exports.createDownloadFile=r.createDownloadFile;exports.createRequest=r.createRequest;exports.createUploadFile=r.createUploadFile;exports.endLoading=r.endLoading;exports.promisifyRequest=r.promisifyRequest;exports.startLoading=r.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.getCache=e.getCache;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.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;exports.cloneDeepWithDescriptors=n.cloneDeepWithDescriptors;exports.getRawType=n.getRawType;exports.hasOwnProperty=n.hasOwnProperty;exports.backToRoute=t.backToRoute;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=d.index;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./aliPay/index.js"),a=require("./array/index.js"),s=require("./date/index.js"),o=require("./fs/index.js"),g=require("./getLocation/index.js"),r=require("./http/index.js"),e=require("./index-4975afce.js"),n=require("./object/index.js"),t=require("./pageStack/index.js"),i=require("./validate/index.js"),d=require("./index-9456b3d9.js"),m=require("./lodash");Object.assign(exports,m);exports.alipaySubmit=c.alipaySubmit;exports.exchangeArrP=a.exchangeArrP;exports.filterTree=a.filterTree;exports.findTreeItem=a.findTreeItem;exports.flatWithKey=a.flatWithKey;exports.getTreePath=a.getTreePath;exports.groupBy=a.groupBy;exports.reverseForEach=a.reverseForEach;exports.treeItemSetParent=a.treeItemSetParent;exports.dateFormat=s.dateFormat;exports.getDate=s.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=g.getLocation;exports.openLocation=g.openLocation;exports.CONTENT_TYPES=r.CONTENT_TYPES;exports.CancelToken=r.CancelToken;exports.createDownloadFile=r.createDownloadFile;exports.createRequest=r.createRequest;exports.createUploadFile=r.createUploadFile;exports.endLoading=r.endLoading;exports.promisifyRequest=r.promisifyRequest;exports.startLoading=r.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.getCache=e.getCache;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.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;exports.cloneDeepWithDescriptors=n.cloneDeepWithDescriptors;exports.getRawType=n.getRawType;exports.hasOwnProperty=n.hasOwnProperty;exports.backToRoute=t.backToRoute;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=d.index;
@@ -181,27 +181,31 @@ export declare function toQueryString(
181
181
  export function getOnLoadParams<T extends Record<string, any>>(e: T & { scene?: string }): T & { fromCode?: boolean } & Record<string, any>;
182
182
 
183
183
  /**
184
- * 设置本地缓存(带过期时间)
185
- * @param { string } key 缓存键名
186
- * @param { any } data 缓存数据
187
- * @param { number } expire 过期时间(毫秒),默认1小时
184
+ * 设置uni‑app本地缓存,支持过期时间控制
185
+ * @param key 缓存存储键名
186
+ * @param data 需要存储的数据,可以为任意可序列化类型
187
+ * @param expire 过期时长,单位:秒;<=0代表永不过期;非法数字自动降级永不过期;默认 3600(1小时)
188
+ * @returns true写入成功;false写入发生异常失败
188
189
  */
189
190
  export function setCache(key: string, data: any, expire?: number): boolean;
190
191
 
191
192
  /**
192
- * 获取本地缓存(自动校验有效性,过期自动清理)
193
- * @param { string } key 缓存键名
193
+ * 读取本地缓存;自动判断过期,过期自动删除并返回null
194
+ * @param key 缓存存储键名
195
+ * @returns 缓存有效返回存储data;缓存不存在/结构异常/已过期返回null
194
196
  */
195
- export function getCache<T = any>(key: string): T | null;
197
+ export function getCache(key: string): any | null;
196
198
 
197
199
  /**
198
- * 续期缓存,重置过期倒计时(沿用原有expire时长)
199
- * @param { string } key 缓存键名
200
+ * 缓存续期,重置过期计时;永不过期缓存不会写入存储,直接返回true
201
+ * @param key 缓存存储键名
202
+ * @returns true:缓存有效;false:缓存不存在/结构损坏/已经过期
200
203
  */
201
204
  export function renewCache(key: string): boolean;
202
205
 
203
206
  /**
204
- * 删除指定缓存
205
- * @param { string } key 缓存键名
207
+ * 删除指定key本地缓存
208
+ * @param key 缓存存储键名
209
+ * @returns true删除成功;false删除异常失败
206
210
  */
207
211
  export function removeCache(key: string): boolean;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index-b81565a7.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.getCache=e.getCache;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.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index-4975afce.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.getCache=e.getCache;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.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-uniapp",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "description": "aubyn's utils for uniapp",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",