瀏覽代碼

增加一键批量发送属性功能

wzh 2 年之前
父節點
當前提交
6b55aab53c
共有 1 個文件被更改,包括 134 次插入237 次删除
  1. 134 237
      pages/device/detail.vue

+ 134 - 237
pages/device/detail.vue

@@ -191,8 +191,47 @@
               <!--                 ></u-button>-->
               <!--               </view>-->
               <scroll-view style="height: 88%;" scroll-y="true">
+                <view style="margin-top:20rpx;margin-left:20rpx" v-if="properties.length>0">属性区</view>
+                <view v-for="item in properties"  v-if="checkCommonProp(item)">
+                  <view class="prop-item">
+                    <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>
+                      </view>
+                      <view style="width:240rpx;position: absolute;top:0rpx;" v-if="item.type === 'string'">
+                        <u-input :customStyle="inputStyle" fontSize="20rpx"  placeholder="请输入字符串"  v-model="item.shadow">
+                        </u-input>
+                      </view>
+                      <view style="width:240rpx;position: absolute;top: 0rpx;" v-if="item.type === 'array'">
+                        <u-input :customStyle="inputStyle" fontSize="20rpx" placeholder="请使用英文逗号分隔的字符串"  v-model="item.shadow">
+                        </u-input>
+                      </view>
+                      <view style="padding:0 10rpx;position: absolute;top: -10rpx;left: -40rpx;" v-if="item.type === 'enum'">
 
-                <view v-for="item in inputProp"  v-if="checkCommonProp(item)">
+                        <u-cell customStyle="border:0px;" size="mini" @click="chooseItemData(item)" arrow-direction="left" v-if="item.text != null && item.text.length>0" :title="item.text">
+                          <u-icon slot="icon" size="12" name="arrow-down"></u-icon>
+
+                        </u-cell>
+
+                        <u-cell customStyle="border:0px;" size="mini" @click="chooseItemData(item)" arrow-direction="down" v-else title="请选择">
+                          <u-icon slot="icon" size="12" name="arrow-down"></u-icon>
+
+                        </u-cell>
+
+                      </view>
+
+                    </view>
+                  </view>
+                </view>
+                <view v-if="properties.length>0">
+                  <button style="width: 30%; height: 58rpx;
+    margin-top: 20rpx;    float: right;
+    margin-right: 140rpx;" @click="sendProperties" class="login-btn cu-btn block bg-blue lg round send_btn">发送</button>
+                </view>
+                <view style="margin-top:20rpx;margin-left:20rpx" v-if="functions.length>0">功能区</view>
+                <view v-for="item in functions"  v-if="checkCommonProp(item)">
                   <view class="prop-item">
                     <view class="prop-item-left">{{item.name}}</view>
                     <view class="prop-item-right">
@@ -226,10 +265,10 @@
                   </view>
                 </view>
 
-                <view>
+                <view v-if="functions.length>0">
                   <button style="width: 30%; height: 58rpx;
     margin-top: 20rpx;    float: right;
-    margin-right: 140rpx;" @click="send" class="login-btn cu-btn block bg-blue lg round send_btn">发送</button>
+    margin-right: 140rpx;" @click="sendFunctions" class="login-btn cu-btn block bg-blue lg round send_btn">发送</button>
                 </view>
 
                 <view style="margin-top:20rpx;margin-left:20rpx">
@@ -261,205 +300,7 @@
 
       </view>
 
