Parcourir la source

增加开关机属性

wzh il y a 2 ans
Parent
commit
87111fffc1
2 fichiers modifiés avec 290 ajouts et 86 suppressions
  1. 8 0
      api/device/device.js
  2. 282 86
      pages/device/detail.vue

+ 8 - 0
api/device/device.js

@@ -138,4 +138,12 @@ export function resetList(pageNum,pageSize,deviceName){
         method: 'get',
     })
 }
+//获取设备运行时间统计
+export function getDeviceRunTime(deviceid){
+    let url = '/iot/device/getDeviceRunTime/'+deviceid
+    return request({
+        url: url,
+        method: 'get',
+    })
+}
 

+ 282 - 86
pages/device/detail.vue

@@ -89,13 +89,26 @@
       ></u--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: 30%">
+      <view style="width: 20%">
         <u-button @click="openLocation(deviceInfo)" type="primary" size="mini" text="查看位置"></u-button>
 
 
@@ -152,95 +165,168 @@
 
       <view class="prop-container" style="background: white;padding:10px ">
         <u-form>
-          <u--text text="属性控制" style="margin-top:10px"></u--text>
-        <u-form-item   style="border:0px;position: relative" v-for="item in inputProp"
-                       :label="item.name"
-                       labelWidth="auto"
-                       :borderBottom="false"
-        >
-
-          <u-input  placeholder="请输入字符串" v-if="item.type === 'string'" v-model="item.shadow">
-            <template slot="suffix">
-              <u-button v-if="deviceInfo.status==3"
-                        @tap="send(item)"
-                        text="发送"
-                        type="success"
-                        size="mini"
-              ></u-button>
-              <u-button v-if="deviceInfo.status!=3"
-                        @tap="send(item)"
-                        text="发送"
-                        type="info"
-                        size="mini"
-              ></u-button>
-            </template>
-          </u-input>
-
-          <u-input placeholder="请输入整数" v-if="item.type === 'integer'"  v-model="item.shadow">
-            <template slot="suffix">
-              <u-button v-if="deviceInfo.status==3"
-                        @tap="send(item)"
-                        text="发送"
-                        type="success"
-                        size="mini"
-              ></u-button>
-              <u-button v-if="deviceInfo.status!=3"
-                        @tap="send(item)"
-                        text="发送"
-                        type="info"
-                        size="mini"
-              ></u-button>
-            </template>
-          </u-input>
-
-          <u-input placeholder="请使用英文逗号分隔的字符串" v-if="item.type === 'array'"  v-model="item.shadow">
-            <template slot="suffix">
-              <u-button v-if="deviceInfo.status==3"
-                        @tap="send(item)"
-                        text="发送"
-                        type="success"
-                        size="mini"
-              ></u-button>
-              <u-button v-if="deviceInfo.status!=3"
-                        @tap="send(item)"
-                        text="发送"
-                        type="info"
-                        size="mini"
-              ></u-button>
-            </template>
-          </u-input>
-
-        <view v-if="item.type === 'enum'" style="position: relative" >
-
-          <view @click="chooseItemData(item)" style="width:100%" v-if="item.text != null && item.text.length>0">{{ item.text }}</view>
-
-          <view @click="chooseItemData(item)" style="width:100%" v-else>请选择</view>
-          <u-button v-if="deviceInfo.status==3" customStyle="position: absolute;top: 8rpx;right: 20rpx;width: 13%;"
-                    @tap="send(item)"
-                    text="发送"
-                    type="success"
-                    size="mini"
-          ></u-button>
-
-        </view>
-
-        </u-form-item>
+          <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>
+
+         <view v-for="item in inputProp"  v-if="checkCommonProp(item)">
+           <uni-row class="demo-uni-row" v-if="item.type === 'integer'">
+             <uni-col :span="10">
+               <view class="item">{{item.name}}</view>
+             </uni-col>
+             <uni-col :span="10">
+               <view style="padding:0 10rpx">
+                 <u-input placeholder="请输入整数"   v-model="item.shadow">
+                 </u-input>
+               </view>
+             </uni-col>
+             <uni-col :span="4">
+               <view class="item" style="padding-top:14rpx">
+                 <u-button v-if="deviceInfo.status==3"
+                           @tap="send(item)"
+                           text="发送"
+                           type="success"
+                           size="mini"
+                 ></u-button>
+                 <u-button v-if="deviceInfo.status!=3"
+                           @tap="send(item)"
+                           text="发送"
+                           type="info"
+                           size="mini"
+                 ></u-button>
+               </view>
+             </uni-col>
+           </uni-row>
+
+
+           <uni-row class="demo-uni-row" v-if="item.type === 'string'">
+             <uni-col :span="10">
+               <view class="item">{{item.name}}</view>
+             </uni-col>
+             <uni-col :span="10">
+               <view style="padding:0 10rpx">
+                 <u-input  placeholder="请输入字符串"  v-model="item.shadow">
+                 </u-input>
+               </view>
+             </uni-col>
+             <uni-col :span="4">
+               <view class="item" style="padding-top:14rpx">
+                 <u-button v-if="deviceInfo.status==3"
+                           @tap="send(item)"
+                           text="发送"
+                           type="success"
+                           size="mini"
+                 ></u-button>
+                 <u-button v-if="deviceInfo.status!=3"
+                           @tap="send(item)"
+                           text="发送"
+                           type="info"
+                           size="mini"
+                 ></u-button>
+               </view>
+             </uni-col>
+           </uni-row>
+
+
+           <uni-row class="demo-uni-row" v-if="item.type === 'array'">
+             <uni-col :span="10">
+               <view class="item">{{item.name}}</view>
+             </uni-col>
+             <uni-col :span="10">
+               <view style="padding:0 10rpx">
+                 <u-input  placeholder="请使用英文逗号分隔的字符串"  v-model="item.shadow">
+                 </u-input>
+               </view>
+             </uni-col>
+             <uni-col :span="4">
+               <view class="item" style="padding-top:14rpx">
+                 <u-button v-if="deviceInfo.status==3"
+                           @tap="send(item)"
+                           text="发送"
+                           type="success"
+                           size="mini"
+                 ></u-button>
+                 <u-button v-if="deviceInfo.status!=3"
+                           @tap="send(item)"
+                           text="发送"
+                           type="info"
+                           size="mini"
+                 ></u-button>
+               </view>
+             </uni-col>
+           </uni-row>
+
+           <uni-row class="demo-uni-row" v-if="item.type === 'enum'">
+             <uni-col :span="10">
+               <view class="item">{{item.name}}</view>
+             </uni-col>
+             <uni-col :span="10">
+               <view style="padding:0 10rpx">
+
+                 <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>
+             </uni-col>
+             <uni-col :span="4">
+               <view class="item" style="padding-top:14rpx">
+                 <u-button v-if="deviceInfo.status==3"
+                           @tap="send(item)"
+                           text="发送"
+                           type="success"
+                           size="mini"
+                 ></u-button>
+                 <u-button v-if="deviceInfo.status!=3"
+                           @tap="send(item)"
+                           text="发送"
+                           type="info"
+                           size="mini"
+                 ></u-button>
+               </view>
+             </uni-col>
+           </uni-row>
+
+
+
+
+         </view>
 
           <u-line></u-line>
