Преглед на файлове

1.通讯页面增加心跳机制-防止自动短线
2.todo OSS调整

wzh преди 2 години
родител
ревизия
043ae8fdb5
променени са 6 файла, в които са добавени 80 реда и са изтрити 4 реда
  1. 1 0
      config.js
  2. 41 2
      pages/device/detail.vue
  3. 37 1
      pages/device/index.vue
  4. 1 1
      pages/login.vue
  5. BIN
      static/images/device/bg.png
  6. BIN
      static/images/login/bg.png

+ 1 - 0
config.js

@@ -3,6 +3,7 @@ module.exports = {
   //baseUrl: 'https://vue.ruoyi.vip/prod-api',
   baseUrl: 'https://yun.dnzc.vip',
   //baseUrl: 'http://127.0.0.1:8991',
+  imgUrl:"https://hyscancode.oss-cn-hangzhou.aliyuncs.com/jianyaoji",
   // 应用信息
   appInfo: {
     // 应用名称

+ 41 - 2
pages/device/detail.vue

@@ -2,7 +2,7 @@
   <view class="content">
     <view class="header" style="margin:0;padding: 0px;">
 
-      <view class="bg" style="position: fixed;top:0px;bottom:0px;left:0px;right:0px;background-image: url('/static/images/device/bg.png');background-size: 100% 100%;padding:0 40rpx">
+      <view class="bg" style="position: fixed;top:0px;bottom:0px;left:0px;right:0px;background-image: url('https://hyscancode.oss-cn-hangzhou.aliyuncs.com/jianyaoji/images/device/bg.png');background-size: 100% 100%;padding:0 40rpx">
         <view style="position: absolute;right:10rpx;top:30rpx;z-index: 9999">
           <u-button @click="reportError" color="#EC6D2F" text="上报异常" type="error" size="mini"></u-button>
         </view>
@@ -408,17 +408,20 @@ export default {
         location:{},
         sysDept:null,
         timeobj:{alltime:0,avgtime:0},
+        publishMsg:false,
+        checkTimer:null,
       }
   },
   onLoad: function(opt) {
     this.id = opt.id;
-    this.id = 61;
+    // this.id = 61;
    this.connectMqtt();
     this.getDetail();
   },
   destroyed() {
     // 取消订阅主题
     this.mqttUnSubscribe(this.deviceInfo);
+    clearInterval(this.checkTimer);
   },
   methods:{
     checkItemValue(item){
@@ -666,6 +669,7 @@ export default {
         await this.$mqttTool.connect(this.vuex_token);
       }
       this.mqttCallback();
+      this.startCheck();
     },
     /** Mqtt订阅主题 */
     mqttSubscribe(device) {
@@ -895,6 +899,7 @@ export default {
       }
       if (topic != "") {
         // 发布
+        let self = this;
         this.$mqttTool.publish(topic, message, model.name).then(res => {
           this.notifySuccess(res);
         }).catch(res => {
@@ -902,6 +907,40 @@ export default {
         });
       }
     },
+    startCheck(){
+      let self = this;
+        this.checkTimer = setInterval(function (){
+          self.sendHeart();
+        },20000);
+    },
+    checkActive(){
+      let self = this;
+      setTimeout(function (){
+        if(self.publishMsg){
+          self.resetConn()
+        }
+      },3000);
+    },
+    sendHeart(){
+      console.log("发送心跳")
+      let device = this.deviceInfo;
+      let self = this;
+      let topic = "/property-offline/post";
+      self.publishMsg = true;
+      self.checkActive();
+      this.$mqttTool.publish(topic, "ok", "heart").then(res => {
+        self.publishMsg = false;
+      }).catch(res => {
+        self.publishMsg = false;
+      });
+    },
+    resetConn(){
+      console.log("检测异常,重连")
+      this.$mqttTool.end();
+      this.$mqttTool.client = null;
+      this.connectMqtt();
+      this.getDetail();
+    }
 
   }
 }

+ 37 - 1
pages/device/index.vue

@@ -22,7 +22,7 @@
 
             </view>
             <view style="position: absolute;right:20rpx;top:24rpx;display: flex;flex-direction: column;">
-              <view v-if="item.status == 2">
+              <view v-if="item.status == 3">
                 <u-image :showLoading="true" src="/static/images/device/online.png" width="60rpx" height="60rpx" ></u-image>
                 <view style="color:#48C373;font-size: 20rpx;text-align: center">在线</view>
               </view>
@@ -77,6 +77,7 @@ export default {
   destroyed() {
     // 取消订阅主题
     this.mqttUnSubscribe(this.deviceList);
+    clearInterval(this.checkTimer);
   },
   methods:{
     goDeviceDetail(item){
@@ -130,6 +131,7 @@ export default {
       }
       this.mqttCallback();
       this.listDevice();
+      this.startCheck();
     },
     /* Mqtt回调处理  */
     mqttCallback() {
@@ -279,6 +281,40 @@ export default {
       }
       console.log('取消订阅', topics);
       this.$mqttTool.unsubscribe(topics);
+    },
+    startCheck(){
+      let self = this;
+      this.checkTimer = setInterval(function (){
+        self.sendHeart();
+      },20000);
+    },
+    checkActive(){
+      let self = this;
+      setTimeout(function (){
+        if(self.publishMsg){
+          self.resetConn()
+        }
+      },3000);
+    },
+    sendHeart(){
+      console.log("发送心跳")
+      let device = this.deviceInfo;
+      let self = this;
+      let topic = "/property-offline/post";
+      self.publishMsg = true;
+      self.checkActive();
+      this.$mqttTool.publish(topic, "ok", "heart").then(res => {
+        self.publishMsg = false;
+      }).catch(res => {
+        self.publishMsg = false;
+      });
+    },
+    resetConn(){
+      console.log("检测异常,重连")
+      this.$mqttTool.end();
+      this.$mqttTool.client = null;
+      this.connectMqtt();
+      this.getDetail();
     }
 
   }

+ 1 - 1
pages/login.vue

@@ -1,5 +1,5 @@
 <template>
-  <view class="normal-login-container" style="background-image: url('/static/images/login/bg.png');background-size: 100% 100%;">
+  <view class="normal-login-container" style="background-image: url('https://hyscancode.oss-cn-hangzhou.aliyuncs.com/jianyaoji/images/login/bg.png');background-size: 100% 100%;">
     <view class="logo-content align-center justify-center flex">
 <!--      <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">-->
 <!--      </image>-->

BIN
static/images/device/bg.png


BIN
static/images/login/bg.png