| | |
| | | // axios中请求配置有baseURL选项,表示请求URL公共部分 |
| | | baseURL: process.env.VUE_APP_BASE_API, |
| | | // 超时 |
| | | timeout: 10000 |
| | | timeout: 1000000 |
| | | }) |
| | | |
| | | // request拦截器 |
| | |
| | | // get请求映射params参数 |
| | | if (config.method === 'get' && config.params) { |
| | | let url = config.url + '?' + tansParams(config.params); |
| | | |
| | | |
| | | url = url.slice(0, -1); |
| | | config.params = {}; |
| | | config.url = url; |
| | | if(config.responseType!=undefined) |
| | | { |
| | | config.responseType='blob' |
| | | } |
| | | config.headers['Content-Type']= 'application/json' |
| | | } |
| | | if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) { |
| | | const requestObj = { |
| | |
| | | return config |
| | | }, error => { |
| | | console.log(error) |
| | | |
| | | Promise.reject(error) |
| | | }) |
| | | |
| | |
| | | service.interceptors.response.use(res => { |
| | | // 未设置状态码则默认成功状态 |
| | | const code = res.data.code || 200; |
| | | |
| | | |
| | | // 获取错误信息 |
| | | const msg = errorCode[code] || res.data.msg || errorCode['default'] |
| | | // 二进制数据则直接返回 |
| | |
| | | return Promise.reject('无效的会话,或者会话已过期,请重新登录。') |
| | | } else if (code === 500) { |
| | | Message({ message: msg, type: 'error' }) |
| | | alert(msg) |
| | | return Promise.reject(new Error(msg)) |
| | | } else if (code === 601) { |
| | | Message({ message: msg, type: 'warning' }) |