-          <u--text text="属性监控" style="margin-top:10px"></u--text>
+          <u--text text="属性监控" style="margin-top:20px"></u--text>
 
           <view>
 
-            <u-form-item   style="border:0px" v-for="item in deviceInfo.readOnlyList"
-                           :label="item.name"
-                           labelWidth="auto"
-                           :borderBottom="false"
-            >
-              <u-input  placeholder="请输入字符串" disabled=""  :value="item.shadow+' '+item.unit">
-              </u-input>
-
-            </u-form-item>
 
+            <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>
@@ -254,12 +340,22 @@
 
         </view>
       </u-modal>
+
+      <u-modal  :show="showTimeDlg" title="查看时长"  @confirm="closeTime" >
+        <view class="slot-content">
+            <view v-if="timeobj!=null && deviceInfo.status == 3">本次运行时长:{{ timeobj.runtime }}</view>
+          <view v-if="timeobj!=null ">累计时长:{{ timeobj.alltime }}</view>
+
+             <view v-if="timeobj!=null ">平均每天运行时长:{{ timeobj.avgtime }}</view>
+
+        </view>
+      </u-modal>
     </view>
   </view>
 </template>
 
 <script>
-import { getDetail,getDeviceStatus,cacheJsonThingsModel,reportError } from '@/api/device/device.js'
+import { getDetail,getDeviceStatus,cacheJsonThingsModel,reportError ,getDeviceRunTime} from '@/api/device/device.js'
 import UButton from "../../uni_modules/uview-ui/components/u-button/u-button";
 import UForm from "../../uni_modules/uview-ui/components/u--form/u--form";
 import UInput from "../../uni_modules/uview-ui/components/u--input/u--input";
