xinbiaoqian
This commit is contained in:
parent
c2c9f32908
commit
e287df2393
|
@ -25,6 +25,8 @@
|
|||
// }]
|
||||
// }
|
||||
// ]
|
||||
// import sysConfig from "@/config";
|
||||
// const linkUrl = sysConfig.API_URL.slice(0,--3)+"#/bigScreen";
|
||||
|
||||
const routes = [
|
||||
{
|
||||
|
@ -50,11 +52,12 @@ const routes = [
|
|||
},
|
||||
{
|
||||
"name": "bigScreen",
|
||||
"path": "/bigScreen",
|
||||
"path": "http://222.222.144.147:6013/#/bigScreen",
|
||||
"meta": {
|
||||
"title": "驾驶舱",
|
||||
"icon": "el-icon-position",
|
||||
"fullpage": true,
|
||||
"type": "link",
|
||||
"perms": ["bigScreen"]
|
||||
},
|
||||
"component": "bigScreen"
|
||||
|
|
|
@ -6,8 +6,12 @@ import router from '@/router';
|
|||
|
||||
axios.defaults.baseURL = sysConfig.API_URL;
|
||||
|
||||
axios.defaults.timeout = sysConfig.TIMEOUT
|
||||
axios.defaults.timeout = sysConfig.TIMEOUT;
|
||||
|
||||
// 是否正在刷新的标记
|
||||
let isRefreshing = false;
|
||||
// 重试队列,每一项将是一个待执行的函数形式
|
||||
let requests = [];
|
||||
// HTTP request 拦截器
|
||||
axios.interceptors.request.use(
|
||||
(config) => {
|
||||
|
@ -36,10 +40,44 @@ axios.interceptors.response.use(
|
|||
if (error.response) {
|
||||
if (error.response.status == 401) {
|
||||
if(error.response.data.err_code == 'no_active_account'){
|
||||
ElNotification.warning({
|
||||
title: '请求失败',
|
||||
message: "账户密码错误或已禁用"
|
||||
});
|
||||
// ElNotification.warning({
|
||||
// title: '请求失败',
|
||||
// message: "账户密码错误或已禁用"
|
||||
// });
|
||||
if (!isRefreshing) {
|
||||
isRefreshing = true;
|
||||
axios({
|
||||
method: 'post',
|
||||
url: sysConfig.API_URL+'/auth/token/refresh/',
|
||||
headers: {
|
||||
Authorization: `Bearer ${tool.cookie.get("TOKEN")}`,
|
||||
},
|
||||
data:{refresh:tool.cookie.get("TOKEN_REFRESH")}
|
||||
}).then(res=>{
|
||||
debugger;
|
||||
console.log(res.data.access);
|
||||
// 替换本地的token
|
||||
tool.cookie.set("TOKEN", res.data.access);
|
||||
tool.data.set("TOKEN_TIME", new Date().getTime());
|
||||
error.config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + res.data.access;
|
||||
isRefreshing = false;
|
||||
requests.forEach(cb => cb())
|
||||
//发起后将requests置空
|
||||
requests=[];
|
||||
return axios(error.config)
|
||||
}).catch(()=>{
|
||||
// refresh_token 有值 , 但是过期了, 请求失败
|
||||
router.push('/login')
|
||||
})
|
||||
|
||||
}else{
|
||||
//如果正在刷新token,将发起的请求暂存在requests中
|
||||
return new Promise((resolve)=>{
|
||||
requests.push(()=>{
|
||||
resolve(axios(error.config));
|
||||
})
|
||||
})
|
||||
}
|
||||
}else{
|
||||
// ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', {
|
||||
// type: 'error',
|
||||
|
|
|
@ -157,6 +157,8 @@ export default {
|
|||
that.$TOOL.cookie.set("TOKEN", res.access, {
|
||||
expires: that.form.autologin ? 24 * 60 * 60 : 0,
|
||||
});
|
||||
that.$TOOL.cookie.set("TOKEN_REFRESH", res.refresh);
|
||||
that.$TOOL.data.set("TOKEN_TIME", new Date().getTime());
|
||||
try {
|
||||
var res1 = await that.$API.auth.info.get();
|
||||
that.$TOOL.data.set("USER_INFO", res1);
|
||||
|
|
Loading…
Reference in New Issue