1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 状态码处理
import route from "@/router";
import store from "@/store";
import Vue from "vue";
let that = new Vue();
// token失效
const TOKEN_INVLIDE_TO_LOGIN = (code) => {
// 状态码判断
if (code === "1012") {
if (store.state.common.userInfo !== "") {
that.$msg.error({
message: "登陆失败",
description: "token已过期",
});
}
// 清除个人数据
store.commit("common/setUserInfo", "");
route.replace({
path: "/login",
query: {
redirect: route.currentRoute.fullPath,
},
});
return false;
} else {
return true;
}
};
// 全局错误处理
const PUB_ERR = (code, message, config) => {
if(code === '1018') {
that.$msg.error({
message,
});
}
if (config.responseType && config.responseType === "blob") {
return true;
}
return true;
};
export default {
TOKEN_INVLIDE_TO_LOGIN,
PUB_ERR,
};