|
@@ -62,16 +62,8 @@ service.interceptors.response.use(res => {
|
|
|
// 获取错误信息 - 优先使用后端返回的 message 或 msg,兼容两种字段名
|
|
// 获取错误信息 - 优先使用后端返回的 message 或 msg,兼容两种字段名
|
|
|
const msg = res.data.message || res.data.msg || errorCode[code] || errorCode['default']
|
|
const msg = res.data.message || res.data.msg || errorCode[code] || errorCode['default']
|
|
|
if (code === 401) {
|
|
if (code === 401) {
|
|
|
- MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
|
|
- confirmButtonText: '重新登录',
|
|
|
|
|
- cancelButtonText: '取消',
|
|
|
|
|
- type: 'warning'
|
|
|
|
|
- }
|
|
|
|
|
- ).then(() => {
|
|
|
|
|
- store.dispatch('LogOut').then(() => {
|
|
|
|
|
- location.href = '/index';
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ handleAuthExpired()
|
|
|
|
|
+ return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
} else if (code === 500) {
|
|
} else if (code === 500) {
|
|
|
Notification.error({
|
|
Notification.error({
|
|
|
title: msg
|
|
title: msg
|
|
@@ -88,6 +80,13 @@ service.interceptors.response.use(res => {
|
|
|
},
|
|
},
|
|
|
error => {
|
|
error => {
|
|
|
console.log('err' + error)
|
|
console.log('err' + error)
|
|
|
|
|
+ const status = error.response && error.response.status
|
|
|
|
|
+ const respMsg = (error.response && error.response.data && (error.response.data.message || error.response.data.msg)) || ''
|
|
|
|
|
+ // HTTP 401,或 JWT 签名/鉴权失败被后端打成 500 时,清理登录态并跳转登录
|
|
|
|
|
+ if (status === 401 || isAuthInvalidMessage(respMsg) || isAuthInvalidMessage(error.message)) {
|
|
|
|
|
+ handleAuthExpired()
|
|
|
|
|
+ return Promise.reject(error)
|
|
|
|
|
+ }
|
|
|
let { message } = error;
|
|
let { message } = error;
|
|
|
if (message == "Network Error") {
|
|
if (message == "Network Error") {
|
|
|
message = "后端接口连接异常";
|
|
message = "后端接口连接异常";
|
|
@@ -107,4 +106,37 @@ service.interceptors.response.use(res => {
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+let isReloginShowing = false
|
|
|
|
|
+
|
|
|
|
|
+function isAuthInvalidMessage(msg) {
|
|
|
|
|
+ if (!msg) {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ const text = String(msg)
|
|
|
|
|
+ return text.indexOf('JWT signature') !== -1
|
|
|
|
|
+ || text.indexOf('JWT validity') !== -1
|
|
|
|
|
+ || text.indexOf('认证失败') !== -1
|
|
|
|
|
+ || text.indexOf('Token') !== -1 && text.indexOf('过期') !== -1
|
|
|
|
|
+ || text.indexOf('登录状态已过期') !== -1
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function handleAuthExpired() {
|
|
|
|
|
+ if (isReloginShowing) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ isReloginShowing = true
|
|
|
|
|
+ MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
|
|
+ confirmButtonText: '重新登录',
|
|
|
|
|
+ cancelButtonText: '取消',
|
|
|
|
|
+ type: 'warning'
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ isReloginShowing = false
|
|
|
|
|
+ store.dispatch('FedLogOut').then(() => {
|
|
|
|
|
+ location.href = '/login'
|
|
|
|
|
+ })
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ isReloginShowing = false
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export default service
|
|
export default service
|