2 lines
1.6 KiB
JavaScript
2 lines
1.6 KiB
JavaScript
(function(s,u){if(typeof module=="object"&&module.exports){module.exports=u(s);return}s.AxiosRequestUtil=u(s)})(typeof globalThis!="undefined"?globalThis:window,function(s){"use strict";function u(e){return typeof FormData!="undefined"&&e instanceof FormData}function h(e,r){var t=new Error(e);return Object.keys(r||{}).forEach(function(a){t[a]=r[a]}),t}function d(e){if(!e||typeof e!="object")return e;if(e.code!==void 0&&Number(e.code)!==200)throw h(e.msg||"接口请求失败",{code:e.code,response:e});return Object.prototype.hasOwnProperty.call(e,"data")?e.data:Object.prototype.hasOwnProperty.call(e,"rows")?{rows:e.rows,total:e.total}:e}function v(e){var r=e||{},t=r.axiosInstance||s.axios;if(!t||typeof t.request!="function"&&typeof t.create!="function")throw new Error("缺少 Axios 公共依赖");return typeof t.create=="function"?t.create({baseURL:r.baseUrl}):t}function g(e){var r=e||{},t=v(r);function a(p){Number(p)===401&&r.onUnauthorized&&r.onUnauthorized()}return async function(l,x,q){var o=q||{},i=Object.assign({},o.headers||{}),w=r.getToken?r.getToken():"",j=r.tokenHeaderName||"Authorization",c=o.body,m;i.clientid=r.clientId,w&&o.auth!==!1&&(i[j]="Bearer "+w),c!=null&&!u(c)&&(i["Content-Type"]=i["Content-Type"]||"application/json");try{m=await t.request({method:String(l||"GET").toLowerCase(),url:x,params:o.query,data:c,headers:i})}catch(n){var f=n.response&&n.response.data,b=n.response&&n.response.status;throw o.auth!==!1&&a(b),h(f&&f.msg||n.message||"接口请求失败",{status:b,response:f,cause:n})}try{return d(m.data)}catch(n){throw o.auth!==!1&&a(n.code),n}}}return{createRequester:g,unwrapResponse:d}});
|