uniapp-request-sdk 1.3.0 → 1.3.1
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/dist/index.d.ts +1 -1
- package/dist/index.umd.mini.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.umd.mini.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["UNIAPP-REQUEST-SDK"]={})}(this,(function(e){"use strict";function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"))?i:String(i)),r)}var o,i}var n=function(){function e(t){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.baseUrl="",this.onErrorHandler=function(e){console.error(e)},this.maxRetryCount=3,this.timeout=1e4,this.retryDelay=
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["UNIAPP-REQUEST-SDK"]={})}(this,(function(e){"use strict";function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"))?i:String(i)),r)}var o,i}var n=function(){function e(t){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.baseUrl="",this.onErrorHandler=function(e){console.error(e)},this.maxRetryCount=3,this.timeout=1e4,this.retryDelay=3e3,this.tokenEventName="getLoginInfo",t&&Object.keys(t).forEach((function(e){void 0!==t[e]&&(n[e]=t[e])}))}var n,r,o;return n=e,r=[{key:"rejectHandler",value:function(e,t){var n;e(t),null===(n=this.onErrorHandler)||void 0===n||n.call(this,t)}},{key:"setParams",value:function(e){var t=this;e&&Object.keys(e).forEach((function(n){void 0!==e[n]&&(t[n]=e[n])}))}},{key:"request",value:function(e){var t=this,n=e.url;n=/^https?:\/\//.test(n)?"".concat(e.url,"?t=").concat(Date.now()):"".concat(this.baseUrl.replace(/\/$/,""),"/").concat(e.url.replace(/^\//,""),"?t=").concat(Date.now());var r=Object.assign(Object.assign(Object.assign({},this.header),e.header),{Authorization:"Bearer ".concat(this.token)}),o=!1,i=0;return new Promise((function(a,u){var c=function(){var c;(c=Object.assign(Object.assign({},e),{header:r,url:n,timeout:t.timeout}),new Promise((function(e,t){uni.request(Object.assign(Object.assign({},c),{success:e,fail:t}))}))).then((function(e){var n,r=e.statusCode,c=e.data;200===r?c.errno?t.rejectHandler(u,e):a(c.data):403!==r||o?t.maxRetryCount>i?s():t.rejectHandler(u,e):((n=t.tokenEventName,new Promise((function(e,t){var r=setTimeout(t,5e3);uni.sendNativeEvent(n,{},(function(t){clearTimeout(r),e(null==t?void 0:t.token)}))}))).then((function(e){t.token=e,o=!0,s()})).catch((function(){t.maxRetryCount>i?s():t.rejectHandler(u,e)})),t.rejectHandler(u,e))})).catch((function(e){t.maxRetryCount>i?s():t.rejectHandler(u,e)}))},s=function(){setTimeout((function(){i++,c()}),t.retryDelay)};c()}))}},{key:"post",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return this.request({url:e,data:t,header:n,method:"POST"})}},{key:"get",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return this.request({url:e,data:t,header:n,method:"GET"})}},{key:"delete",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return this.request({url:e,data:t,header:n,method:"DELETE"})}},{key:"put",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;return this.request({url:e,data:t,header:n,method:"PUT"})}}],r&&t(n.prototype,r),o&&t(n,o),Object.defineProperty(n,"prototype",{writable:!1}),e}();e.default=n,Object.defineProperty(e,"__esModule",{value:!0})}));
|