修改代码
This commit is contained in:
parent
79219792c9
commit
0b47562cca
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { handleToken } from '@/utils/auth';
|
import { handleToken } from '@/utils/auth';
|
||||||
import { creatSubscribe, perpetualTopic, commonTopic } from '@/utils/stomp';
|
import { creatSubscribe, clearSubscribe, perpetualTopic, commonTopic } from '@/utils/stomp';
|
||||||
import DeomonTopic from '@/views/demonstration/deomonTopic';
|
import DeomonTopic from '@/views/demonstration/deomonTopic';
|
||||||
import WindowResizeHandler from '@/mixin/WindowResizeHandler';
|
import WindowResizeHandler from '@/mixin/WindowResizeHandler';
|
||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
@ -53,6 +53,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async pageDestory() {
|
async pageDestory() {
|
||||||
|
this.unSubscribe();
|
||||||
const token = handleToken();
|
const token = handleToken();
|
||||||
Cookies.remove('UserDesignName');
|
Cookies.remove('UserDesignName');
|
||||||
Cookies.remove('UserDesignToken');
|
Cookies.remove('UserDesignToken');
|
||||||
@ -77,6 +78,10 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
unSubscribe() {
|
||||||
|
clearSubscribe(perpetualTopic);
|
||||||
|
clearSubscribe(commonTopic);
|
||||||
|
},
|
||||||
subscribeMessage(res) {
|
subscribeMessage(res) {
|
||||||
if (this.$refs.deomonTopic) {
|
if (this.$refs.deomonTopic) {
|
||||||
this.$refs.deomonTopic.doShow(res);
|
this.$refs.deomonTopic.doShow(res);
|
||||||
|
@ -9,57 +9,57 @@ const BASE_API = getBaseUrl();
|
|||||||
|
|
||||||
// 创建axios实例
|
// 创建axios实例
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: BASE_API, // api的base_url
|
baseURL: BASE_API, // api的base_url
|
||||||
withCredentials: true, // 跨域请求时是否需要使用凭证
|
withCredentials: true, // 跨域请求时是否需要使用凭证
|
||||||
timeout: 60000 // 请求超时时间
|
timeout: 600000 // 请求超时时间
|
||||||
});
|
});
|
||||||
|
|
||||||
// request拦截器
|
// request拦截器
|
||||||
service.interceptors.request.use(config => {
|
service.interceptors.request.use(config => {
|
||||||
if (handleToken()) {
|
if (handleToken()) {
|
||||||
config.headers['X-Token'] = handleToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
|
config.headers['X-Token'] = handleToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||||
}
|
}
|
||||||
if (config.time) {
|
if (config.time) {
|
||||||
config.timeout = config.time; // 让每个请求携带自定义token 请根据实际情况自行修改
|
config.timeout = config.time; // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}, error => {
|
}, error => {
|
||||||
// Do something with request error
|
// Do something with request error
|
||||||
Promise.reject(error);
|
Promise.reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
// respone拦截器
|
// respone拦截器
|
||||||
service.interceptors.response.use(
|
service.interceptors.response.use(
|
||||||
response => {
|
response => {
|
||||||
/** code为非200是抛错 可结合自己业务进行修改*/
|
/** code为非200是抛错 可结合自己业务进行修改*/
|
||||||
const res = response.data;
|
const res = response.data;
|
||||||
if (res.code != 200) {
|
if (res.code != 200) {
|
||||||
// 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了;
|
// 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了;
|
||||||
if (res.code == 40004 || res.code == 40005 || res.code == 40003) {
|
if (res.code == 40004 || res.code == 40005 || res.code == 40003) {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
EventBus.$emit('stop');
|
EventBus.$emit('stop');
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
EventBus.$emit('viewLoading', false);
|
EventBus.$emit('viewLoading', false);
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
EventBus.$emit('clearCheckLogin');
|
EventBus.$emit('clearCheckLogin');
|
||||||
MessageBox.confirm('你已被登出,请重新登录', '确定登出', {
|
MessageBox.confirm('你已被登出,请重新登录', '确定登出', {
|
||||||
confirmButtonText: '重新登录',
|
confirmButtonText: '重新登录',
|
||||||
showCancelButton: false,
|
showCancelButton: false,
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
store.dispatch('FedLogOut', gainClientId()).then(() => {
|
store.dispatch('FedLogOut', gainClientId()).then(() => {
|
||||||
location.reload();// 为了重新实例化vue-router对象 避免bug
|
location.reload();// 为了重新实例化vue-router对象 避免bug
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Promise.reject(res);
|
return Promise.reject(res);
|
||||||
} else {
|
} else {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export default service;
|
export default service;
|
||||||
|
Loading…
Reference in New Issue
Block a user