From 2c4d726e2f3af93a36d1685a9afdfd2c62a9f544 Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Wed, 24 Mar 2021 16:02:50 +0800
Subject: [PATCH] webSocket调整,退出登录时关闭websocket
---
src/page/index/top/index.vue | 6 +++++-
src/page/index/logo.vue | 14 +++++++-------
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/page/index/logo.vue b/src/page/index/logo.vue
index fb0ad94..98f62fa 100644
--- a/src/page/index/logo.vue
+++ b/src/page/index/logo.vue
@@ -370,14 +370,14 @@
}
if (window.WebSocket) {
- that.socket = new WebSocket("ws://36.134.81.48:9034/websocket");
- that.socket.onmessage = function (event) {
+ window.socket = new WebSocket("ws://36.134.81.48:9034/websocket");
+ window.socket.onmessage = function (event) {
};
- that.socket.onopen = function (event) {
+ window.socket.onopen = function (event) {
};
- that.socket.onclose = function (event) {
+ window.socket.onclose = function (event) {
};
} else {
console.log("您的浏览器不支持WebSocket");
@@ -387,12 +387,12 @@
if(!window.WebSocket){
return;
}
- if(that.socket.readyState == WebSocket.OPEN){
- that.socket.send(that.userId);
+ if(window.socket.readyState == WebSocket.OPEN){
+ window.socket.send(that.userId);
}else{
console.log("WebSocket连接没有建立成功!!");
}
- }, 4000);
+ }, 2000);
axios({
diff --git a/src/page/index/top/index.vue b/src/page/index/top/index.vue
index 395e94d..14b3f6e 100644
--- a/src/page/index/top/index.vue
+++ b/src/page/index/top/index.vue
@@ -19,7 +19,7 @@
</span>
</div>
<div class="top-bar__right">
-
+
<img src="/img/ydlg.png" style="height: 44px; vertical-align: middle;" alt="">
<el-tooltip v-if="showColor"
effect="dark"
@@ -170,6 +170,10 @@
cancelButtonText: this.$t("cancelText"),
type: "warning"
}).then(() => {
+
+ //关闭webSocket
+ window.socket.close();
+
this.$store.dispatch("LogOut").then(() => {
resetRouter();
this.$router.push({path: "/login"});
--
Gitblit v1.9.3