|
@@ -2547,6 +2547,25 @@ export default {
|
|
|
this.imgZoomUrl = url;
|
|
|
this.imgZoomStatus = true;
|
|
|
},
|
|
|
+ //5.9 创建链接 防止websocket意外中断
|
|
|
+ getWebsocket(){
|
|
|
+ //判断当前的route是否为/hall,否则不触发这个方法
|
|
|
+ if(this.$route.path=="/hall"){
|
|
|
+ this.$confirm('您的会话意外断开,是否重新连接?', '提示', {
|
|
|
+ confirmButtonText: '重新连接',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ //强制刷新页面
|
|
|
+ window.location.reload();
|
|
|
+ }).catch(() => {
|
|
|
+ //取消刷新
|
|
|
+ this.$message.error("您的连接已中断!")
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ console.log("前往其他页面,关闭ws!")
|
|
|
+ }
|
|
|
+ }
|
|
|
//5.websocket会话 end---------------------------------------->
|
|
|
},
|
|
|
mounted() {
|
|
@@ -2561,10 +2580,15 @@ export default {
|
|
|
this.ws = new WebSocket(websocketNewUrl);
|
|
|
this.ws.addEventListener('message', this.handleIncomingMessage);
|
|
|
|
|
|
+ //3.当连接中断时提供一个方法重新连接
|
|
|
+ let that = this;
|
|
|
+
|
|
|
//当连接关闭的时候关闭websocket
|
|
|
this.ws.addEventListener('close', function (event) {
|
|
|
// 连接关闭时执行的操作
|
|
|
- console.log("关闭链接",event)
|
|
|
+ console.log("关闭链接",event);
|
|
|
+ // 弹窗询问用户是否手动刷新
|
|
|
+ that.getWebsocket();
|
|
|
});
|
|
|
|
|
|
//开启websocket连接 end---------------------------------------->
|