From d21e19d8754956109b87c1e20c4a249d93f5aa2c Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Thu, 25 Mar 2021 12:03:36 +0800
Subject: [PATCH] webSocket调整,改为在请求页调用,防止关闭后自动登录的情况
---
src/page/index/logo.vue | 64 +++++++++++++++++++++++++++++--
1 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/src/page/index/logo.vue b/src/page/index/logo.vue
index 4451528..4020fe9 100644
--- a/src/page/index/logo.vue
+++ b/src/page/index/logo.vue
@@ -261,7 +261,7 @@
</div>
</div>
</template>
-
+
<script>
import { mapGetters } from "vuex";
import axios from "axios";
@@ -338,7 +338,8 @@
};
},
created() {
- this.getData();
+ //this.getData();
+ this.websocketStart();
},
computed: {
...mapGetters(["website", "keyCollapse"]),
@@ -346,7 +347,6 @@
methods: {
getData() {
var that = this;
-
axios({
url: "/api/blade-jfpts/alarm/alarm/getLimit",
method: "get",
@@ -763,10 +763,64 @@
this.ofX = e.offsetX;
this.ofY = e.offsetY;
},
+
+ //启动websocket
+ websocketStart(){
+ if (!window.WebSocket) {
+ window.WebSocket = window.MozWebSocket;
+ }
+ if (window.WebSocket) {
+ //https
+ //window.socket = new WebSocket("wss://web.byisf.com/wss/websocket/");
+
+ //http
+ window.socket = new WebSocket("ws://localhost:9034/websocket");
+
+ window.socket.onmessage = function (event) {
+ };
+
+ window.socket.onopen = function (event) {
+ };
+
+ window.socket.onclose = function (event) {
+ };
+ } else {
+ console.log("WebSocket连接没有建立成功!!");
+ }
+
+ setTimeout(function () {
+
+ window.clearTimeout(window.websockPing);
+
+ if(!window.WebSocket){
+ return;
+ }
+ if(window.socket.readyState == WebSocket.OPEN){
+
+ var userId = JSON.parse(
+ window.localStorage.getItem("物联网安保云服务平台-userInfo")
+ ).content.user_id;
+
+ window.socket.send(userId);
+
+ //开启心跳传送
+ window.websockPing = setInterval(function () {
+ window.socket.send("ping");
+ },20000);
+
+
+ }else{
+ console.log("WebSocket连接没有建立成功!!");
+ }
+ }, 2000);
+
+
+
+ },
},
};
</script>
-
+
<style lang="scss">
.fade-leave-active {
transition: opacity 0.2s;
@@ -883,4 +937,4 @@
height: calc(100% - 44px);
box-sizing: border-box;
}
-</style>
\ No newline at end of file
+</style>
--
Gitblit v1.9.3