南昌市物联网技防平台-前端
shuishen
2021-03-25 fe9be2557c00090bc3074a378907d59c19ffe455
Merge branch 'master' of http://s16s652780.51mypc.cn:49896/r/jfpt-Vue
1 files modified
58 ■■■■■ changed files
src/page/index/logo.vue 58 ●●●●● patch | view | raw | blame | history
src/page/index/logo.vue
@@ -339,7 +339,8 @@
    };
  },
  created() {
    this.getData();
    //this.getData();
    this.websocketStart();
  },
  computed: {
    ...mapGetters(["website", "keyCollapse"]),
@@ -347,7 +348,6 @@
  methods: {
    getData() {
      var that = this;
      axios({
        url: "/api/blade-jfpts/alarm/alarm/getLimit",
        method: "get",
@@ -764,6 +764,60 @@
      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>