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