南昌市物联网技防平台-前端
zengh
2021-03-24 6c35a10041238b7f53c4538354c8b14db9db169c
webSocket调整,改为在请求页调用,防止关闭后自动登录的情况
1 files modified
43 ■■■■■ changed files
src/page/index/logo.vue 43 ●●●●● patch | view | raw | blame | history
src/page/index/logo.vue
@@ -276,6 +276,8 @@
      videoConversationReal: false,
      oldVideoSatart: false,
      deviceId: null,
        userId: null,
        socket: null,
      form: {},
      itemOption: {
        menuBtn: false,
@@ -338,6 +340,12 @@
    };
  },
  created() {
      this.userId = JSON.parse(
        window.localStorage.getItem("物联网安保云服务平台-userInfo")
      ).content.user_id;
    this.getData();
    
  },
@@ -357,6 +365,36 @@
    getData() {
      var that = this;
        if (!window.WebSocket) {
          window.WebSocket = window.MozWebSocket;
        }
        if (window.WebSocket) {
          that.socket = new WebSocket("ws://36.134.81.48:9034/websocket");
          that.socket.onmessage = function (event) {
          };
          that.socket.onopen = function (event) {
          };
          that.socket.onclose = function (event) {
          };
        } else {
          console.log("您的浏览器不支持WebSocket");
        }
        setTimeout(function () {
          if(!window.WebSocket){
            return;
          }
          if(that.socket.readyState == WebSocket.OPEN){
            that.socket.send(that.userId);
          }else{
            console.log("WebSocket连接没有建立成功!!");
          }
        }, 4000);
      axios({
        url: "/api/blade-jfpts/alarm/alarm/getLimit",
        method: "get",
@@ -375,15 +413,12 @@
          url: "/api/blade-jfpts/alarm/alarm/selecttx?id=" + that.deviceId,
          method: "post",
        }).then(function (response) {
          var userId = JSON.parse(
            window.localStorage.getItem("物联网安保云服务平台-userInfo")
          ).content.user_id;
          if (response.data.data.length > 0) {
            that.deviceId = response.data.data[0].id;
            if (
              response.data.data[0].waringType == "紧急求救" &&
              response.data.data[0].alarmId == userId
                response.data.data[0].alarmId == that.userId
            ) {
              response.data.data[0].waringType = "一键求助";
              that.form = response.data.data[0];