@@ -267,6 +363,16 @@ export default {
   components: {UInput, UForm, UButton},
   data(){
       return {
+        modelKey:['PowerControl','LockControl'],
+        power:{
+          loading:true,
+          value:0,
+        },
+        lock:{
+          loading:true,
+          value:0,
+        },
+        showTimeDlg:false,
         showErrDlg:null,
         errorMsg:"",
         show:null,
@@ -282,6 +388,7 @@ export default {
         columns:[],
         location:{},
         sysDept:null,
+        timeobj:null,
       }
   },
   onLoad: function(opt) {
@@ -294,6 +401,45 @@ export default {
     this.mqttUnSubscribe(this.deviceInfo);
   },
   methods:{
+    changeProp(key){
+      let item = null;
+      let obj = null;
+        if(key === "LockControl"){
+          item = this.lock;
+        }else if(key === "PowerControl"){
+          item =  this.power;
+        }
+      let value = item.value;
+      obj = item.item;
+       if(value){
+         obj.value = 1;
+         obj.shadow = 1;
+       }else{
+         obj.value = 0;
+         obj.shadow = 0;
+       }
+       this.publishThingsModel(this.deviceInfo,obj);
+    },
+    checkCommonProp(item){
+      let id =item.id;
+      let isCommonKey = this.modelKey.some(res=>{
+        return id === res;
+      })
+      return !isCommonKey;
+    },
+    getRunTime(){
+      let self = this;
+      getDeviceRunTime(this.id).then(res=>{
+        self.timeobj = res.data;
+      })
+    },
+    seeTime(){
+      this.showTimeDlg = true;
+      this.getRunTime();
+    },
+    closeTime(){
+      this.showTimeDlg = false;
+    },
     cancel(){
       this.showErrDlg = false;
     },
@@ -391,6 +537,50 @@ export default {
             self.parseStatusData(data)
       });
     },
+    parseEnumList(){
+      let enumList = this.deviceInfo.enumList;
+      for (let enumListElement of enumList) {
+        let id = enumListElement.id;
+        let isCommonKey = this.modelKey.some(res=>{
+          return id === res;
+        })
+        if(isCommonKey){
+          if(id.indexOf("LockControl") !=-1){
+            let shadow = enumListElement.shadow;
+            this.lock.item = enumListElement;
+            if(shadow == 1){
+              this.lock.value  = true;
+              this.lock.loading = false;
+            }else if(shadow == 0){
+              this.lock.value  = false;
+              this.lock.loading = false;
+            }else{
+              this.lock.loading = true;
+            }
+          }
+          if(id.indexOf("PowerControl") !=-1){
+            let shadow = enumListElement.shadow;
+            this.power.item = enumListElement;
+            if(shadow == 1){
+              this.power.value  = true;
+              this.power.loading = false;
+            }else if(shadow == 0){
+              this.power.value  = false;
+              this.power.loading = false;
+            }else{
+              this.power.loading = true;
+            }
+          }
+        }
+        let shadow = enumListElement.shadow
+        let valueList = enumListElement.enumList;
+        for (let valueObj of valueList){
+          if(valueObj.value == shadow){
+            enumListElement.text = valueObj.text;
+          }
+        }
+      }
+    },
     parseStatusData(data){
       let arr = [];
       let arrayList = data.arrayList;
@@ -405,7 +595,7 @@ export default {
 
       let readOnlyList = data.readOnlyList;
       this.watchProp = readOnlyList;
-
+      this.parseEnumList();
     },
     parseSummay(summary){
       let self = this;
@@ -580,6 +770,7 @@ export default {
                 }
               }
             }
+            this.parseEnumList();
           }
         }
       });
@@ -723,4 +914,9 @@ export default {
   font-size: 36rpx;
   color: #8f8f94;
 }
+.item{
+
+  height: 80rpx;
+  line-height: 80rpx;
+}
 </style>