-      <!--  <u&#45;&#45;form>-->
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                   label="设备名称:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--    >-->
-      <!--      <u&#45;&#45;input disabled-->
-      <!--                placeholder="请选择分组"-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                v-model="deviceInfo.deviceName"-->
-      <!--      ></u&#45;&#45;input>-->
-      <!--    </u-form-item>-->
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                   label="所属机构:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--    >-->
-      <!--      <u&#45;&#45;input v-if="sysDept != null" disabled-->
-      <!--                placeholder="请选择分组22"-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                :value="sysDept.deptName"-->
-      <!--      ></u&#45;&#45;input>-->
-
-      <!--      <u&#45;&#45;input v-else-if="deviceInfo.deptId == -1" disabled-->
-      <!--                placeholder="请选择分组11"-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                value="已注销"-->
-      <!--      ></u&#45;&#45;input>-->
-      <!--      <u&#45;&#45;input v-else disabled-->
-      <!--                placeholder="未绑定"-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                value="未绑定"-->
-      <!--      ></u&#45;&#45;input>-->
-      <!--    </u-form-item>-->
-
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                   label="设备编号:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--                   ref="item1"-->
-      <!--    >-->
-      <!--      <u&#45;&#45;input disabled-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                v-model="deviceInfo.serialNumber"-->
-      <!--      ></u&#45;&#45;input>-->
-      <!--    </u-form-item>-->
-
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                   label="二维码ID:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--                   ref="item1"-->
-      <!--    >-->
-      <!--      <u&#45;&#45;input disabled-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                v-model="deviceInfo.qrcodeId"-->
-      <!--      ></u&#45;&#45;input>-->
-      <!--    </u-form-item>-->
-
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                   label="激活时间:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--                   ref="item1"-->
-      <!--    >-->
-      <!--      <u&#45;&#45;input disabled-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                :value="deviceInfo.activeTime"-->
-      <!--      ></u&#45;&#45;input>-->
-      <!--    </u-form-item>-->
-
-
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                  label="运行时长:"-->
-      <!--                  labelWidth="auto"-->
-      <!--                  :borderBottom="false"-->
-      <!--                  ref="item1"-->
-      <!--    >-->
-      <!--      <view style="width: 20%">-->
-      <!--        <u-button @click="seeTime()" type="primary" size="mini" text="查看时长"></u-button>-->
-      <!--      </view>-->
-      <!--    </u-form-item>-->
-
-
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                   label="位置信息:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--                   ref="item1"-->
-      <!--    >-->
-      <!--      <view style="width: 20%">-->
-      <!--        <u-button @click="openLocation(deviceInfo)" type="primary" size="mini" text="查看位置"></u-button>-->
-
-
-      <!--      </view>-->
-      <!--    </u-form-item>-->
-
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                   label="设备信号:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--    >-->
-      <!--      <u&#45;&#45;input disabled-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                :value="deviceInfo.rssi"-->
-      <!--      ></u&#45;&#45;input>-->
-      <!--    </u-form-item>-->
-
-      <!--    <u-form-item v-if="deviceInfo.networkAddress != null"   style="border:0px"-->
-      <!--                   label="设备网络:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--                   ref="item1"-->
-      <!--    >-->
-      <!--      <u&#45;&#45;input disabled-->
-      <!--                border="none"-->
-      <!--                color="gray"-->
-      <!--                disabledColor="white"-->
-      <!--                :value="deviceInfo.networkAddress+'('+deviceInfo.networkIp+')'"-->
-      <!--      ></u&#45;&#45;input>-->
-      <!--    </u-form-item>-->
-
-      <!--    <u-form-item   style="border:0px"-->
-      <!--                   label="设备状态:"-->
-      <!--                   labelWidth="auto"-->
-      <!--                   :borderBottom="false"-->
-      <!--    >-->
-      <!--       <view style="width:90rpx">-->
-      <!--         <u-tag v-if="deviceInfo.status === 4" text="离线"  size="mini" type="info"></u-tag>-->
-      <!--         <u-tag v-if="deviceInfo.status === 3" text="在线"  size="mini" type="success"></u-tag>-->
-      <!--         <u-tag v-if="deviceInfo.status === 2" text="禁用"  size="mini" type="error"></u-tag>-->
-      <!--         <u-tag v-if="deviceInfo.status === 1" text="未激活"  size="mini" type="error"></u-tag>-->
-
-      <!--       </view>-->
-
-      <!--    </u-form-item>-->
-
-
-      <!--  </u&#45;&#45;form>-->
-      <!--    </view>-->
-      <!--    <view class="text-area">-->
-      <!--      <u-tabs :list="summary" keyName="tabName" @change="getDeviceStatus"></u-tabs>-->
-
-      <!--      <view class="prop-container" style="background: white;padding:10px ">-->
-      <!--        <u-form>-->
-      <!--          <u-form-item   style="border:0px;position: relative"-->
-      <!--                         label=" "-->
-      <!--                         labelWidth="auto"-->
-      <!--                         :borderBottom="false"-->
-      <!--          >-->
-      <!--            <uni-row class="demo-uni-row">-->
-      <!--              <uni-col :span="12">-->
-      <!--                开机: <u-switch v-model="power.value" :loading ="power.loading" @change="changeProp('PowerControl')"></u-switch>-->
-      <!--              </uni-col>-->
-      <!--              <uni-col :span="12">-->
-      <!--                锁定: <u-switch v-model="lock.value" :loading ="lock.loading" @change="changeProp('LockControl')"></u-switch>-->
-      <!--              </uni-col>-->
-      <!--            </uni-row>-->
-
-      <!--          </u-form-item>-->
-
-
-
-      <!--          <u-line></u-line>-->
-      <!--          <view>-->
-
-
-      <!--            <uni-row class="demo-uni-row"  v-if="checkCommonProp(item)"  v-for="item in deviceInfo.readOnlyList">-->
-      <!--              <uni-col :span="10">-->
-      <!--                <view class="item">{{item.name}}</view>-->
-      <!--              </uni-col>-->
-      <!--              <uni-col :span="10">-->
-      <!--                <view style="padding:0 10rpx">-->
-      <!--                  <u-input  placeholder="请输入字符串" disabled=""  :value="item.shadow+' '+item.unit">-->
-      <!--                  </u-input>-->
-      <!--                </view>-->
-      <!--              </uni-col>-->
-      <!--            </uni-row>-->
-
-      <!--          </view>-->
-      <!--        </u-form>-->
-
-      <!--      </view>-->
+
       <u-picker @cancel="show=null" :show="show!=null" :columns="columns" @confirm="confirmItemData" keyName="text"></u-picker>
       <u-modal @cancel="cancel" :show="showErrDlg" title="异常上报" :showCancelButton="true" @confirm="doReportError" >
         <view class="slot-content">
