@ibiz-template/core 0.0.1-alpha.34 → 0.0.1-alpha.37
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/system/index.system.js +1 -1
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +1 -0
- package/out/install.js +2 -2
- package/out/interface/i-environment/i-environment.d.ts +8 -0
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/utils/index.d.ts +1 -1
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +1 -1
- package/out/utils/interceptor/core-interceptor.d.ts +15 -0
- package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
- package/out/utils/interceptor/core-interceptor.js +30 -0
- package/out/utils/interceptor/index.d.ts +3 -0
- package/out/utils/interceptor/index.d.ts.map +1 -0
- package/out/utils/interceptor/index.js +2 -0
- package/out/utils/interceptor/interceptor.d.ts +74 -3
- package/out/utils/interceptor/interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/interceptor.js +75 -22
- package/out/utils/net/net.d.ts +66 -22
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +97 -35
- package/package.json +4 -4
- package/src/environment/environment.ts +1 -0
- package/src/install.ts +2 -2
- package/src/interface/i-environment/i-environment.ts +9 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/interceptor/core-interceptor.ts +35 -0
- package/src/utils/interceptor/index.ts +2 -0
- package/src/utils/interceptor/interceptor.ts +111 -22
- package/src/utils/net/net.ts +122 -40
|
@@ -1 +1 @@
|
|
|
1
|
-
System.register(["axios","lodash-es","qx-util","qs","pluralize"],(function(e){"use strict";var t,n,o,r,i,s;return{setters:[function(e){t=e.default},function(e){n=e.debounce},function(e){o=e.getCookie,r=e.notNilEmpty},function(e){i=e.stringify},function(e){s=e.default}],execute:function(){function a(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}e({debounceAndMerge:function(e,t,o,r){var i,s=n((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return i=void 0,e.apply(void 0,b([],g(t),!1))}),o,r);return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var o=e;return i&&(o=t(i,o)),i=o,s.apply(void 0,b([],g(o),!1))}},getToken:w,install:function(){if(window.ibiz)throw new Error("ibiz 已经存在, 无需重复安装");window.ibiz=new A,window.___fc=new C,new x},isOverlap:function(e,t){return Array.from(new Set(b(b([],g(e),!1),g(t),!1))).length!==e.length+t.length},plural:P,pluralLower:function(e){return P(e).toLowerCase()}});var c,u,l=e("CoreConst",function(){function e(){}return e.DEFAULT_MODEL_SERVICE_TAG="default",e.TOKEN="access_token",e}()),f=e("HttpStatusMessageConst",{200:"服务器成功返回请求的数据。",201:"新建或修改数据成功。",202:"一个请求已经进入后台排队(异步任务)。",204:"删除数据成功。",400:"发出的请求有错误,服务器没有进行新建或修改数据的操作。",401:"用户没有权限(令牌、用户名、密码错误)。",403:"用户得到授权,但是访问是被禁止的。",404:"发出的请求针对的是不存在的记录,服务器没有进行操作。",406:"请求的格式不可得。",410:"请求的资源被永久删除,且不会再得到的。",422:"当创建一个对象时,发生一个验证错误。",500:"服务器发生错误,请检查服务器。",502:"网关错误。",503:"服务不可用,服务器暂时过载或维护。",504:"网关超时。"});e("LoginMode",c),function(e){e.DEFAULT="DEFAULT",e.CUSTOM="CUSTOM",e.CAS="CAS"}(c||e("LoginMode",c={})),e("MenuPermissionMode",u),function(e){e.MIXIN="MIXIN",e.RESOURCE="RESOURCE",e.RT="RT"}(u||e("MenuPermissionMode",u={}));e("IBizContext",(function(e,t){if(void 0===e&&(e={}),t){var n=this;Object.defineProperty(this,"_context",{enumerable:!1,value:{}});var o={};Object.keys(t).forEach((function(e){o[e]={enumerable:!0,set:function(t){n._context[e]=null==t?null:t},get:function(){return void 0!==n._context[e]?n._context[e]:t[e]}}})),Object.defineProperties(this,o)}Object.assign(this,e)}));var p=e("Environment",{dev:!1,logLevel:"ERROR",jsCdn:"https://cdn.jsdelivr.net",baseUrl:"",remoteModelUrl:"/remotemodel",assetsUrl:"./assets",dcSystem:"",ExportFile:"/ibizutil/download",UploadFile:"/ibizutil/upload",casLoginUrl:"",loginMode:c.DEFAULT,menuPermissionMode:u.MIXIN,enablePermission:!0}),h=e("HttpError",(function(e){this.name="HttpError";var t=e.response;this.response=e.response,t?(t.data?this.message=t.data.message:this.message=t.statusText,this.message||(this.message=f[t.status]),this.message||(this.message="网络异常,请稍后重试!"),this.status=t.status):(this.message=e.message,this.status=500)})),d=(e("RuntimeError",(function(e){this.message=e,this.name="Runtime Error"})),function(){return d=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},d.apply(this,arguments)});function y(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))}function v(e,t){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function g(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s}function b(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}function w(){return o(l.TOKEN)}var m,E,R,x=e("Interceptor",function(){function e(){this.init()}return e.prototype.init=function(){t.interceptors.request.use((function(e){e.headers||(e.headers={}),e.headers.Authorization="Bearer ".concat(w());var t=ibiz.orgData;return t&&(t.systemid&&(e.headers.srfsystemid=t.systemid),t.orgid&&(e.headers.srforgid=t.orgid)),e}))},e}()),O="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},L={exports:{}};E=O,R=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function r(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function i(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(o){return"debug"===o&&(o="log"),typeof console!==t&&("trace"===o&&n?i:void 0!==console[o]?r(console,o):void 0!==console.log?r(console,"log"):e)}function a(t,n){for(var r=0;r<o.length;r++){var i=o[r];this[i]=r<t?e:this.methodFactory(i,t,n)}this.log=this.debug}function c(e,n,o){return function(){typeof console!==t&&(a.call(this,n,o),this[e].apply(this,arguments))}}function u(e,t,n){return s(e)||c.apply(this,arguments)}function l(e,n,r){var i,s=this;n=null==n?"WARN":n;var c="loglevel";function l(){var e;if(typeof window!==t&&c){try{e=window.localStorage[c]}catch(e){}if(typeof e===t)try{var n=window.document.cookie,o=n.indexOf(encodeURIComponent(c)+"=");-1!==o&&(e=/^([^;]+)/.exec(n.slice(o))[1])}catch(e){}return void 0===s.levels[e]&&(e=void 0),e}}"string"==typeof e?c+=":"+e:"symbol"==typeof e&&(c=void 0),s.name=e,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=r||u,s.getLevel=function(){return i},s.setLevel=function(n,r){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(i=n,!1!==r&&function(e){var n=(o[e]||"silent").toUpperCase();if(typeof window!==t&&c){try{return void(window.localStorage[c]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(c)+"="+n+";"}catch(e){}}}(n),a.call(s,n,e),typeof console===t&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(e){n=e,l()||s.setLevel(e,!1)},s.resetLevel=function(){s.setLevel(n,!1),function(){if(typeof window!==t&&c){try{return void window.localStorage.removeItem(c)}catch(e){}try{window.document.cookie=encodeURIComponent(c)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}()},s.enableAll=function(e){s.setLevel(s.levels.TRACE,e)},s.disableAll=function(e){s.setLevel(s.levels.SILENT,e)};var f=l();null==f&&(f=n),s.setLevel(f,!1)}var f=new l,p={};f.getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=p[e];return t||(t=p[e]=new l(e,f.getLevel(),f.methodFactory)),t};var h=typeof window!==t?window.log:void 0;return f.noConflict=function(){return typeof window!==t&&window.log===f&&(window.log=h),f},f.getLoggers=function(){return p},f.default=f,f},(m=L).exports?m.exports=R():E.log=R();var T=a({__proto__:null,default:L.exports},[L.exports]);e("Logger",T);function U(e,t,n,o,r){var i="".concat(e,"-").concat(t);return n&&(i+="-".concat(n)),o&&(i+="__".concat(o)),r&&(i+="--".concat(r)),i}e("Namespace",function(){function e(e,t){this.block=e,this.namespace=t||"ibiz"}return e.prototype.b=function(e){return void 0===e&&(e=""),U(this.namespace,this.block,e,"","")},e.prototype.e=function(e){return e?U(this.namespace,this.block,"",e,""):""},e.prototype.m=function(e){return e?U(this.namespace,this.block,"","",e):""},e.prototype.be=function(e,t){return e&&t?U(this.namespace,this.block,e,t,""):""},e.prototype.em=function(e,t){return e&&t?U(this.namespace,this.block,"",e,t):""},e.prototype.bm=function(e,t){return e&&t?U(this.namespace,this.block,e,"",t):""},e.prototype.bem=function(e,t,n){return e&&t&&n?U(this.namespace,this.block,e,t,n):""},e.prototype.is=function(e,t){return e&&t?"".concat("is-").concat(e):""},e.prototype.cssVar=function(e){var t={};for(var n in e)e[n]&&(t[this.cssVarName(n)]=e[n]);return t},e.prototype.cssVarBlock=function(e){var t={};for(var n in e)e[n]&&(t[this.cssVarBlockName(n)]=e[n]);return t},e.prototype.cssVarName=function(e){return"--".concat(this.namespace,"-").concat(e)},e.prototype.cssVarBlockName=function(e){return"--".concat(this.namespace,"-").concat(this.block,"-").concat(e)},e}()),e("HttpResponse",(function(e,t,n){this.local=!0,this.ok=!1,this.headers={},this.config={},this.data=e,this.status=t||200,this.statusText=n||"",this.status>=200&&this.status<300&&(this.ok=!0)}));var k=e("Net",function(){function e(e){this._prefix="",e&&(this._prefix=e)}return Object.defineProperty(e.prototype,"prefix",{get:function(){return this._prefix||ibiz.env.baseUrl},enumerable:!1,configurable:!0}),e.prototype.post=function(e,n,o,r){return void 0===o&&(o={}),void 0===r&&(r={}),y(this,void 0,void 0,(function(){var i,s;return v(this,(function(a){switch(a.label){case 0:e=this.handleAppPresetParam(e,o),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,t({method:"post",url:e,data:n,headers:d({"Content-Type":"application/json;charset=UTF-8",Accept:"application/json"},r)})];case 2:return i=a.sent(),[2,this.doResponseResult(i)];case 3:throw s=a.sent(),new h(s);case 4:return[2]}}))}))},e.prototype.get=function(e,n,o,r){return void 0===n&&(n={}),void 0===o&&(o={}),void 0===r&&(r={}),y(this,void 0,void 0,(function(){var i,s;return v(this,(function(a){switch(a.label){case 0:e=this.attachUrlParam(e,n),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,t.get(e,d({headers:o},r))];case 2:return i=a.sent(),[2,this.doResponseResult(i)];case 3:throw s=a.sent(),new h(s);case 4:return[2]}}))}))},e.prototype.delete=function(e,n,o){return void 0===o&&(o={}),y(this,void 0,void 0,(function(){var r,i;return v(this,(function(s){switch(s.label){case 0:e=this.handleAppPresetParam(e,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,t.delete(e,{headers:o})];case 2:return r=s.sent(),[2,this.doResponseResult(r)];case 3:throw i=s.sent(),new h(i);case 4:return[2]}}))}))},e.prototype.put=function(e,n,o,r){return void 0===o&&(o={}),void 0===r&&(r={}),y(this,void 0,void 0,(function(){var i,s;return v(this,(function(a){switch(a.label){case 0:e=this.handleAppPresetParam(e,o),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,t.put(e,n,{headers:r})];case 2:return i=a.sent(),[2,this.doResponseResult(i)];case 3:throw s=a.sent(),new h(s);case 4:return[2]}}))}))},e.prototype.getModel=function(e,n){return void 0===n&&(n={}),y(this,void 0,void 0,(function(){var o,r;return v(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,t.get(e,{headers:n})];case 1:return o=i.sent(),[2,this.doResponseResult(o)];case 2:throw r=i.sent(),new h(r);case 3:return[2]}}))}))},e.prototype.doResponseResult=function(e){var t=e;return t.status>=200&&t.status<=299&&(t.ok=!0),t},e.prototype.handleAppPresetParam=function(e,t){if(t){var n=Object.keys(t),o={};return n.forEach((function(e){e.startsWith("srf")&&r(t[e])&&(o[e]=t[e])})),this.attachUrlParam(e,t)}return e},e.prototype.attachUrlParam=function(e,t){e=this.attachUrl(e);var n=i(t);return r(n)&&(e=e.endsWith("?")||-1!==e.indexOf("?")&&e.endsWith("&")?"".concat(e).concat(n):-1===e.indexOf("?")||e.endsWith("&")?"".concat(e,"?").concat(n):"".concat(e,"&").concat(n)),e},e.prototype.attachUrl=function(e){return"".concat(this.prefix).concat(e)},e}());function P(e){return s(e)}e("UrlHelper",function(){function e(){}return Object.defineProperty(e,"routeBase",{get:function(){return"".concat(this.appBase,"/#")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"appBase",{get:function(){var e=window.location,t=e.origin,n=e.pathname;return"".concat(t).concat(n).replace(/\/$/,"")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"routePath",{get:function(){return window.location.hash.replace("#","")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"fullPath",{get:function(){return window.location.href},enumerable:!1,configurable:!0}),e}());var A=e("IBizSys",(function(){this.env=p,this.log=T,this.net=new k})),C=e("FactoryCenter",(function(){}))}}}));
|
|
1
|
+
System.register(["lodash-es","qx-util","axios","qs","pluralize"],(function(e){"use strict";var t,n,o,r,i,s,c;return{setters:[function(e){t=e.debounce,n=e.merge},function(e){o=e.getCookie,r=e.notNilEmpty},function(e){i=e.default},function(e){s=e.stringify},function(e){c=e.default}],execute:function(){function a(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}e({debounceAndMerge:function(e,n,o,r){var i,s=t((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return i=void 0,e.apply(void 0,b([],w(t),!1))}),o,r);return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var o=e;return i&&(o=n(i,o)),i=o,s.apply(void 0,b([],w(o),!1))}},getToken:m,install:function(){if(window.ibiz)throw new Error("ibiz 已经存在, 无需重复安装");window.ibiz=new A,window.___fc=new S,ibiz.net.addInterceptor("CoreInterceptor",new O)},isOverlap:function(e,t){return Array.from(new Set(b(b([],w(e),!1),w(t),!1))).length!==e.length+t.length},plural:j,pluralLower:function(e){return j(e).toLowerCase()}});var u,l,p=e("CoreConst",function(){function e(){}return e.DEFAULT_MODEL_SERVICE_TAG="default",e.TOKEN="access_token",e}()),f=e("HttpStatusMessageConst",{200:"服务器成功返回请求的数据。",201:"新建或修改数据成功。",202:"一个请求已经进入后台排队(异步任务)。",204:"删除数据成功。",400:"发出的请求有错误,服务器没有进行新建或修改数据的操作。",401:"用户没有权限(令牌、用户名、密码错误)。",403:"用户得到授权,但是访问是被禁止的。",404:"发出的请求针对的是不存在的记录,服务器没有进行操作。",406:"请求的格式不可得。",410:"请求的资源被永久删除,且不会再得到的。",422:"当创建一个对象时,发生一个验证错误。",500:"服务器发生错误,请检查服务器。",502:"网关错误。",503:"服务不可用,服务器暂时过载或维护。",504:"网关超时。"});e("LoginMode",u),function(e){e.DEFAULT="DEFAULT",e.CUSTOM="CUSTOM",e.CAS="CAS"}(u||e("LoginMode",u={})),e("MenuPermissionMode",l),function(e){e.MIXIN="MIXIN",e.RESOURCE="RESOURCE",e.RT="RT"}(l||e("MenuPermissionMode",l={}));e("IBizContext",(function(e,t){if(void 0===e&&(e={}),t){var n=this;Object.defineProperty(this,"_context",{enumerable:!1,value:{}});var o={};Object.keys(t).forEach((function(e){o[e]={enumerable:!0,set:function(t){n._context[e]=null==t?null:t},get:function(){return void 0!==n._context[e]?n._context[e]:t[e]}}})),Object.defineProperties(this,o)}Object.assign(this,e)}));var h=e("Environment",{dev:!1,logLevel:"ERROR",jsCdn:"https://cdn.jsdelivr.net",baseUrl:"",pluginBaseUrl:"./plugins",remoteModelUrl:"/remotemodel",assetsUrl:"./assets",dcSystem:"",ExportFile:"/ibizutil/download",UploadFile:"/ibizutil/upload",casLoginUrl:"",loginMode:u.DEFAULT,menuPermissionMode:l.MIXIN,enablePermission:!0}),d=e("HttpError",(function(e){this.name="HttpError";var t=e.response;this.response=e.response,t?(t.data?this.message=t.data.message:this.message=t.statusText,this.message||(this.message=f[t.status]),this.message||(this.message="网络异常,请稍后重试!"),this.status=t.status):(this.message=e.message,this.status=500)})),y=(e("RuntimeError",(function(e){this.message=e,this.name="Runtime Error"})),function(e,t){return y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},y(e,t)});function v(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function c(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((o=o.apply(e,t||[])).next())}))}function g(e,t){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function w(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s}function b(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}function m(){return o(p.TOKEN)}var R,E,T,C=e("Interceptor",function(){function e(){}return e.prototype.onBeforeRequest=function(e){return v(this,void 0,void 0,(function(){return g(this,(function(t){return[2,e]}))}))},e.prototype.onRequestError=function(e){return console.log(e),Promise.reject(e)},e.prototype.onResponseSuccess=function(e){return v(this,void 0,void 0,(function(){return g(this,(function(t){return[2,e]}))}))},e.prototype.onResponseError=function(e){return console.log(e),Promise.reject(e)},e.prototype.use=function(e){this.requestTag=e.interceptors.request.use(this.onBeforeRequest,this.onRequestError),this.responseTag=e.interceptors.response.use(this.onResponseSuccess,this.onResponseError)},e.prototype.eject=function(e){this.requestTag&&e.interceptors.request.eject(this.requestTag),this.responseTag&&e.interceptors.response.eject(this.responseTag)},e}()),O=e("CoreInterceptor",function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}y(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t.prototype.onBeforeRequest=function(t){return v(this,void 0,void 0,(function(){var n;return g(this,(function(o){switch(o.label){case 0:return[4,e.prototype.onBeforeRequest.call(this,t)];case 1:return o.sent(),t.headers||(t.headers={}),t.headers.Authorization="Bearer ".concat(m()),(n=ibiz.orgData)&&(n.systemid&&(t.headers.srfsystemid=n.systemid),n.orgid&&(t.headers.srforgid=n.orgid)),[2,t]}}))}))},t}(C)),L="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},P={exports:{}};E=L,T=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function r(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function i(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(o){return"debug"===o&&(o="log"),typeof console!==t&&("trace"===o&&n?i:void 0!==console[o]?r(console,o):void 0!==console.log?r(console,"log"):e)}function c(t,n){for(var r=0;r<o.length;r++){var i=o[r];this[i]=r<t?e:this.methodFactory(i,t,n)}this.log=this.debug}function a(e,n,o){return function(){typeof console!==t&&(c.call(this,n,o),this[e].apply(this,arguments))}}function u(e,t,n){return s(e)||a.apply(this,arguments)}function l(e,n,r){var i,s=this;n=null==n?"WARN":n;var a="loglevel";function l(){var e;if(typeof window!==t&&a){try{e=window.localStorage[a]}catch(e){}if(typeof e===t)try{var n=window.document.cookie,o=n.indexOf(encodeURIComponent(a)+"=");-1!==o&&(e=/^([^;]+)/.exec(n.slice(o))[1])}catch(e){}return void 0===s.levels[e]&&(e=void 0),e}}"string"==typeof e?a+=":"+e:"symbol"==typeof e&&(a=void 0),s.name=e,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=r||u,s.getLevel=function(){return i},s.setLevel=function(n,r){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(i=n,!1!==r&&function(e){var n=(o[e]||"silent").toUpperCase();if(typeof window!==t&&a){try{return void(window.localStorage[a]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(a)+"="+n+";"}catch(e){}}}(n),c.call(s,n,e),typeof console===t&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(e){n=e,l()||s.setLevel(e,!1)},s.resetLevel=function(){s.setLevel(n,!1),function(){if(typeof window!==t&&a){try{return void window.localStorage.removeItem(a)}catch(e){}try{window.document.cookie=encodeURIComponent(a)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}()},s.enableAll=function(e){s.setLevel(s.levels.TRACE,e)},s.disableAll=function(e){s.setLevel(s.levels.SILENT,e)};var p=l();null==p&&(p=n),s.setLevel(p,!1)}var p=new l,f={};p.getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=f[e];return t||(t=f[e]=new l(e,p.getLevel(),p.methodFactory)),t};var h=typeof window!==t?window.log:void 0;return p.noConflict=function(){return typeof window!==t&&window.log===p&&(window.log=h),p},p.getLoggers=function(){return f},p.default=p,p},(R=P).exports?R.exports=T():E.log=T();var U=a({__proto__:null,default:P.exports},[P.exports]);e("Logger",U);function k(e,t,n,o,r){var i="".concat(e,"-").concat(t);return n&&(i+="-".concat(n)),o&&(i+="__".concat(o)),r&&(i+="--".concat(r)),i}e("Namespace",function(){function e(e,t){this.block=e,this.namespace=t||"ibiz"}return e.prototype.b=function(e){return void 0===e&&(e=""),k(this.namespace,this.block,e,"","")},e.prototype.e=function(e){return e?k(this.namespace,this.block,"",e,""):""},e.prototype.m=function(e){return e?k(this.namespace,this.block,"","",e):""},e.prototype.be=function(e,t){return e&&t?k(this.namespace,this.block,e,t,""):""},e.prototype.em=function(e,t){return e&&t?k(this.namespace,this.block,"",e,t):""},e.prototype.bm=function(e,t){return e&&t?k(this.namespace,this.block,e,"",t):""},e.prototype.bem=function(e,t,n){return e&&t&&n?k(this.namespace,this.block,e,t,n):""},e.prototype.is=function(e,t){return e&&t?"".concat("is-").concat(e):""},e.prototype.cssVar=function(e){var t={};for(var n in e)e[n]&&(t[this.cssVarName(n)]=e[n]);return t},e.prototype.cssVarBlock=function(e){var t={};for(var n in e)e[n]&&(t[this.cssVarBlockName(n)]=e[n]);return t},e.prototype.cssVarName=function(e){return"--".concat(this.namespace,"-").concat(e)},e.prototype.cssVarBlockName=function(e){return"--".concat(this.namespace,"-").concat(this.block,"-").concat(e)},e}()),e("HttpResponse",(function(e,t,n){this.local=!0,this.ok=!1,this.headers={},this.config={},this.data=e,this.status=t||200,this.statusText=n||"",this.status>=200&&this.status<300&&(this.ok=!0)}));var x=e("Net",function(){function e(e){this.interceptors=new Map,this.instance=i.create(e)}return e.prototype.addInterceptor=function(e,t){t.use(this.instance),this.interceptors.set(e,t)},e.prototype.removeInterceptor=function(e){var t=this.interceptors.get(e);t&&(t.eject(this.instance),this.interceptors.delete(e))},Object.defineProperty(e.prototype,"presetConfig",{get:function(){return{baseURL:this.instance.defaults.baseURL||ibiz.env.baseUrl,headers:{"Content-Type":"application/json;charset=UTF-8",Accept:"application/json"}}},enumerable:!1,configurable:!0}),e.prototype.mergeConfig=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 0===e.length?this.presetConfig:n.apply(void 0,b([this.presetConfig],w(e),!1))},e.prototype.post=function(e,t,n,o){return void 0===n&&(n={}),void 0===o&&(o={}),v(this,void 0,void 0,(function(){var r,i;return g(this,(function(s){switch(s.label){case 0:e=this.handleAppPresetParam(e,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request(e,{method:"post",data:t,headers:o})];case 2:return r=s.sent(),[2,this.doResponseResult(r)];case 3:throw i=s.sent(),new d(i);case 4:return[2]}}))}))},e.prototype.get=function(e,t,o,r){return void 0===t&&(t={}),void 0===o&&(o={}),void 0===r&&(r={}),v(this,void 0,void 0,(function(){var i,s;return g(this,(function(c){switch(c.label){case 0:e=this.attachUrlParam(e,t),c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.request(e,n({method:"get",headers:o},r))];case 2:return i=c.sent(),[2,this.doResponseResult(i)];case 3:throw s=c.sent(),new d(s);case 4:return[2]}}))}))},e.prototype.delete=function(e,t,n){return void 0===n&&(n={}),v(this,void 0,void 0,(function(){var o,r;return g(this,(function(i){switch(i.label){case 0:e=this.handleAppPresetParam(e,t),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.request(e,{method:"delete",headers:n})];case 2:return o=i.sent(),[2,this.doResponseResult(o)];case 3:throw r=i.sent(),new d(r);case 4:return[2]}}))}))},e.prototype.put=function(e,t,n,o){return void 0===n&&(n={}),void 0===o&&(o={}),v(this,void 0,void 0,(function(){var r,i;return g(this,(function(s){switch(s.label){case 0:e=this.handleAppPresetParam(e,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request(e,{method:"put",data:t,headers:o})];case 2:return r=s.sent(),[2,this.doResponseResult(r)];case 3:throw i=s.sent(),new d(i);case 4:return[2]}}))}))},e.prototype.getModel=function(e,t){return void 0===t&&(t={}),v(this,void 0,void 0,(function(){var n,o;return g(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.instance.get(e,{headers:t})];case 1:return n=r.sent(),[2,this.doResponseResult(n)];case 2:throw o=r.sent(),new d(o);case 3:return[2]}}))}))},e.prototype.request=function(e,t){return void 0===t&&(t={}),v(this,void 0,void 0,(function(){var n,o;return g(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.instance.request(this.mergeConfig({url:e},t))];case 1:return n=r.sent(),[2,this.doResponseResult(n)];case 2:throw o=r.sent(),new d(o);case 3:return[2]}}))}))},e.prototype.doResponseResult=function(e){var t=e;return t.status>=200&&t.status<=299&&(t.ok=!0),t},e.prototype.handleAppPresetParam=function(e,t){if(t){var n=Object.keys(t),o={};return n.forEach((function(e){e.startsWith("srf")&&r(t[e])&&(o[e]=t[e])})),this.attachUrlParam(e,t)}return e},e.prototype.attachUrlParam=function(e,t){var n=s(t);return r(n)&&(e=e.endsWith("?")||-1!==e.indexOf("?")&&e.endsWith("&")?"".concat(e).concat(n):-1===e.indexOf("?")||e.endsWith("&")?"".concat(e,"?").concat(n):"".concat(e,"&").concat(n)),e},e}());function j(e){return c(e)}e("UrlHelper",function(){function e(){}return Object.defineProperty(e,"routeBase",{get:function(){return"".concat(this.appBase,"/#")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"appBase",{get:function(){var e=window.location,t=e.origin,n=e.pathname;return"".concat(t).concat(n).replace(/\/$/,"")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"routePath",{get:function(){return window.location.hash.replace("#","")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"fullPath",{get:function(){return window.location.href},enumerable:!1,configurable:!0}),e}());var A=e("IBizSys",(function(){this.env=h,this.log=U,this.net=new x})),S=e("FactoryCenter",(function(){}))}}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/environment/environment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/environment/environment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,YAezB,CAAC"}
|
package/out/install.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FactoryCenter } from './factory-center';
|
|
2
2
|
import { IBizSys } from './ibizsys';
|
|
3
|
-
import {
|
|
3
|
+
import { CoreInterceptor } from './utils';
|
|
4
4
|
/**
|
|
5
5
|
* 初始化全局对象
|
|
6
6
|
*
|
|
@@ -14,5 +14,5 @@ export function install() {
|
|
|
14
14
|
}
|
|
15
15
|
window.ibiz = new IBizSys();
|
|
16
16
|
window.___fc = new FactoryCenter();
|
|
17
|
-
new
|
|
17
|
+
ibiz.net.addInterceptor('CoreInterceptor', new CoreInterceptor());
|
|
18
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i-environment.d.ts","sourceRoot":"","sources":["../../../src/interface/i-environment/i-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;OAOG;IACH,GAAG,EAAE,OAAO,CAAC;IAEb;;;;;;OAMG;IACH,QAAQ,EAAE,YAAY,CAAC;IAEvB;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;;;;;OAMG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAE1B;;;;;;OAMG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC"}
|
|
1
|
+
{"version":3,"file":"i-environment.d.ts","sourceRoot":"","sources":["../../../src/interface/i-environment/i-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;OAOG;IACH,GAAG,EAAE,OAAO,CAAC;IAEb;;;;;;OAMG;IACH,QAAQ,EAAE,YAAY,CAAC;IAEvB;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;;OAMG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;;;;;OAMG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAE1B;;;;;;OAMG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC"}
|
package/out/utils/index.d.ts
CHANGED
package/out/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC"}
|
package/out/utils/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Interceptor } from './interceptor';
|
|
3
|
+
/**
|
|
4
|
+
* 核心包拦截器
|
|
5
|
+
*
|
|
6
|
+
* @author lxm
|
|
7
|
+
* @date 2022-10-27 17:10:48
|
|
8
|
+
* @export
|
|
9
|
+
* @class CoreInterceptor
|
|
10
|
+
* @extends {Interceptor}
|
|
11
|
+
*/
|
|
12
|
+
export declare class CoreInterceptor extends Interceptor {
|
|
13
|
+
protected onBeforeRequest(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=core-interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/core-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,WAAW;cAC9B,eAAe,CAC7B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC;CAkB/B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getToken } from '../util/util';
|
|
2
|
+
import { Interceptor } from './interceptor';
|
|
3
|
+
/**
|
|
4
|
+
* 核心包拦截器
|
|
5
|
+
*
|
|
6
|
+
* @author lxm
|
|
7
|
+
* @date 2022-10-27 17:10:48
|
|
8
|
+
* @export
|
|
9
|
+
* @class CoreInterceptor
|
|
10
|
+
* @extends {Interceptor}
|
|
11
|
+
*/
|
|
12
|
+
export class CoreInterceptor extends Interceptor {
|
|
13
|
+
async onBeforeRequest(config) {
|
|
14
|
+
await super.onBeforeRequest(config);
|
|
15
|
+
if (!config.headers) {
|
|
16
|
+
config.headers = {};
|
|
17
|
+
}
|
|
18
|
+
config.headers.Authorization = `Bearer ${getToken()}`;
|
|
19
|
+
const { orgData } = ibiz;
|
|
20
|
+
if (orgData) {
|
|
21
|
+
if (orgData.systemid) {
|
|
22
|
+
config.headers.srfsystemid = orgData.systemid;
|
|
23
|
+
}
|
|
24
|
+
if (orgData.orgid) {
|
|
25
|
+
config.headers.srforgid = orgData.orgid;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* 拦截器基类
|
|
3
4
|
*
|
|
4
5
|
* @author chitanda
|
|
5
6
|
* @date 2022-07-20 18:07:11
|
|
@@ -7,7 +8,77 @@
|
|
|
7
8
|
* @class Interceptor
|
|
8
9
|
*/
|
|
9
10
|
export declare class Interceptor {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* 请求拦截器绑定标识
|
|
13
|
+
*
|
|
14
|
+
* @author lxm
|
|
15
|
+
* @date 2022-10-27 17:10:20
|
|
16
|
+
* @private
|
|
17
|
+
* @type {number}
|
|
18
|
+
*/
|
|
19
|
+
private requestTag?;
|
|
20
|
+
/**
|
|
21
|
+
* 响应拦截器绑定标识
|
|
22
|
+
*
|
|
23
|
+
* @author lxm
|
|
24
|
+
* @date 2022-10-27 17:10:19
|
|
25
|
+
* @private
|
|
26
|
+
* @type {number}
|
|
27
|
+
*/
|
|
28
|
+
private responseTag?;
|
|
29
|
+
/**
|
|
30
|
+
* 请求之前处理
|
|
31
|
+
*
|
|
32
|
+
* @author lxm
|
|
33
|
+
* @date 2022-10-27 17:10:41
|
|
34
|
+
* @protected
|
|
35
|
+
* @param {AxiosRequestConfig} config
|
|
36
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
37
|
+
*/
|
|
38
|
+
protected onBeforeRequest(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
|
|
39
|
+
/**
|
|
40
|
+
* 请求失败之后处理
|
|
41
|
+
*
|
|
42
|
+
* @author lxm
|
|
43
|
+
* @date 2022-10-27 17:10:40
|
|
44
|
+
* @protected
|
|
45
|
+
* @param {*} error
|
|
46
|
+
*/
|
|
47
|
+
protected onRequestError(error: any): Promise<never>;
|
|
48
|
+
/**
|
|
49
|
+
* 响应成功之后处理
|
|
50
|
+
*
|
|
51
|
+
* @author lxm
|
|
52
|
+
* @date 2022-10-27 17:10:38
|
|
53
|
+
* @protected
|
|
54
|
+
* @param {AxiosResponse} config
|
|
55
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
56
|
+
*/
|
|
57
|
+
protected onResponseSuccess(config: AxiosResponse): Promise<AxiosResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* 响应失败之后处理
|
|
60
|
+
*
|
|
61
|
+
* @author lxm
|
|
62
|
+
* @date 2022-10-27 17:10:37
|
|
63
|
+
* @protected
|
|
64
|
+
* @param {*} _error
|
|
65
|
+
*/
|
|
66
|
+
protected onResponseError(error: any): Promise<never>;
|
|
67
|
+
/**
|
|
68
|
+
* 使用拦截器
|
|
69
|
+
*
|
|
70
|
+
* @author lxm
|
|
71
|
+
* @date 2022-10-27 17:10:28
|
|
72
|
+
* @param {AxiosInstance} instance
|
|
73
|
+
*/
|
|
74
|
+
use(instance: AxiosInstance): void;
|
|
75
|
+
/**
|
|
76
|
+
* 移出拦截器
|
|
77
|
+
*
|
|
78
|
+
* @author lxm
|
|
79
|
+
* @date 2022-10-27 17:10:27
|
|
80
|
+
* @param {AxiosInstance} instance
|
|
81
|
+
*/
|
|
82
|
+
eject(instance: AxiosInstance): void;
|
|
12
83
|
}
|
|
13
84
|
//# sourceMappingURL=interceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/interceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/interceptor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEzE;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW,CAAC,CAAS;IAE7B;;;;;;;;OAQG;cACa,eAAe,CAC7B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC;IAI9B;;;;;;;OAOG;IACH,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG;IAMnC;;;;;;;;OAQG;cACa,iBAAiB,CAC/B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG;IAMpC;;;;;;OAMG;IACH,GAAG,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAWlC;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,EAAE,aAAa;CAQ9B"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { getToken } from '../util/util';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* 拦截器基类
|
|
5
3
|
*
|
|
6
4
|
* @author chitanda
|
|
7
5
|
* @date 2022-07-20 18:07:11
|
|
@@ -9,25 +7,80 @@ import { getToken } from '../util/util';
|
|
|
9
7
|
* @class Interceptor
|
|
10
8
|
*/
|
|
11
9
|
export class Interceptor {
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 请求之前处理
|
|
12
|
+
*
|
|
13
|
+
* @author lxm
|
|
14
|
+
* @date 2022-10-27 17:10:41
|
|
15
|
+
* @protected
|
|
16
|
+
* @param {AxiosRequestConfig} config
|
|
17
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
18
|
+
*/
|
|
19
|
+
async onBeforeRequest(config) {
|
|
20
|
+
return config;
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
/**
|
|
23
|
+
* 请求失败之后处理
|
|
24
|
+
*
|
|
25
|
+
* @author lxm
|
|
26
|
+
* @date 2022-10-27 17:10:40
|
|
27
|
+
* @protected
|
|
28
|
+
* @param {*} error
|
|
29
|
+
*/
|
|
30
|
+
onRequestError(error) {
|
|
31
|
+
// 处理请求错误
|
|
32
|
+
console.log(error);
|
|
33
|
+
return Promise.reject(error);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 响应成功之后处理
|
|
37
|
+
*
|
|
38
|
+
* @author lxm
|
|
39
|
+
* @date 2022-10-27 17:10:38
|
|
40
|
+
* @protected
|
|
41
|
+
* @param {AxiosResponse} config
|
|
42
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
43
|
+
*/
|
|
44
|
+
async onResponseSuccess(config) {
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 响应失败之后处理
|
|
49
|
+
*
|
|
50
|
+
* @author lxm
|
|
51
|
+
* @date 2022-10-27 17:10:37
|
|
52
|
+
* @protected
|
|
53
|
+
* @param {*} _error
|
|
54
|
+
*/
|
|
55
|
+
onResponseError(error) {
|
|
56
|
+
// 处理响应错误
|
|
57
|
+
console.log(error);
|
|
58
|
+
return Promise.reject(error);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 使用拦截器
|
|
62
|
+
*
|
|
63
|
+
* @author lxm
|
|
64
|
+
* @date 2022-10-27 17:10:28
|
|
65
|
+
* @param {AxiosInstance} instance
|
|
66
|
+
*/
|
|
67
|
+
use(instance) {
|
|
68
|
+
this.requestTag = instance.interceptors.request.use(this.onBeforeRequest, this.onRequestError);
|
|
69
|
+
this.responseTag = instance.interceptors.response.use(this.onResponseSuccess, this.onResponseError);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 移出拦截器
|
|
73
|
+
*
|
|
74
|
+
* @author lxm
|
|
75
|
+
* @date 2022-10-27 17:10:27
|
|
76
|
+
* @param {AxiosInstance} instance
|
|
77
|
+
*/
|
|
78
|
+
eject(instance) {
|
|
79
|
+
if (this.requestTag) {
|
|
80
|
+
instance.interceptors.request.eject(this.requestTag);
|
|
81
|
+
}
|
|
82
|
+
if (this.responseTag) {
|
|
83
|
+
instance.interceptors.response.eject(this.responseTag);
|
|
84
|
+
}
|
|
32
85
|
}
|
|
33
86
|
}
|
package/out/utils/net/net.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RawAxiosRequestHeaders } from 'axios';
|
|
1
|
+
import { RawAxiosRequestHeaders, AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
|
|
2
|
+
import { Interceptor } from '../interceptor/interceptor';
|
|
2
3
|
import { IHttpResponse } from './http-response';
|
|
3
4
|
/**
|
|
4
5
|
* 全局请求工具类
|
|
@@ -10,23 +11,66 @@ import { IHttpResponse } from './http-response';
|
|
|
10
11
|
*/
|
|
11
12
|
export declare class Net {
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
+
* axios实例
|
|
14
15
|
*
|
|
15
|
-
* @author
|
|
16
|
-
* @date 2022-
|
|
16
|
+
* @author lxm
|
|
17
|
+
* @date 2022-10-27 17:10:18
|
|
17
18
|
* @protected
|
|
18
|
-
* @type {
|
|
19
|
+
* @type {AxiosInstance}
|
|
19
20
|
*/
|
|
20
|
-
protected
|
|
21
|
-
get prefix(): string;
|
|
21
|
+
protected instance: AxiosInstance;
|
|
22
22
|
/**
|
|
23
23
|
* Creates an instance of Net.
|
|
24
|
+
* @author lxm
|
|
25
|
+
* @date 2022-10-27 16:10:05
|
|
26
|
+
* @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
|
|
27
|
+
*/
|
|
28
|
+
constructor(config?: CreateAxiosDefaults);
|
|
29
|
+
/**
|
|
30
|
+
* 注册的拦截器
|
|
24
31
|
*
|
|
25
|
-
* @author
|
|
26
|
-
* @date 2022-
|
|
27
|
-
* @
|
|
32
|
+
* @author lxm
|
|
33
|
+
* @date 2022-10-27 17:10:18
|
|
34
|
+
* @type {Map<string, Interceptor>}
|
|
28
35
|
*/
|
|
29
|
-
|
|
36
|
+
interceptors: Map<string, Interceptor>;
|
|
37
|
+
/**
|
|
38
|
+
* 添加拦截器
|
|
39
|
+
*
|
|
40
|
+
* @author lxm
|
|
41
|
+
* @date 2022-10-27 17:10:42
|
|
42
|
+
* @param {string} name 唯一标识
|
|
43
|
+
* @param {Interceptor} interceptor 拦截器
|
|
44
|
+
*/
|
|
45
|
+
addInterceptor(name: string, interceptor: Interceptor): void;
|
|
46
|
+
/**
|
|
47
|
+
* 删除拦截器
|
|
48
|
+
*
|
|
49
|
+
* @author lxm
|
|
50
|
+
* @date 2022-10-27 17:10:27
|
|
51
|
+
* @param {string} name 唯一标识
|
|
52
|
+
*/
|
|
53
|
+
removeInterceptor(name: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* 预置config,绑定动态的配置
|
|
56
|
+
*
|
|
57
|
+
* @author lxm
|
|
58
|
+
* @date 2022-10-27 16:10:48
|
|
59
|
+
* @readonly
|
|
60
|
+
* @protected
|
|
61
|
+
* @type {AxiosRequestConfig}
|
|
62
|
+
*/
|
|
63
|
+
protected get presetConfig(): AxiosRequestConfig;
|
|
64
|
+
/**
|
|
65
|
+
* 从左到右递归合并配置参数(内置第一个合并的预置参数)
|
|
66
|
+
*
|
|
67
|
+
* @author lxm
|
|
68
|
+
* @date 2022-10-27 16:10:09
|
|
69
|
+
* @protected
|
|
70
|
+
* @param {...AxiosRequestConfig[]} configs
|
|
71
|
+
* @returns {*}
|
|
72
|
+
*/
|
|
73
|
+
protected mergeConfig(...configs: AxiosRequestConfig[]): any;
|
|
30
74
|
/**
|
|
31
75
|
* Post 请求
|
|
32
76
|
*
|
|
@@ -50,7 +94,7 @@ export declare class Net {
|
|
|
50
94
|
* @param {IParams} [option={}]
|
|
51
95
|
* @return {*} {Promise<IHttpResponse>}
|
|
52
96
|
*/
|
|
53
|
-
get(url: string, params?: IParams, headers?: RawAxiosRequestHeaders, option?:
|
|
97
|
+
get(url: string, params?: IParams, headers?: RawAxiosRequestHeaders, option?: AxiosRequestConfig): Promise<IHttpResponse>;
|
|
54
98
|
/**
|
|
55
99
|
* Delete 请求
|
|
56
100
|
*
|
|
@@ -84,6 +128,16 @@ export declare class Net {
|
|
|
84
128
|
* @return {*} {Promise<IHttpResponse>}
|
|
85
129
|
*/
|
|
86
130
|
getModel(url: string, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
|
|
131
|
+
/**
|
|
132
|
+
* 基础请求方法,会合并预置配置
|
|
133
|
+
*
|
|
134
|
+
* @author lxm
|
|
135
|
+
* @date 2022-10-27 14:10:06
|
|
136
|
+
* @param {string} url
|
|
137
|
+
* @param {AxiosRequestConfig} [config={}]
|
|
138
|
+
* @returns {*} {Promise<IHttpResponse>}
|
|
139
|
+
*/
|
|
140
|
+
request(url: string, config?: AxiosRequestConfig): Promise<IHttpResponse>;
|
|
87
141
|
/**
|
|
88
142
|
* 统一处理请求返回
|
|
89
143
|
*
|
|
@@ -116,15 +170,5 @@ export declare class Net {
|
|
|
116
170
|
* @return {*} {string}
|
|
117
171
|
*/
|
|
118
172
|
private attachUrlParam;
|
|
119
|
-
/**
|
|
120
|
-
* 处理 url 参数
|
|
121
|
-
*
|
|
122
|
-
* @author chitanda
|
|
123
|
-
* @date 2022-07-20 20:07:17
|
|
124
|
-
* @private
|
|
125
|
-
* @param {string} url
|
|
126
|
-
* @return {*} {string}
|
|
127
|
-
*/
|
|
128
|
-
private attachUrl;
|
|
129
173
|
}
|
|
130
174
|
//# sourceMappingURL=net.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAEZ,sBAAsB,
|
|
1
|
+
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAEZ,sBAAsB,EAEtB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACpB,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,GAAG;IACd;;;;;;;OAOG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC;IAElC;;;;;OAKG;gBACS,MAAM,CAAC,EAAE,mBAAmB;IAIxC;;;;;;OAMG;IACH,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAa;IAEnD;;;;;;;OAOG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW;IAKrD;;;;;;OAMG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM;IAQ9B;;;;;;;;OAQG;IACH,SAAS,KAAK,YAAY,IAAI,kBAAkB,CAS/C;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,WAAW,CAAC,GAAG,OAAO,EAAE,kBAAkB,EAAE;IAOtD;;;;;;;;;;OAUG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,EACpC,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IAiBzB;;;;;;;;;OASG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;OAQG;IACG,OAAO,CACX,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;CAevB"}
|
package/out/utils/net/net.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
2
3
|
import { stringify } from 'qs';
|
|
3
4
|
import { notNilEmpty } from 'qx-util';
|
|
4
5
|
import { HttpError } from '../../error';
|
|
@@ -13,27 +14,80 @@ import { HttpError } from '../../error';
|
|
|
13
14
|
export class Net {
|
|
14
15
|
/**
|
|
15
16
|
* Creates an instance of Net.
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
19
|
-
* @param {string} [prefix] 请求前缀
|
|
17
|
+
* @author lxm
|
|
18
|
+
* @date 2022-10-27 16:10:05
|
|
19
|
+
* @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
|
|
20
20
|
*/
|
|
21
|
-
constructor(
|
|
21
|
+
constructor(config) {
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* 注册的拦截器
|
|
24
24
|
*
|
|
25
|
-
* @author
|
|
26
|
-
* @date 2022-
|
|
27
|
-
* @
|
|
28
|
-
* @type {string}
|
|
25
|
+
* @author lxm
|
|
26
|
+
* @date 2022-10-27 17:10:18
|
|
27
|
+
* @type {Map<string, Interceptor>}
|
|
29
28
|
*/
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
this.interceptors = new Map();
|
|
30
|
+
this.instance = axios.create(config);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 添加拦截器
|
|
34
|
+
*
|
|
35
|
+
* @author lxm
|
|
36
|
+
* @date 2022-10-27 17:10:42
|
|
37
|
+
* @param {string} name 唯一标识
|
|
38
|
+
* @param {Interceptor} interceptor 拦截器
|
|
39
|
+
*/
|
|
40
|
+
addInterceptor(name, interceptor) {
|
|
41
|
+
interceptor.use(this.instance);
|
|
42
|
+
this.interceptors.set(name, interceptor);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 删除拦截器
|
|
46
|
+
*
|
|
47
|
+
* @author lxm
|
|
48
|
+
* @date 2022-10-27 17:10:27
|
|
49
|
+
* @param {string} name 唯一标识
|
|
50
|
+
*/
|
|
51
|
+
removeInterceptor(name) {
|
|
52
|
+
const interceptor = this.interceptors.get(name);
|
|
53
|
+
if (interceptor) {
|
|
54
|
+
interceptor.eject(this.instance);
|
|
55
|
+
this.interceptors.delete(name);
|
|
33
56
|
}
|
|
34
57
|
}
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
/**
|
|
59
|
+
* 预置config,绑定动态的配置
|
|
60
|
+
*
|
|
61
|
+
* @author lxm
|
|
62
|
+
* @date 2022-10-27 16:10:48
|
|
63
|
+
* @readonly
|
|
64
|
+
* @protected
|
|
65
|
+
* @type {AxiosRequestConfig}
|
|
66
|
+
*/
|
|
67
|
+
get presetConfig() {
|
|
68
|
+
return {
|
|
69
|
+
// 请求前缀路径
|
|
70
|
+
baseURL: this.instance.defaults.baseURL || ibiz.env.baseUrl,
|
|
71
|
+
headers: {
|
|
72
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
73
|
+
Accept: 'application/json',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 从左到右递归合并配置参数(内置第一个合并的预置参数)
|
|
79
|
+
*
|
|
80
|
+
* @author lxm
|
|
81
|
+
* @date 2022-10-27 16:10:09
|
|
82
|
+
* @protected
|
|
83
|
+
* @param {...AxiosRequestConfig[]} configs
|
|
84
|
+
* @returns {*}
|
|
85
|
+
*/
|
|
86
|
+
mergeConfig(...configs) {
|
|
87
|
+
if (configs.length === 0) {
|
|
88
|
+
return this.presetConfig;
|
|
89
|
+
}
|
|
90
|
+
return merge(this.presetConfig, ...configs);
|
|
37
91
|
}
|
|
38
92
|
/**
|
|
39
93
|
* Post 请求
|
|
@@ -49,11 +103,10 @@ export class Net {
|
|
|
49
103
|
async post(url, data, params = {}, headers = {}) {
|
|
50
104
|
url = this.handleAppPresetParam(url, params);
|
|
51
105
|
try {
|
|
52
|
-
const response = await
|
|
106
|
+
const response = await this.request(url, {
|
|
53
107
|
method: 'post',
|
|
54
|
-
url,
|
|
55
108
|
data,
|
|
56
|
-
headers
|
|
109
|
+
headers,
|
|
57
110
|
});
|
|
58
111
|
return this.doResponseResult(response);
|
|
59
112
|
}
|
|
@@ -79,7 +132,7 @@ export class Net {
|
|
|
79
132
|
// }
|
|
80
133
|
url = this.attachUrlParam(url, params);
|
|
81
134
|
try {
|
|
82
|
-
const response = await
|
|
135
|
+
const response = await this.request(url, merge({ method: 'get', headers }, option));
|
|
83
136
|
return this.doResponseResult(response);
|
|
84
137
|
}
|
|
85
138
|
catch (error) {
|
|
@@ -99,7 +152,7 @@ export class Net {
|
|
|
99
152
|
async delete(url, params, headers = {}) {
|
|
100
153
|
url = this.handleAppPresetParam(url, params);
|
|
101
154
|
try {
|
|
102
|
-
const response = await
|
|
155
|
+
const response = await this.request(url, { method: 'delete', headers });
|
|
103
156
|
return this.doResponseResult(response);
|
|
104
157
|
}
|
|
105
158
|
catch (error) {
|
|
@@ -120,7 +173,11 @@ export class Net {
|
|
|
120
173
|
async put(url, data, params = {}, headers = {}) {
|
|
121
174
|
url = this.handleAppPresetParam(url, params);
|
|
122
175
|
try {
|
|
123
|
-
const response = await
|
|
176
|
+
const response = await this.request(url, {
|
|
177
|
+
method: 'put',
|
|
178
|
+
data,
|
|
179
|
+
headers,
|
|
180
|
+
});
|
|
124
181
|
return this.doResponseResult(response);
|
|
125
182
|
}
|
|
126
183
|
catch (error) {
|
|
@@ -138,7 +195,7 @@ export class Net {
|
|
|
138
195
|
*/
|
|
139
196
|
async getModel(url, headers = {}) {
|
|
140
197
|
try {
|
|
141
|
-
const response = await
|
|
198
|
+
const response = await this.instance.get(url, {
|
|
142
199
|
headers,
|
|
143
200
|
});
|
|
144
201
|
return this.doResponseResult(response);
|
|
@@ -147,6 +204,24 @@ export class Net {
|
|
|
147
204
|
throw new HttpError(error);
|
|
148
205
|
}
|
|
149
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* 基础请求方法,会合并预置配置
|
|
209
|
+
*
|
|
210
|
+
* @author lxm
|
|
211
|
+
* @date 2022-10-27 14:10:06
|
|
212
|
+
* @param {string} url
|
|
213
|
+
* @param {AxiosRequestConfig} [config={}]
|
|
214
|
+
* @returns {*} {Promise<IHttpResponse>}
|
|
215
|
+
*/
|
|
216
|
+
async request(url, config = {}) {
|
|
217
|
+
try {
|
|
218
|
+
const response = await this.instance.request(this.mergeConfig({ url }, config));
|
|
219
|
+
return this.doResponseResult(response);
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
throw new HttpError(error);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
150
225
|
/**
|
|
151
226
|
* 统一处理请求返回
|
|
152
227
|
*
|
|
@@ -197,7 +272,6 @@ export class Net {
|
|
|
197
272
|
* @return {*} {string}
|
|
198
273
|
*/
|
|
199
274
|
attachUrlParam(url, params) {
|
|
200
|
-
url = this.attachUrl(url);
|
|
201
275
|
const strParams = stringify(params);
|
|
202
276
|
if (notNilEmpty(strParams)) {
|
|
203
277
|
if (url.endsWith('?')) {
|
|
@@ -215,16 +289,4 @@ export class Net {
|
|
|
215
289
|
}
|
|
216
290
|
return url;
|
|
217
291
|
}
|
|
218
|
-
/**
|
|
219
|
-
* 处理 url 参数
|
|
220
|
-
*
|
|
221
|
-
* @author chitanda
|
|
222
|
-
* @date 2022-07-20 20:07:17
|
|
223
|
-
* @private
|
|
224
|
-
* @param {string} url
|
|
225
|
-
* @return {*} {string}
|
|
226
|
-
*/
|
|
227
|
-
attachUrl(url) {
|
|
228
|
-
return `${this.prefix}${url}`;
|
|
229
|
-
}
|
|
230
292
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibiz-template/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.37",
|
|
4
4
|
"description": "核心包",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "out/index.js",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"@types/pluralize": "^0.0.29",
|
|
39
39
|
"@types/qs": "^6.9.7",
|
|
40
40
|
"lodash-es": "^4.17.21",
|
|
41
|
-
"qx-util": "0.4.
|
|
41
|
+
"qx-util": "^0.4.4"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"lodash-es": "^4.17.21",
|
|
45
|
-
"qx-util": "^0.4.
|
|
45
|
+
"qx-util": "^0.4.4"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "5dc73da226eb8c5863add2ee60a25d0251a26ed3"
|
|
48
48
|
}
|
package/src/install.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FactoryCenter } from './factory-center';
|
|
2
2
|
import { IBizSys } from './ibizsys';
|
|
3
|
-
import {
|
|
3
|
+
import { CoreInterceptor } from './utils';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 初始化全局对象
|
|
@@ -15,5 +15,5 @@ export function install(): void {
|
|
|
15
15
|
}
|
|
16
16
|
window.ibiz = new IBizSys();
|
|
17
17
|
window.___fc = new FactoryCenter();
|
|
18
|
-
new
|
|
18
|
+
ibiz.net.addInterceptor('CoreInterceptor', new CoreInterceptor());
|
|
19
19
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { getToken } from '../util/util';
|
|
3
|
+
import { Interceptor } from './interceptor';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 核心包拦截器
|
|
7
|
+
*
|
|
8
|
+
* @author lxm
|
|
9
|
+
* @date 2022-10-27 17:10:48
|
|
10
|
+
* @export
|
|
11
|
+
* @class CoreInterceptor
|
|
12
|
+
* @extends {Interceptor}
|
|
13
|
+
*/
|
|
14
|
+
export class CoreInterceptor extends Interceptor {
|
|
15
|
+
protected async onBeforeRequest(
|
|
16
|
+
config: AxiosRequestConfig,
|
|
17
|
+
): Promise<AxiosRequestConfig> {
|
|
18
|
+
await super.onBeforeRequest(config);
|
|
19
|
+
|
|
20
|
+
if (!config.headers) {
|
|
21
|
+
config.headers = {};
|
|
22
|
+
}
|
|
23
|
+
config.headers.Authorization = `Bearer ${getToken()}`;
|
|
24
|
+
const { orgData } = ibiz;
|
|
25
|
+
if (orgData) {
|
|
26
|
+
if (orgData.systemid) {
|
|
27
|
+
config.headers.srfsystemid = orgData.systemid;
|
|
28
|
+
}
|
|
29
|
+
if (orgData.orgid) {
|
|
30
|
+
config.headers.srforgid = orgData.orgid;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return config;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 拦截器基类
|
|
6
6
|
*
|
|
7
7
|
* @author chitanda
|
|
8
8
|
* @date 2022-07-20 18:07:11
|
|
@@ -10,26 +10,115 @@ import { getToken } from '../util/util';
|
|
|
10
10
|
* @class Interceptor
|
|
11
11
|
*/
|
|
12
12
|
export class Interceptor {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* 请求拦截器绑定标识
|
|
15
|
+
*
|
|
16
|
+
* @author lxm
|
|
17
|
+
* @date 2022-10-27 17:10:20
|
|
18
|
+
* @private
|
|
19
|
+
* @type {number}
|
|
20
|
+
*/
|
|
21
|
+
private requestTag?: number;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 响应拦截器绑定标识
|
|
25
|
+
*
|
|
26
|
+
* @author lxm
|
|
27
|
+
* @date 2022-10-27 17:10:19
|
|
28
|
+
* @private
|
|
29
|
+
* @type {number}
|
|
30
|
+
*/
|
|
31
|
+
private responseTag?: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 请求之前处理
|
|
35
|
+
*
|
|
36
|
+
* @author lxm
|
|
37
|
+
* @date 2022-10-27 17:10:41
|
|
38
|
+
* @protected
|
|
39
|
+
* @param {AxiosRequestConfig} config
|
|
40
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
41
|
+
*/
|
|
42
|
+
protected async onBeforeRequest(
|
|
43
|
+
config: AxiosRequestConfig,
|
|
44
|
+
): Promise<AxiosRequestConfig> {
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 请求失败之后处理
|
|
50
|
+
*
|
|
51
|
+
* @author lxm
|
|
52
|
+
* @date 2022-10-27 17:10:40
|
|
53
|
+
* @protected
|
|
54
|
+
* @param {*} error
|
|
55
|
+
*/
|
|
56
|
+
protected onRequestError(error: any) {
|
|
57
|
+
// 处理请求错误
|
|
58
|
+
console.log(error);
|
|
59
|
+
return Promise.reject(error);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 响应成功之后处理
|
|
64
|
+
*
|
|
65
|
+
* @author lxm
|
|
66
|
+
* @date 2022-10-27 17:10:38
|
|
67
|
+
* @protected
|
|
68
|
+
* @param {AxiosResponse} config
|
|
69
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
70
|
+
*/
|
|
71
|
+
protected async onResponseSuccess(
|
|
72
|
+
config: AxiosResponse,
|
|
73
|
+
): Promise<AxiosResponse> {
|
|
74
|
+
return config;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 响应失败之后处理
|
|
79
|
+
*
|
|
80
|
+
* @author lxm
|
|
81
|
+
* @date 2022-10-27 17:10:37
|
|
82
|
+
* @protected
|
|
83
|
+
* @param {*} _error
|
|
84
|
+
*/
|
|
85
|
+
protected onResponseError(error: any) {
|
|
86
|
+
// 处理响应错误
|
|
87
|
+
console.log(error);
|
|
88
|
+
return Promise.reject(error);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 使用拦截器
|
|
93
|
+
*
|
|
94
|
+
* @author lxm
|
|
95
|
+
* @date 2022-10-27 17:10:28
|
|
96
|
+
* @param {AxiosInstance} instance
|
|
97
|
+
*/
|
|
98
|
+
use(instance: AxiosInstance): void {
|
|
99
|
+
this.requestTag = instance.interceptors.request.use(
|
|
100
|
+
this.onBeforeRequest,
|
|
101
|
+
this.onRequestError,
|
|
102
|
+
);
|
|
103
|
+
this.responseTag = instance.interceptors.response.use(
|
|
104
|
+
this.onResponseSuccess,
|
|
105
|
+
this.onResponseError,
|
|
106
|
+
);
|
|
15
107
|
}
|
|
16
108
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return config;
|
|
33
|
-
});
|
|
109
|
+
/**
|
|
110
|
+
* 移出拦截器
|
|
111
|
+
*
|
|
112
|
+
* @author lxm
|
|
113
|
+
* @date 2022-10-27 17:10:27
|
|
114
|
+
* @param {AxiosInstance} instance
|
|
115
|
+
*/
|
|
116
|
+
eject(instance: AxiosInstance) {
|
|
117
|
+
if (this.requestTag) {
|
|
118
|
+
instance.interceptors.request.eject(this.requestTag);
|
|
119
|
+
}
|
|
120
|
+
if (this.responseTag) {
|
|
121
|
+
instance.interceptors.response.eject(this.responseTag);
|
|
122
|
+
}
|
|
34
123
|
}
|
|
35
124
|
}
|
package/src/utils/net/net.ts
CHANGED
|
@@ -2,10 +2,15 @@ import axios, {
|
|
|
2
2
|
AxiosError,
|
|
3
3
|
RawAxiosRequestHeaders,
|
|
4
4
|
AxiosResponse,
|
|
5
|
+
AxiosRequestConfig,
|
|
6
|
+
AxiosInstance,
|
|
7
|
+
CreateAxiosDefaults,
|
|
5
8
|
} from 'axios';
|
|
9
|
+
import { merge } from 'lodash-es';
|
|
6
10
|
import { stringify } from 'qs';
|
|
7
11
|
import { notNilEmpty } from 'qx-util';
|
|
8
12
|
import { HttpError } from '../../error';
|
|
13
|
+
import { Interceptor } from '../interceptor/interceptor';
|
|
9
14
|
import { IHttpResponse } from './http-response';
|
|
10
15
|
|
|
11
16
|
/**
|
|
@@ -18,30 +23,96 @@ import { IHttpResponse } from './http-response';
|
|
|
18
23
|
*/
|
|
19
24
|
export class Net {
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
26
|
+
* axios实例
|
|
22
27
|
*
|
|
23
|
-
* @author
|
|
24
|
-
* @date 2022-
|
|
28
|
+
* @author lxm
|
|
29
|
+
* @date 2022-10-27 17:10:18
|
|
25
30
|
* @protected
|
|
26
|
-
* @type {
|
|
31
|
+
* @type {AxiosInstance}
|
|
27
32
|
*/
|
|
28
|
-
protected
|
|
33
|
+
protected instance: AxiosInstance;
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Creates an instance of Net.
|
|
37
|
+
* @author lxm
|
|
38
|
+
* @date 2022-10-27 16:10:05
|
|
39
|
+
* @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
|
|
40
|
+
*/
|
|
41
|
+
constructor(config?: CreateAxiosDefaults) {
|
|
42
|
+
this.instance = axios.create(config);
|
|
32
43
|
}
|
|
33
44
|
|
|
34
45
|
/**
|
|
35
|
-
*
|
|
46
|
+
* 注册的拦截器
|
|
36
47
|
*
|
|
37
|
-
* @author
|
|
38
|
-
* @date 2022-
|
|
39
|
-
* @
|
|
48
|
+
* @author lxm
|
|
49
|
+
* @date 2022-10-27 17:10:18
|
|
50
|
+
* @type {Map<string, Interceptor>}
|
|
51
|
+
*/
|
|
52
|
+
interceptors: Map<string, Interceptor> = new Map();
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 添加拦截器
|
|
56
|
+
*
|
|
57
|
+
* @author lxm
|
|
58
|
+
* @date 2022-10-27 17:10:42
|
|
59
|
+
* @param {string} name 唯一标识
|
|
60
|
+
* @param {Interceptor} interceptor 拦截器
|
|
61
|
+
*/
|
|
62
|
+
addInterceptor(name: string, interceptor: Interceptor) {
|
|
63
|
+
interceptor.use(this.instance);
|
|
64
|
+
this.interceptors.set(name, interceptor);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 删除拦截器
|
|
69
|
+
*
|
|
70
|
+
* @author lxm
|
|
71
|
+
* @date 2022-10-27 17:10:27
|
|
72
|
+
* @param {string} name 唯一标识
|
|
73
|
+
*/
|
|
74
|
+
removeInterceptor(name: string) {
|
|
75
|
+
const interceptor = this.interceptors.get(name);
|
|
76
|
+
if (interceptor) {
|
|
77
|
+
interceptor.eject(this.instance);
|
|
78
|
+
this.interceptors.delete(name);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 预置config,绑定动态的配置
|
|
84
|
+
*
|
|
85
|
+
* @author lxm
|
|
86
|
+
* @date 2022-10-27 16:10:48
|
|
87
|
+
* @readonly
|
|
88
|
+
* @protected
|
|
89
|
+
* @type {AxiosRequestConfig}
|
|
90
|
+
*/
|
|
91
|
+
protected get presetConfig(): AxiosRequestConfig {
|
|
92
|
+
return {
|
|
93
|
+
// 请求前缀路径
|
|
94
|
+
baseURL: this.instance.defaults.baseURL || ibiz.env.baseUrl,
|
|
95
|
+
headers: {
|
|
96
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
97
|
+
Accept: 'application/json',
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 从左到右递归合并配置参数(内置第一个合并的预置参数)
|
|
104
|
+
*
|
|
105
|
+
* @author lxm
|
|
106
|
+
* @date 2022-10-27 16:10:09
|
|
107
|
+
* @protected
|
|
108
|
+
* @param {...AxiosRequestConfig[]} configs
|
|
109
|
+
* @returns {*}
|
|
40
110
|
*/
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
this.
|
|
111
|
+
protected mergeConfig(...configs: AxiosRequestConfig[]) {
|
|
112
|
+
if (configs.length === 0) {
|
|
113
|
+
return this.presetConfig;
|
|
44
114
|
}
|
|
115
|
+
return merge(this.presetConfig, ...configs);
|
|
45
116
|
}
|
|
46
117
|
|
|
47
118
|
/**
|
|
@@ -63,15 +134,10 @@ export class Net {
|
|
|
63
134
|
): Promise<IHttpResponse> {
|
|
64
135
|
url = this.handleAppPresetParam(url, params);
|
|
65
136
|
try {
|
|
66
|
-
const response = await
|
|
137
|
+
const response = await this.request(url, {
|
|
67
138
|
method: 'post',
|
|
68
|
-
url,
|
|
69
139
|
data,
|
|
70
|
-
headers
|
|
71
|
-
'Content-Type': 'application/json;charset=UTF-8',
|
|
72
|
-
Accept: 'application/json',
|
|
73
|
-
...headers,
|
|
74
|
-
},
|
|
140
|
+
headers,
|
|
75
141
|
});
|
|
76
142
|
return this.doResponseResult(response);
|
|
77
143
|
} catch (error) {
|
|
@@ -94,7 +160,7 @@ export class Net {
|
|
|
94
160
|
url: string,
|
|
95
161
|
params: IParams = {},
|
|
96
162
|
headers: RawAxiosRequestHeaders = {},
|
|
97
|
-
option:
|
|
163
|
+
option: AxiosRequestConfig = {},
|
|
98
164
|
): Promise<IHttpResponse> {
|
|
99
165
|
// if (params.srfparentdata) {
|
|
100
166
|
// Object.assign(params, params.srfparentdata);
|
|
@@ -102,7 +168,10 @@ export class Net {
|
|
|
102
168
|
// }
|
|
103
169
|
url = this.attachUrlParam(url, params);
|
|
104
170
|
try {
|
|
105
|
-
const response = await
|
|
171
|
+
const response = await this.request(
|
|
172
|
+
url,
|
|
173
|
+
merge({ method: 'get', headers }, option),
|
|
174
|
+
);
|
|
106
175
|
return this.doResponseResult(response);
|
|
107
176
|
} catch (error) {
|
|
108
177
|
throw new HttpError(error as AxiosError);
|
|
@@ -126,7 +195,7 @@ export class Net {
|
|
|
126
195
|
): Promise<IHttpResponse> {
|
|
127
196
|
url = this.handleAppPresetParam(url, params);
|
|
128
197
|
try {
|
|
129
|
-
const response = await
|
|
198
|
+
const response = await this.request(url, { method: 'delete', headers });
|
|
130
199
|
return this.doResponseResult(response);
|
|
131
200
|
} catch (error) {
|
|
132
201
|
throw new HttpError(error as AxiosError);
|
|
@@ -152,7 +221,11 @@ export class Net {
|
|
|
152
221
|
): Promise<IHttpResponse> {
|
|
153
222
|
url = this.handleAppPresetParam(url, params);
|
|
154
223
|
try {
|
|
155
|
-
const response = await
|
|
224
|
+
const response = await this.request(url, {
|
|
225
|
+
method: 'put',
|
|
226
|
+
data,
|
|
227
|
+
headers,
|
|
228
|
+
});
|
|
156
229
|
return this.doResponseResult(response);
|
|
157
230
|
} catch (error) {
|
|
158
231
|
throw new HttpError(error as AxiosError);
|
|
@@ -173,7 +246,7 @@ export class Net {
|
|
|
173
246
|
headers: RawAxiosRequestHeaders = {},
|
|
174
247
|
): Promise<IHttpResponse> {
|
|
175
248
|
try {
|
|
176
|
-
const response = await
|
|
249
|
+
const response = await this.instance.get(url, {
|
|
177
250
|
headers,
|
|
178
251
|
});
|
|
179
252
|
return this.doResponseResult(response);
|
|
@@ -182,6 +255,29 @@ export class Net {
|
|
|
182
255
|
}
|
|
183
256
|
}
|
|
184
257
|
|
|
258
|
+
/**
|
|
259
|
+
* 基础请求方法,会合并预置配置
|
|
260
|
+
*
|
|
261
|
+
* @author lxm
|
|
262
|
+
* @date 2022-10-27 14:10:06
|
|
263
|
+
* @param {string} url
|
|
264
|
+
* @param {AxiosRequestConfig} [config={}]
|
|
265
|
+
* @returns {*} {Promise<IHttpResponse>}
|
|
266
|
+
*/
|
|
267
|
+
async request(
|
|
268
|
+
url: string,
|
|
269
|
+
config: AxiosRequestConfig = {},
|
|
270
|
+
): Promise<IHttpResponse> {
|
|
271
|
+
try {
|
|
272
|
+
const response = await this.instance.request(
|
|
273
|
+
this.mergeConfig({ url }, config),
|
|
274
|
+
);
|
|
275
|
+
return this.doResponseResult(response);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
throw new HttpError(error as AxiosError);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
185
281
|
/**
|
|
186
282
|
* 统一处理请求返回
|
|
187
283
|
*
|
|
@@ -234,7 +330,6 @@ export class Net {
|
|
|
234
330
|
* @return {*} {string}
|
|
235
331
|
*/
|
|
236
332
|
private attachUrlParam(url: string, params: IParams): string {
|
|
237
|
-
url = this.attachUrl(url);
|
|
238
333
|
const strParams: string = stringify(params);
|
|
239
334
|
if (notNilEmpty(strParams)) {
|
|
240
335
|
if (url.endsWith('?')) {
|
|
@@ -249,17 +344,4 @@ export class Net {
|
|
|
249
344
|
}
|
|
250
345
|
return url;
|
|
251
346
|
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* 处理 url 参数
|
|
255
|
-
*
|
|
256
|
-
* @author chitanda
|
|
257
|
-
* @date 2022-07-20 20:07:17
|
|
258
|
-
* @private
|
|
259
|
-
* @param {string} url
|
|
260
|
-
* @return {*} {string}
|
|
261
|
-
*/
|
|
262
|
-
private attachUrl(url: string): string {
|
|
263
|
-
return `${this.prefix}${url}`;
|
|
264
|
-
}
|
|
265
347
|
}
|