Browse Source

聊天室断线重连

udream-cxs 4 years ago
parent
commit
714518745b

+ 9 - 1
src/apps/mobile/views/monitoring-center-bank/chat-room/chat-room.vue

@@ -215,7 +215,8 @@ export default {
             dataTable: null,
             $ws: null,
             timer: '',
-            isShowHistory: true
+            isShowHistory: true,
+            isAutoCloseWs: false
         };
     },
     created() {
@@ -278,9 +279,15 @@ export default {
         wsClose: function(e) {
             console.log('WebSocket连接关闭...........');
             clearInterval(this.timer);
+            if(!this.isAutoCloseWs){
+                setTimeout(() => {
+                    this.initWebSocket();
+                }, 3000);
+            }
         },
         wsError: function(e) {
             console.log('WebSocket连接出现错误............');
+            
         },
         wsMessage: function(e) {
             let msgData = JSON.parse(e.data);
@@ -496,6 +503,7 @@ export default {
     },
     destroyed() {
         this.$ws.onclose();
+        this.isAutoCloseWs = true;
     },
 };
 </script>