UNPKG

@fast-china/axios

Version:

Fast Axios 请求工具库.

3 lines (2 loc) 3.03 kB
"use strict";var e=Object.defineProperty,s=(s,t,r)=>((s,t,r)=>t in s?e(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r)(s,"symbol"!=typeof t?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("axios"),r=require("lodash-unified");require("./types/index.js");const i=require("./types/loading.js"),o=require("./types/message.js"),n=require("./types/messageBox.js"),a=require("./types/cache.js"),h=require("./types/crypto.js"),u=require("./types/interceptors.js");class c{constructor(e){s(this,"_baseUrl"),s(this,"_timeout"),s(this,"_headers"),s(this,"_requestCipher"),s(this,"errorCode"),s(this,"loading"),s(this,"message"),s(this,"messageBox"),s(this,"cache"),s(this,"crypto"),s(this,"interceptors"),this.setOptions(e),this.errorCode={cancelDuplicate:"重复请求,自动取消!",offLine:"您断网了!",fileDownloadError:"文件下载失败或此文件不存在!",302:"接口重定向了!",400:"参数不正确!",401:"您没有权限操作(令牌、用户名、密码错误)!",403:"您的访问是被禁止的!",404:"请求的资源不存在!",405:"请求的格式不正确!",408:"请求超时!",409:"系统已存在相同数据!",410:"请求的资源被永久删除,且不会再得到的!",422:"当创建一个对象时,发生一个验证错误!",429:"请求过于频繁,请稍后再试!",500:"服务器内部错误!",501:"服务未实现!",502:"网关错误!",503:"服务不可用,服务器暂时过载或维护!",504:"服务暂时无法访问,请稍后再试!",505:"HTTP版本不受支持!",[t.AxiosError.ETIMEDOUT]:"请求超时!",[t.AxiosError.ECONNABORTED]:"连接中断,服务器暂时过载或维护!",[t.AxiosError.ERR_NETWORK]:"网关错误,服务不可用,服务器暂时过载或维护!"},this.loading=new i.LoadingManage,this.message=new o.MessageManage,this.messageBox=new n.MessageBoxManage,this.cache=new a.CacheManage,this.crypto=new h.CryptoManage,this.interceptors=new u.InterceptorsManage}setOptions(e){return(null==e?void 0:e.baseUrl)&&(this._baseUrl=e.baseUrl),(null==e?void 0:e.timeout)?this._timeout=e.timeout:this._timeout=this._timeout??6e4,(null==e?void 0:e.headers)&&(this._headers={...this._headers??{},...e.headers}),r.isNil(null==e?void 0:e.requestCipher)?this._requestCipher=!!r.isNil(this._requestCipher)||this._requestCipher:this._requestCipher=e.requestCipher,this}get baseUrl(){return this._baseUrl}get timeout(){return this._timeout}get headers(){return this._headers}get requestCipher(){return this._requestCipher}addErrorCode(e,s){if("string"==typeof e||"number"==typeof e)this.errorCode[e]=s;else for(const t in e)this.errorCode[t]=e[t];return this}}s(c,"instance");exports.createFastAxios=(e,s=!1)=>{if(s)return new c(e);if(!c.instance){const s=new c(e);c.instance=s}return c.instance},exports.useFastAxios=()=>{if(!c.instance)throw new Error("请先调用 'createFastAxios' 初始化 'fast-axios'。");return c.instance}; //# sourceMappingURL=fastAxios.js.map