|
|
@ -8,14 +8,14 @@ import { |
|
|
|
getToken, |
|
|
|
getStorage |
|
|
|
} from '@/utils/auth' |
|
|
|
|
|
|
|
import router from '@/router' |
|
|
|
// create an axios instance
|
|
|
|
const service = axios.create({ |
|
|
|
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
|
|
|
|
// withCredentials: true, // send cookies when cross-domain requests
|
|
|
|
timeout: 30000 // request timeout
|
|
|
|
}) |
|
|
|
|
|
|
|
var isLoging = false |
|
|
|
// request interceptor
|
|
|
|
service.interceptors.request.use( |
|
|
|
config => { |
|
|
@ -59,6 +59,9 @@ service.interceptors.response.use( |
|
|
|
const statusCode = response.status |
|
|
|
console.log('statusCode>>>' + statusCode) |
|
|
|
// if the custom code is not 20000, it is judged as an error.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (statusCode !== 200) { |
|
|
|
Message({ |
|
|
|
message: res.msg || response.message || 'Error', |
|
|
@ -68,20 +71,20 @@ service.interceptors.response.use( |
|
|
|
}) |
|
|
|
|
|
|
|
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
|
|
|
if (statusCode === 401 || res.code === '5000' || res.code === 5000 || res.code === 50012 || res.code === |
|
|
|
50014) { |
|
|
|
// to re-login
|
|
|
|
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { |
|
|
|
confirmButtonText: '重新登录', |
|
|
|
cancelButtonText: '取消', |
|
|
|
type: 'warning' |
|
|
|
}).then(() => { |
|
|
|
store.dispatch('logout').then(() => { |
|
|
|
location.href = 'http://120.46.131.15/#/login' |
|
|
|
// location.reload()
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
// if (statusCode === 401 || res.code === '5000' || res.code === 5000 || res.code === 50012 || res.code ===
|
|
|
|
// 50014) {
|
|
|
|
// // to re-login
|
|
|
|
// MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
|
// confirmButtonText: '重新登录',
|
|
|
|
// cancelButtonText: '取消',
|
|
|
|
// type: 'warning'
|
|
|
|
// }).then(() => {
|
|
|
|
// store.dispatch('logout').then(() => {
|
|
|
|
// location.href = '/#/login'
|
|
|
|
// // location.reload()
|
|
|
|
// })
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
return Promise.reject(new Error(res.message || 'Error')) |
|
|
|
} else { |
|
|
|
if (!res.success && res.success !== null && res.success !== undefined) { |
|
|
@ -92,6 +95,32 @@ service.interceptors.response.use( |
|
|
|
duration: 5 * 1000 |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
if (res.code === '5000') { |
|
|
|
// to re-login
|
|
|
|
console.log("aaa",isLoging); |
|
|
|
|
|
|
|
if (!isLoging) { |
|
|
|
console.log("aaa2",isLoging); |
|
|
|
isLoging = true |
|
|
|
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { |
|
|
|
confirmButtonText: '重新登录', |
|
|
|
cancelButtonText: '取消', |
|
|
|
type: 'warning' |
|
|
|
}).then(() => { |
|
|
|
isLoging = false |
|
|
|
router.push({ |
|
|
|
path: '/login' |
|
|
|
}) |
|
|
|
done() |
|
|
|
|
|
|
|
}).catch(() => { |
|
|
|
isLoging = false |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return res |
|
|
|
} |
|
|
|
}, |
|
|
|