From 2f120b8c19e17e9df50c6e9cc55091382c44d8f5 Mon Sep 17 00:00:00 2001 From: joylink_cuiweidong <364937672@qq.com> Date: Tue, 14 Jan 2020 18:18:54 +0800 Subject: [PATCH] =?UTF-8?q?sock=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 16 +++++++++------- src/store/modules/user.js | 1 + src/utils/request.js | 17 +++++++++-------- src/utils/sock.js | 11 +++++++++-- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/App.vue b/src/App.vue index 05a1384db..d28ca267d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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}); + }); + } + }); }); } }, diff --git a/src/store/modules/user.js b/src/store/modules/user.js index a4aadd7cf..d52813076 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -188,6 +188,7 @@ const user = { }, disconnect({commit}, params) { commit('Disconnect', params); + removeToken(); } } }; diff --git a/src/utils/request.js b/src/utils/request.js index d9b003ba1..d8d2f83c3 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -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 + }); }); }); } diff --git a/src/utils/sock.js b/src/utils/sock.js index a20774e48..b620bcdbc 100644 --- a/src/utils/sock.js +++ b/src/utils/sock.js @@ -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(() => {