|
|
|
@ -14,12 +14,14 @@ axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
|
|
// 创建axios实例
|
|
|
|
|
const service = axios.create({
|
|
|
|
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
|
|
|
|
baseURL: 'http://118.31.7.2:8800',
|
|
|
|
|
// baseURL: 'http://118.31.7.2:8800',
|
|
|
|
|
baseURL: 'http://localhost:8800',
|
|
|
|
|
// baseURL: 'http://192.168.2.14:8800',
|
|
|
|
|
// baseURL:"http://192.168.2.17:8801",
|
|
|
|
|
// baseURL: process.env.VUE_APP_BASE_API,
|
|
|
|
|
// 超时
|
|
|
|
|
timeout: 200000
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
// request拦截器
|
|
|
|
|
service.interceptors.request.use(config => {
|
|
|
|
@ -69,9 +71,10 @@ service.interceptors.request.use(config => {
|
|
|
|
|
|
|
|
|
|
// 响应拦截器
|
|
|
|
|
service.interceptors.response.use(res => {
|
|
|
|
|
console.log(res, 'res1');
|
|
|
|
|
// console.log(res, 'res1');
|
|
|
|
|
debugger
|
|
|
|
|
// 未设置状态码则默认成功状态
|
|
|
|
|
const code = res.data.code || 200
|
|
|
|
|
const code = res.status || 200
|
|
|
|
|
// 获取错误信息
|
|
|
|
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
|
|
// 二进制数据则直接返回
|
|
|
|
@ -106,19 +109,20 @@ service.interceptors.response.use(res => {
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
let { message } = error
|
|
|
|
|
|
|
|
|
|
// debugger
|
|
|
|
|
if (message == 'Network Error') {
|
|
|
|
|
message = '后端接口连接异常'
|
|
|
|
|
} else if (message.includes('timeout')) {
|
|
|
|
|
message = '系统接口请求超时'
|
|
|
|
|
|
|
|
|
|
} else if (message.includes('401')) {
|
|
|
|
|
} else if (error.response.status=="401") {
|
|
|
|
|
if (!isRelogin.show) {
|
|
|
|
|
isRelogin.show = true
|
|
|
|
|
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
|
|
|
|
isRelogin.show = false
|
|
|
|
|
document.cookie = 'Admin-Token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
|
|
|
|
// store.dispatch('LogOut').then(() => {
|
|
|
|
|
// location.href = '/index';
|
|
|
|
|
location.href = '/login';
|
|
|
|
|
// })
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
isRelogin.show = false
|
|
|
|
@ -126,7 +130,7 @@ error => {
|
|
|
|
|
}
|
|
|
|
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (message.includes('Request failed with status code')) {
|
|
|
|
|
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
|
|
|
|
}
|
|
|
|
@ -159,7 +163,7 @@ export function download(url, params, filename, config) {
|
|
|
|
|
console.error(r)
|
|
|
|
|
Message.error('下载文件出现错误,请联系管理员!')
|
|
|
|
|
downloadLoadingInstance.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
export default service
|
|
|
|
|