|
@@ -5,9 +5,9 @@ import { getToken } from '@/utils/auth'
|
|
|
|
|
|
|
|
// create an axios instance
|
|
// create an axios instance
|
|
|
const service = axios.create({
|
|
const service = axios.create({
|
|
|
- baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
|
|
|
|
|
|
|
+ baseURL: window.Domain.api_url, // url = base url + request url
|
|
|
// withCredentials: true, // send cookies when cross-domain requests
|
|
// withCredentials: true, // send cookies when cross-domain requests
|
|
|
- timeout: 5000 // request timeout
|
|
|
|
|
|
|
+ timeout: 10000 // request timeout
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// request interceptor
|
|
// request interceptor
|
|
@@ -19,7 +19,7 @@ service.interceptors.request.use(
|
|
|
// let each request carry token
|
|
// let each request carry token
|
|
|
// ['X-Token'] is a custom headers key
|
|
// ['X-Token'] is a custom headers key
|
|
|
// please modify it according to the actual situation
|
|
// please modify it according to the actual situation
|
|
|
- config.headers['X-Token'] = getToken()
|
|
|
|
|
|
|
+ config.headers['Authorization'] = `Bearer ${getToken()}`
|
|
|
}
|
|
}
|
|
|
return config
|
|
return config
|
|
|
},
|
|
},
|
|
@@ -46,15 +46,15 @@ service.interceptors.response.use(
|
|
|
const res = response.data
|
|
const res = response.data
|
|
|
|
|
|
|
|
// if the custom code is not 20000, it is judged as an error.
|
|
// if the custom code is not 20000, it is judged as an error.
|
|
|
- if (res.code !== 20000) {
|
|
|
|
|
|
|
+ if (res.code !== 200) {
|
|
|
Message({
|
|
Message({
|
|
|
- message: res.message || 'Error',
|
|
|
|
|
|
|
+ message: res.msg || 'Error',
|
|
|
type: 'error',
|
|
type: 'error',
|
|
|
duration: 5 * 1000
|
|
duration: 5 * 1000
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
|
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
|
|
- if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
|
|
|
|
|
|
|
+ if (res.code === 401 || res.code === 50012 || res.code === 50014) {
|
|
|
// to re-login
|
|
// to re-login
|
|
|
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
|
|
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
|
|
|
confirmButtonText: 'Re-Login',
|
|
confirmButtonText: 'Re-Login',
|