Przeglądaj źródła

fix(修复整数)

wzh 2 lat temu
rodzic
commit
767c8fc022
1 zmienionych plików z 28 dodań i 13 usunięć
  1. 28 13
      pages/device/detail.vue

+ 28 - 13
pages/device/detail.vue

@@ -197,7 +197,7 @@
                     <view class="prop-item-left">{{item.name}}</view>
                     <view class="prop-item-right">
                       <view v-if="item.type === 'integer'" style="width:240rpx;position: absolute;top: 10rpx;;">
-                        <u-input :customStyle="inputStyle" fontSize="20rpx"  placeholder="请输入整数"   v-model="item.shadow">
+                        <u-input :customStyle="inputStyle" fontSize="20rpx" type="number" placeholder="请输入整数"   v-model="item.shadow">
                         </u-input>
                       </view>
                       <view style="width:240rpx;position: absolute;top:0rpx;" v-if="item.type === 'string'">
@@ -378,7 +378,7 @@ export default {
   destroyed() {
     // 取消订阅主题
     this.mqttUnSubscribe(this.deviceInfo);
-    clearInterval(this.checkTimer);
+    clearTimeout(this.checkTimer);
   },
   methods:{
     // 抽屉状态发生变化触发
@@ -423,7 +423,7 @@ export default {
           arr.push(functionObj);
         }
       }
-      this.mqttPublish(1,this.deviceInfo,arr)
+      this.mqttPublish(2,this.deviceInfo,arr)
     },
     changeProp(key,val){
       let item = null;
@@ -537,7 +537,6 @@ export default {
         })
         return;
       }
-      debugger;
       this.publishThingsModel(this.deviceInfo,this.inputProp.map(item=>{return{"id":item.id,"value":item.value}}))
     },
     /** 更新设备状态 */
@@ -574,9 +573,11 @@ export default {
       let self = this;
       if(!e){
         e = {index:0};
+        this.childId = 0;
+      }else{
+        this.activeName = e.index;
+        this.childId = this.summary[this.activeName].id;
       }
-      this.activeName = e.index;
-      this.childId = this.summary[this.activeName].id;
       getDeviceStatus(this.id,this.childId).then(res=>{
         let data =res.data;
         this.deviceInfo = data;
@@ -927,9 +928,25 @@ export default {
           if(oneToMul){
             let info = this.summary[this.activeName];
             let childId = info.id;
-            modelId = modelId+"_"+childId;
+            if(childId){
+              modelId = modelId+"_"+childId;
+            }
+
           }
-          arr.push({id:modelId,value:modelList[i].shadow});
+          let shadow = model.shadow;
+          let modelType = model.type;
+          let shadowInt = parseInt(shadow,10);
+          let isNumber = false;
+          let shadowStr = shadowInt+"";
+          if(shadowStr === shadow){
+            isNumber = true;
+            shadow = shadowInt;
+          }
+          if(modelType == "integer" && !isNumber){
+            this.$modal.showToast(model.name+'的值必须是数字类型')
+            return;
+          }
+          arr.push({id:modelId,value:shadow});
         }
         message = JSON.stringify(arr);
         let self = this;
@@ -942,11 +959,9 @@ export default {
     },
     startCheck(){
       let self = this;
-      if(this.checkTimer!= null){
-        return;
-      }
-      this.checkTimer = setInterval(function (){
+      this.checkTimer = setTimeout(function (){
         self.sendHeart();
+        self.startCheck();
       },20000);
     },
     checkActive(){
@@ -958,7 +973,7 @@ export default {
       },3000);
     },
     sendHeart(){
-      console.log("发送心跳")
+      console.log("发送心跳111")
       let device = this.deviceInfo;
       let self = this;
       let topic = "/property-offline/post";