@@ -524,6 +365,8 @@ export default {
       timeobj:{alltime:0,avgtime:0},
       publishMsg:false,
       checkTimer:null,
+      functions:[],
+      properties:[]
     }
   },
   onLoad: function(opt) {
@@ -558,6 +401,30 @@ export default {
       }
       return true;
     },
+    sendProperties(){
+      let properties = this.properties;
+      for (let i = 0; i < properties; i++) {
+        let property = this.properties[i];
+        let shadow = property.shadow;
+        if(shadow){
+          arr.push(property);
+        }
+      }
+      this.mqttPublish(1,this.deviceInfo,arr)
+    },
+
+    sendFunctions(){
+      let arr = [];
+      let functions = this.functions;
+      for (let i = 0; i < functions.length; i++) {
+        let functionObj = this.functions[i];
+        let shadow = functionObj.shadow;
+        if(shadow){
+          arr.push(functionObj);
+        }
+      }
+      this.mqttPublish(1,this.deviceInfo,arr)
+    },
     changeProp(key,val){
       let item = null;
       let obj = null;
@@ -652,9 +519,9 @@ export default {
       this.inputProp.forEach((item)=>{
         _arr.push(item.value)
       })
-      if(_arr.some(val => val === '' || val.length < 0)){
-        shadow = true
-      }
+      // if(_arr.some(val => val === '' || val.length < 0)){
+      //   shadow = true
+      // }
       if(this.deviceInfo.status != 3){
         uni.showToast({
           title:"设备暂未上线",
@@ -670,6 +537,7 @@ export default {
         })
         return;
       }
+      debugger;
       this.publishThingsModel(this.deviceInfo,this.inputProp.map(item=>{return{"id":item.id,"value":item.value}}))
     },
     /** 更新设备状态 */
@@ -760,20 +628,40 @@ export default {
       }
     },
     parseStatusData(data){
-      let arr = [];
-      let arrayList = data.arrayList;
-      arr = arr.concat(arrayList);
-      let enumList = data.enumList;
-      arr = arr.concat(enumList);
-      let integerList = data.integerList;
-      arr = arr.concat(integerList);
-      let stringList = data.stringList;
-      arr = arr.concat(stringList);
-      this.inputProp = arr;
-
-      let readOnlyList = data.readOnlyList;
-      this.watchProp = readOnlyList;
-      this.parseEnumList();
+      let self = this;
+      cacheJsonThingsModel(data.productId).then(res=>{
+        let thingsModel = JSON.parse(res.data);
+        let arr = [];
+        let arrayList = data.arrayList;
+        arr = arr.concat(arrayList);
+        let enumList = data.enumList;
+        arr = arr.concat(enumList);
+        let integerList = data.integerList;
+        arr = arr.concat(integerList);
+        let stringList = data.stringList;
+        arr = arr.concat(stringList);
+        self.inputProp = arr;
+        for (let i = 0; i < thingsModel.functions.length; i++) {
+          for (let j = 0; j < arr.length; j++) {
+            let model = arr[j];
+            if(model.id == thingsModel.functions[i].id){
+                self.functions.push(model);
+            }
+          }
+        }
+          for (let i = 0; i < thingsModel.properties.length; i++) {
+            for (let j = 0; j < arr.length; j++) {
+              let model = arr[j];
+              if(model.id == thingsModel.properties[i].id){
+                self.properties.push(model);
+              }
+            }
+          }
+        let readOnlyList = data.readOnlyList;
+        self.watchProp = readOnlyList;
+        self.parseEnumList();
+      })
+
     },
     parseSummay(summary){
       let self = this;
@@ -975,7 +863,7 @@ export default {
           }
         }
         if (type != 0) {
-          this.mqttPublish(type, device, model);
+          this.mqttPublish(type, device, [model]);
         }
       });
     },
