utils-uniapp 1.1.4 → 1.1.6
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 +1 -1
- package/lib/getLocation/index.js +1 -1
- package/lib/http/index.d.ts +2 -2
- package/lib/http/index.js +1 -1
- package/lib/{index-b81565a7.js → index-4975afce.js} +1 -1
- package/lib/index.js +1 -1
- package/lib/magic/index.d.ts +15 -11
- package/lib/magic/index.js +1 -1
- package/package.json +1 -1
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-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;
|
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-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;
|
package/lib/http/index.d.ts
CHANGED
|
@@ -126,7 +126,7 @@ export interface NormalizeOpts {
|
|
|
126
126
|
cachePrefix?: string;
|
|
127
127
|
/** 完整缓存key,传入则完全覆盖,优先级高于cachePrefix */
|
|
128
128
|
cacheKey: string;
|
|
129
|
-
/**
|
|
129
|
+
/** 缓存过期时间,单位秒(s), 默认1小时过期 */
|
|
130
130
|
cacheExpire: number;
|
|
131
131
|
/** loading提示文案 */
|
|
132
132
|
loadingText: string;
|
|
@@ -157,7 +157,7 @@ export interface UserRequestOpts {
|
|
|
157
157
|
cachePrefix?: string;
|
|
158
158
|
/** 完整缓存key,传入则完全覆盖,优先级高于cachePrefix */
|
|
159
159
|
cacheKey?: string;
|
|
160
|
-
/**
|
|
160
|
+
/** 缓存过期时间,单位秒(s), 默认1小时过期 */
|
|
161
161
|
cacheExpire?: number;
|
|
162
162
|
/** loading提示文案 */
|
|
163
163
|
loadingText?: string;
|
package/lib/http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("../index-
|
|
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:60*60,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
|
|
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-
|
|
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;
|
package/lib/magic/index.d.ts
CHANGED
|
@@ -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
|
|
186
|
-
* @param
|
|
187
|
-
* @param
|
|
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
|
|
193
|
+
* 读取本地缓存;自动判断过期,过期自动删除并返回null
|
|
194
|
+
* @param key 缓存存储键名
|
|
195
|
+
* @returns 缓存有效返回存储data;缓存不存在/结构异常/已过期返回null
|
|
194
196
|
*/
|
|
195
|
-
export function getCache
|
|
197
|
+
export function getCache(key: string): any | null;
|
|
196
198
|
|
|
197
199
|
/**
|
|
198
|
-
*
|
|
199
|
-
* @param
|
|
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
|
|
207
|
+
* 删除指定key本地缓存
|
|
208
|
+
* @param key 缓存存储键名
|
|
209
|
+
* @returns true删除成功;false删除异常失败
|
|
206
210
|
*/
|
|
207
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-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;
|