sock代码调整

This commit is contained in:
joylink_cuiweidong 2020-01-14 18:18:54 +08:00
parent 75334d11fa
commit 2f120b8c19
4 changed files with 28 additions and 17 deletions

View File

@ -32,13 +32,15 @@ export default {
}
},
'$store.state.socket.beLogoutCount': async function(val) {
this.$alert(this.$t('tip.logoutTips'), this.$t('tip.hint'), {
confirmButtonText: this.$t('tip.confirm'),
callback: action => {
this.$store.dispatch('exit').then(resp => {
this.$router.push({path: loginInfo[getSessionStorage('project')].loginPath});
});
}
this.$store.dispatch('disconnect').then(()=>{
this.$alert(this.$t('tip.logoutTips'), this.$t('tip.hint'), {
confirmButtonText: this.$t('tip.confirm'),
callback: action => {
this.$store.dispatch('exit').then(resp => {
this.$router.push({path: loginInfo[getSessionStorage('project')].loginPath});
});
}
});
});
}
},

View File

@ -188,6 +188,7 @@ const user = {
},
disconnect({commit}, params) {
commit('Disconnect', params);
removeToken();
}
}
};

View File

@ -44,14 +44,15 @@ service.interceptors.response.use(
// eslint-disable-next-line no-undef
EventBus.$emit('clearCheckLogin');
// 断开连接
store.dispatch('Disconnect');
MessageBox.confirm(i18n.t('tip.logoutTips'), i18n.t('tip.hint'), {
confirmButtonText: i18n.t('tip.confirmLogin'),
showCancelButton: false,
type: 'warning'
}).then(() => {
store.dispatch('FedLogOut').then(() => {
location.reload();// 为了重新实例化vue-router对象 避免bug
store.dispatch('disconnect').then(()=>{
MessageBox.confirm(i18n.t('tip.logoutTips'), i18n.t('tip.hint'), {
confirmButtonText: i18n.t('tip.confirmLogin'),
showCancelButton: false,
type: 'warning'
}).then(() => {
store.dispatch('FedLogOut').then(() => {
location.reload();// 为了重新实例化vue-router对象 避免bug
});
});
});
}

View File

@ -37,8 +37,11 @@ StompClient.prototype = {
return new Promise((resolve, reject) => {
try {
// 建立连接对象(还未发起连接)
// null, {transports:['websocket']}解决连接关闭后xhr_streaming无限循环
this.socket = new SockJS(websocketUrl + getToken(), null, {transports:['websocket', 'MozWebSocket']});
// null, {transports:['websocket']}虽可以解决连接关闭后xhr_streaming无限循环
// 但是该参数只会允许websockets,若不支持,直接报错
// 注意sockjs会做降级处理优先处理websockets若浏览器不支持websockets
// 则会降级为xhr_streaming轮询继续不支持的时候会降级为xhr-polling
this.socket = new SockJS(websocketUrl + getToken());
// 获取 STOMP 子协议的客户端对象
this.clientIns = Stomp.over(this.socket);
@ -72,6 +75,10 @@ StompClient.prototype = {
this.logOut(err);
});
};
this.clientIns.ws.onerror = ()=>{
// debugger;
console.log(1111);
};
resolve(this);
}, () => {
checkLoginLine().then(() => {