utils-uniapp 1.1.5 → 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/http/index.d.ts +2 -2
- package/lib/http/index.js +1 -1
- package/package.json +1 -1
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-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:
|
|
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;
|