|
|
|
@ -7,7 +7,7 @@ const service = axios.create({ |
|
|
|
|
baseURL: import.meta.env.VITE_BASE_API, |
|
|
|
|
timeout: 10000, |
|
|
|
|
}); |
|
|
|
|
let loaded = 0; |
|
|
|
|
let logouted = 0; |
|
|
|
|
service.interceptors.request.use( |
|
|
|
|
(config) => { |
|
|
|
|
config.headers = { ...config.headers, ...getAuthHeaders() }; |
|
|
|
@ -18,13 +18,27 @@ service.interceptors.request.use( |
|
|
|
|
|
|
|
|
|
service.interceptors.response.use( |
|
|
|
|
(res) => { |
|
|
|
|
const { message, status } = res.data; |
|
|
|
|
const { message, status, code, msg } = res.data; |
|
|
|
|
if (status) { |
|
|
|
|
if (status === 200) { |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ElMessage.error(message); |
|
|
|
|
} else if (code === 401) { |
|
|
|
|
// 账号互踢
|
|
|
|
|
if (!logouted) { |
|
|
|
|
ElMessageBox.alert(msg.includes('顶') ? '您的账号已在其他设备登录,您已被迫下线!' : '登录过期,请重新登录!', { |
|
|
|
|
confirmButtonText: '重新登录', |
|
|
|
|
type: 'warning', |
|
|
|
|
closeOnClickModal: false, |
|
|
|
|
showClose: false, |
|
|
|
|
}).then(() => { |
|
|
|
|
// 未登录
|
|
|
|
|
logout(); |
|
|
|
|
}); |
|
|
|
|
logouted = 1; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
@ -37,12 +51,12 @@ service.interceptors.response.use( |
|
|
|
|
}, |
|
|
|
|
} = e; |
|
|
|
|
if (status === 401) { |
|
|
|
|
loaded || |
|
|
|
|
logouted || |
|
|
|
|
ElMessageBox.alert('登录状态已过期,请重新登录', { confirmButtonText: '重新登录', type: 'warning', closeOnClickModal: false, showClose: false }).then(() => { |
|
|
|
|
// 未登录
|
|
|
|
|
logout(); |
|
|
|
|
}); |
|
|
|
|
loaded = 1; |
|
|
|
|
logouted = 1; |
|
|
|
|
} else if (message) { |
|
|
|
|
ElMessage.error(message); |
|
|
|
|
} |
|
|
|
|