Skip to content

Commit cf1fb6c

Browse files
committed
refine demo code
1 parent 7287894 commit cf1fb6c

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/utils/fetch.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,34 @@ service.interceptors.request.use(config => {
2424

2525
// respone拦截器
2626
service.interceptors.response.use(
27-
response => response
27+
response => response,
2828
/**
2929
* 下面的注释为通过response自定义code来标示请求状态,当code返回如下情况为权限有问题,登出并返回到登录页
3030
* 如通过xmlhttprequest 状态码标识 逻辑可写在下面error中
3131
*/
32-
// const code = response.data.code;
33-
// // 50014:Token 过期了 50012:其他客户端登录了 50008:非法的token
34-
// if (code === 50008 || code === 50014 || code === 50012) {
35-
// Message({
36-
// message: res.message,
37-
// type: 'error',
38-
// duration: 5 * 1000
39-
// });
40-
// // 登出
41-
// store.dispatch('FedLogOut').then(() => {
42-
// router.push({ path: '/login' })
43-
// });
44-
// } else {
45-
// return response
46-
// }
47-
,
32+
// const res = response.data;
33+
// if (res.code !== 20000) {
34+
// Message({
35+
// message: res.message,
36+
// type: 'error',
37+
// duration: 5 * 1000
38+
// });
39+
// // 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了;
40+
// if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
41+
// MessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
42+
// confirmButtonText: '重新登录',
43+
// cancelButtonText: '取消',
44+
// type: 'warning'
45+
// }).then(() => {
46+
// store.dispatch('FedLogOut').then(() => {
47+
// location.reload();// 为了重新实例化vue-router对象 避免bug
48+
// });
49+
// })
50+
// }
51+
// return Promise.reject(error);
52+
// } else {
53+
// return response.data;
54+
// }
4855
error => {
4956
console.log('err' + error);// for debug
5057
Message({

0 commit comments

Comments
 (0)