@@ -997,49 +885,55 @@ export default {
      * @device 设备
      * @model 物模型
      * */
-    mqttPublish(type, device, model) {
+    mqttPublish(type, device, modelList) {
+      if(modelList.length == 0){
+        return;
+      }
       let topic = "";
       let message = ""
       let oneToMul = false;
       if(this.summary.length>0){
         oneToMul = true;
       }
-      let modelId = model.id;
-      if(oneToMul){
-        let info = this.summary[this.activeName];
-        let childId = info.id;
-        modelId = modelId+"_"+childId;
-      }
       if (type == 1) {
         if (device.status == 3) {
           // 属性,在线模式
           topic = "/" + device.productId + "/" + device.serialNumber + "/property-online/get";
-        } else if (device.isShadow) {
-          // 属性,离线模式
-          topic = "/" + device.productId + "/" + device.serialNumber + "/property-offline/post";
         }
-        message = '[{"id":"' + modelId + '","value":"' + model.shadow + '"}]';
       } else if (type == 2) {
         if (device.status == 3) {
           // 功能,在线模式
           topic = "/" + device.productId + "/" + device.serialNumber + "/function-online/get";
 
-        } else if (device.isShadow) {
-          // 功能,离线模式
-          topic = "/" + device.productId + "/" + device.serialNumber + "/function-offline/post";
         }
-        message = '[{"id":"' + modelId + '","value":"' + model.shadow + '"}]';
       } else if (type == 3) {
         // OTA升级
         topic = "/" + device.productId + "/" + device.serialNumber + "/ota/get";
-        message = '{"version":' + this.firmware.version + ',"downloadUrl":"' + this.getDownloadUrl(this.firmware.filePath) + '"}';
       } else {
         return;
       }
+      let title = "";
+      if(type == 1){
+        title = "属性";
+      }else if(type == 2){
+        title = "功能";
+      }
       if (topic != "") {
         // 发布
+        let arr = [];
+        for (let i = 0; i <modelList.length; i++) {
+          let model = modelList[i];
+          let modelId = model.id;
+          if(oneToMul){
+            let info = this.summary[this.activeName];
+            let childId = info.id;
+            modelId = modelId+"_"+childId;
+          }
+          arr.push({id:modelId,value:modelList[i].shadow});
+        }
+        message = JSON.stringify(arr);
         let self = this;
-        this.$mqttTool.publish(topic, message, model.name).then(res => {
+        this.$mqttTool.publish(topic, message,title).then(res => {
           this.notifySuccess(res);
         }).catch(res => {
           this.notifyError(res);
@@ -1048,6 +942,9 @@ export default {
     },
     startCheck(){
       let self = this;
+      if(this.checkTimer!= null){
+        return;
+      }
       this.checkTimer = setInterval(function (){
         self.sendHeart();
       },20000);