3f535f30
杨鑫
'初始'
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
// config.headers['type'] = ' admin'
}
return config
},
error => {
console.log(error) // for debug
return Promise.reject(error)
}
)
// response interceptor
service.interceptors.response.use(
response => {
const res = response.data
if (response.config.responseType === 'blob') {
return response.data
}
if (res.code !== '' && res.code != 200) {
Message({
message: res.message || 'Error',
type: 'error',
duration: 5 * 1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
/**
token为空 20003
public static final String TOKEN_IS_NULL = "20003";
token认证失败
public static final String TOKEN_APPROVE_ERROR = "20004";
请先登录
public static final String USER_NOT_LOGIN = "20005";
*/
const tokenerr = [20003, '20003', 20004, '20004', 20005, '20005']
if (tokenerr.includes(res.code)) {
localStorage.clear()
removeToken()
router.push({ path: '/login' })
location.reload()
}
if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
// to re-login
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
confirmButtonText: 'Re-Login',
cancelButtonText: 'Cancel',
type: 'warning'
}).then(() => {
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
}
return Promise.reject(new Error(res.message || 'Error'))
} else {
return res
}
},
// error => {
// if (!error.message.includes('timeout')) {
// // Message({
// // message: '服务器暂无响应,请稍后重试',
// // type: 'error',
// // duration: 5 * 1000
// // })
// }
// return Promise.reject(error)
// }
)
export default service
|