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) { '$store.state.socket.beLogoutCount': async function(val) {
this.$alert(this.$t('tip.logoutTips'), this.$t('tip.hint'), { this.$store.dispatch('disconnect').then(()=>{
confirmButtonText: this.$t('tip.confirm'), this.$alert(this.$t('tip.logoutTips'), this.$t('tip.hint'), {
callback: action => { confirmButtonText: this.$t('tip.confirm'),
this.$store.dispatch('exit').then(resp => { callback: action => {
this.$router.push({path: loginInfo[getSessionStorage('project')].loginPath}); 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) { disconnect({commit}, params) {
commit('Disconnect', params); commit('Disconnect', params);
removeToken();
} }
} }
}; };

View File

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

View File

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