hxz 2 vuotta sitten
vanhempi
commit
8eb0a2bb01
4 muutettua tiedostoa jossa 282 lisäystä ja 94 poistoa
  1. 2 0
      api/device.js
  2. 229 60
      pages/loop/loop.js
  3. 25 17
      pages/loop/loop.wxml
  4. 26 17
      utils/loop.js

+ 2 - 0
api/device.js

@@ -10,6 +10,8 @@ module.exports = {
   delDevice: (Device) => request('/devices?id=' + Device,'DELETE'),
   //获取回路参数
   getloop:(Device) => request('/devices/relays?id=' + Device,'GET'),
+  //配置回路参数
+  postloop:(params) => request('/devices/relays','POST',params),
   //控制回路开关
   loopSwitch:(params) => request('/devices/operation','POST',params),
   //获取回路的开关状态

+ 229 - 60
pages/loop/loop.js

@@ -1,8 +1,5 @@
-const {
-  getBasic,
-  getData,
-  postData
-} = require('../../api/intell')
+const {getBasic,getData,postData,} = require('../../api/intell')
+const {getDevice, getloop} = require('../../api/device')
 const enloop = require('../../utils/loop')
 // pages/loop/loop.js
 Page({
@@ -72,12 +69,14 @@ Page({
     deviceKey: '',
     num: 0, //记录回路数量
     play: 0, //新老设备的页面切换
-    timeValue: ['00:00', '00:00'],
-    endTimeValue: ['00:00', '00:00'],
-    lightstartTime: '00:00',
-    lightendTime: '00:00',
+    //新设备数据
+    timeValue: ['00:00', '00:00','00:00','00:00','00:00','00:00'],
     weather: ['晴天', '雨天', '阴天', '黑夜'],
-    wIndex: 0
+    wIndex: 0,
+    newcolor:["#888888","#888888","#888888"],
+    newfont:["#cccccc","#cccccc","#cccccc"],
+    newSwitch:[false,false,false],
+    newSwitchstate:["","",""],
   },
   //分组下拉
   changegroup: function (e) {
@@ -1716,7 +1715,7 @@ Page({
     })
   },
   //时间调控
-  //时控开关选择器
+  //时控开关选择器(1-4旧设备,5-6新设备)
   Controltime1: function () {
     var obtain1 = this.data.state
     obtain1[0] = !obtain1[0]
@@ -1793,6 +1792,25 @@ Page({
       })
     }
   },
+  Controltime5:function(){
+    console.log(2131131)
+    let newSwitch = this.data.newSwitch
+    let newcolor = this.data.newcolor
+    let newfont = this.data.newfont
+    let newSwitchstate =this.data.newSwitchstate
+    newSwitch[0] = !newSwitch[0]
+    if(newSwitch[0] == true){
+      newcolor[0] = "blue"
+      newfont[0] = "white"
+      newSwitchstate[0] = "time"
+    }
+    else{
+      newcolor[0] = "#888888"
+      newfont[0] = "#cccccc"
+      newSwitchstate[0] = ""
+    }
+    that.setData({newSwitch:newSwitch,newcolor:newcolor,newfont,newfont,newSwitchstate:newSwitchstate})
+  },
   //固定与经纬的切换
   change1: function () {
     var change1 = this.data.fixed1
@@ -1842,34 +1860,56 @@ Page({
       })
     }
   },
-  //显示改变后的时间的值
+  //显示改变后的时间的值(1-4旧设备,5-10新设备)
   bindTimeChange1: function (e) {
-    var time1 = this.data.time
-    time1[0] = e.detail.value
-    this.setData({
-      time: time1
-    })
+    let time = this.data.time
+    time[0] = e.detail.value
+    this.setData({time: time})
   },
   bindTimeChange2: function (e) {
-    var time2 = this.data.time
-    time2[1] = e.detail.value
-    this.setData({
-      time: time2
-    })
+    let time = this.data.time
+    time[1] = e.detail.value
+    this.setData({time: time})
   },
   bindTimeChange3: function (e) {
-    var time3 = this.data.time
-    time3[2] = e.detail.value
-    this.setData({
-      time: time3
-    })
+    let time = this.data.time
+    time[2] = e.detail.value
+    this.setData({time: time})
   },
   bindTimeChange4: function (e) {
-    var time4 = this.data.time
-    time4[3] = e.detail.value
-    this.setData({
-      time: time4
-    })
+    let time = this.data.time
+    time[3] = e.detail.value
+    this.setData({time: time})
+  },
+  bindTimeChange5:function(e){
+    let time = this.data.timeValue
+    time[0] = e.detail.value
+    this.setData({timeValue:time})
+  },
+  bindTimeChange6:function(e){
+    let time = this.data.timeValue
+    time[1] = e.detail.value
+    this.setData({timeValue:time})
+  },
+  bindTimeChange7:function(e){
+    let time = this.data.timeValue
+    time[2] = e.detail.value
+    this.setData({timeValue:time})
+  },
+  bindTimeChange8:function(e){
+    let time = this.data.timeValue
+    time[3] = e.detail.value
+    this.setData({timeValue:time})
+  },
+  bindTimeChange9:function(e){
+    let time = this.data.timeValue
+    time[4] = e.detail.value
+    this.setData({timeValue:time})
+  },
+  bindTimeChange10:function(e){
+    let time = this.data.timeValue
+    time[5] = e.detail.value
+    this.setData({timeValue:time})
   },
   //日期调控(图片切换)
   setbuty0: function () {
@@ -3137,9 +3177,7 @@ Page({
     wx.getSystemInfo({
       success: function (res) {
         if (res.model == 'iPad' || res.model == 'iPad Pro 10.5-inch' || res.model == 'iPad Pro 12.9-inch') {
-          that.setData({
-            zoom: 1
-          })
+          that.setData({zoom: 1})
         }
       }
     })
@@ -3152,9 +3190,7 @@ Page({
           groupName: groupName.groups
         })
       } else {
-        that.setData({
-          groupName: groupName.groups
-        })
+        that.setData({groupName: groupName.groups})
       }
       //设备下拉
       var deviceName = enloop.Devicedrop(that.data.groupName, that.data.groupIndex)
@@ -3169,35 +3205,168 @@ Page({
             deviceName: deviceName.device
           })
         } else {
-          that.setData({
-            deviceName: deviceName.device
-          })
+          that.setData({deviceName: deviceName.device})
         }
         //获取设备信息
         var currentGroup = that.data.groupName[that.data.groupIndex]
         var currentDevice = that.data.deviceName[that.data.deviceIndex]
         var message = enloop.deviceMessage(currentGroup, currentDevice)
-        console.log(message)
-        getBasic(message[1], message[2]).then(res => {
-          if (res.data.data.online == true) {
-            that.setData({
-              status: '在线'
-            })
-          } else {
-            that.setData({
-              status: '离线'
+        if(message.modules == 0){
+          getBasic(message.deviceId, message.deviceKey).then(res => {
+            if (res.data.data.online == true) {
+              that.setData({status: '在线'})
+            } else {
+              that.setData({status: '离线'})
+            }
+            getData(message.deviceId, message.deviceKey).then(ever => {
+              let {data} = ever.data
+              let loopnum =  message.loopnum
+              var Summary = enloop.deviceinfo(data,loopnum,that.data.arr,that.data.brr,that.data.time,that.data.state,
+                                that.data.state1,that.data.fixed1,that.data.fixed2,that.data.fixed3,
+                                that.data.fixed4,that.data.address,that.data.radio1,that.data.radio2,
+                                that.data.radio3,that.data.index,that.data.indexs)
+              that.setData({
+                crr:Summary.crr,arr:Summary.arr,brr:Summary.brr,fixed1:Summary.fixed1,
+                fixed2:Summary.fixed2,fixed3:Summary.fixed3,fixed4:Summary.fixed4,
+                index:Summary.index,indexs:Summary.indexs,radio1:Summary.radio1,radio2:Summary.radio2,
+                radio3:Summary.radio3,recorddate:Summary.recorddate,state:Summary.state,
+                state1:Summary.state1,time:Summary.time,address:Summary.address,play:0
+              })
+              //监视开关状态(改变颜色,调整功能)
+              switch (that.data.state[0]) {
+                  case true:
+                    that.setData({
+                      type1:"time",
+                      timecontrolcolor1:"blue",
+                      fontcolor1:"white",
+                    })
+                  break;
+                  default:
+                    that.setData({
+                      type1:"",
+                      timecontrolcolor1:"#888888",
+                      fontcolor1:"#cccccc",
+                    })
+                  break;
+              }
+              switch (that.data.state[1]) {
+                  case true:
+                    that.setData({
+                      type2:"time",
+                      timecontrolcolor2:"blue",
+                      fontcolor2:"white",
+                    })
+                  break;
+                  default:
+                    that.setData({
+                      type2:"",
+                      timecontrolcolor2:"#888888",
+                      fontcolor2:"#cccccc",
+                    })
+                  break;
+              }
+              switch (that.data.state1[0]) {
+                  case true:
+                    that.setData({
+                      type3:"time",
+                      timecontrolcolor3:"blue",
+                      fontcolor3:"white",
+                    })
+                  break;
+                  default:
+                    that.setData({
+                      type3:"",
+                      timecontrolcolor3:"#888888",
+                      fontcolor3:"#cccccc",
+                    })
+                  break;
+              }
+              switch (that.data.state1[1]) {
+                  case true:
+                    that.setData({
+                      type4:"time",
+                      timecontrolcolor4:"blue",
+                      fontcolor4:"white",
+                    })
+                  break;
+                  default:
+                    that.setData({
+                      type4:"",
+                      timecontrolcolor4:"#888888",
+                      fontcolor4:"#cccccc",
+                    })
+                  break;
+              }
+              switch (that.data.state[2]) {
+                  case true:
+                    that.setData({
+                      Lightcontrolcolor1:"blue",
+                      fontcolor5:"white",
+                      select1:"selector"
+                    })
+                  break;
+                  default:
+                    that.setData({
+                      Lightcontrolcolor1:"#888888",
+                      fontcolor5:"#cccccc",
+                      select1:""
+                    })
+                  break;
+              }
+              switch (that.data.state[3]) {
+                  case true:
+                    that.setData({
+                      Lightcontrolcolor2:"blue",
+                      fontcolor6:"white",
+                      select2:"selector"
+                    })
+                  break;
+                  default:
+                    that.setData({
+                      Lightcontrolcolor2:"#888888",
+                      fontcolor6:"#cccccc",
+                      select2:""
+                    })
+                  break;
+              }
             })
-          }
-          getData(message[1], message[2]).then(ever => {
-            let {data} = ever.data
-            var Summary = enloop.deviceinfo(data,that.data.arr,that.data.brr,that.data.time,that.data.state,
-                              that.data.state1,that.data.fixed1,that.data.fixed2,that.data.fixed3,
-                              that.data.fixed4,that.data.address,that.data.radio1,that.data.radio2,
-                              that.data.radio3,that.data.index,that.data.indexs)
-            console.log(Summary)
-            
           })
-        })
+        }
+        else{
+          //新设备在线状态
+          getDevice(message.Device,message.id).then(nrg => {
+            if(nrg.data.code == 0){
+              var nrg = nrg.data.data
+              if(nrg[0].status == 1){
+                that.setData({status:'在线'})
+              }
+              else{
+                that.setData({status:'离线'})
+              }
+              getloop(message.Device).then(suc =>{
+                if(suc.data.code == 0){
+                  that.setData({crr:message.loopnum,play:1})
+                }
+                else{
+                  console.log('获取新设备回路参数失败')
+                  wx.showModal({
+                    title:'错误',
+                    content:suc.data.msg,
+                    showCancel:false
+                  })
+                }
+              })
+            }
+            else{
+              console.log('新设备获取信息失败')
+              wx.showModal({
+                title:'错误',
+                content:nrg.data.msg,
+                showCancel:false
+              })
+            }
+          })
+        }
       }
     }
 

+ 25 - 17
pages/loop/loop.wxml

@@ -127,14 +127,18 @@
     <text style="left: 2%;top: 8%;">时</text>
     <text style="left: 2%;top: 32%;">控</text>
     <text style="left: 2%;top: 57%;">一</text>
-    <switch></switch>
+    <switch bindchange="Controltime5" checked="{{newSwitch[0]}}"></switch>
     <text style="left: 40%;">开启时间</text>
     <text style="left: 75%;">关闭时间</text>
-    <picker mode="time" start="00:00" end="23:59" value="{{timeValue[0]}}">
-        <view class="startTime">{{timeValue[0]}}</view>
+    <picker mode="time" start="00:00" end="23:59" value="{{timeValue[0]}}" bindchange="bindTimeChange5" 
+    mode="{{newSwitchstate[0]}}">
+        <view class="startTime" style="background-color: {{newcolor[0]}};color:{{newfont[0]}}">
+        {{timeValue[0]}}</view>
     </picker>
-    <picker mode="time" start="00:00" end="23:59" value="{{endTimeValue[0]}}">
-        <view class="endTime">{{endTimeValue[0]}}</view>
+    <picker mode="time" start="00:00" end="23:59" value="{{timeValue[1]}}" bindchange="bindTimeChange6" 
+    mode="{{newSwitchstate[0]}}">
+        <view class="endTime" style="background-color: {{newcolor[0]}};color: {{newfont[0]}};">
+        {{timeValue[1]}}</view>
     </picker>
   </view>
   <!-- 时控2 -->
@@ -142,29 +146,33 @@
     <text style="left: 2%;top: 8%;">时</text>
     <text style="left: 2%;top: 32%;">控</text>
     <text style="left: 2%;top: 57%;">二</text>
-    <switch></switch>
+    <switch bindchange="Controltime6" checked="{{newSwitch[1]}}"></switch>
     <text style="left: 40%;">开启时间</text>
     <text style="left: 75%;">关闭时间</text>
-    <picker mode="time" start="00:00" end="23:59" value="{{timeValue[1]}}">
-        <view class="startTime">{{timeValue[1]}}</view>
+    <picker mode="time" start="00:00" end="23:59" value="{{timeValue[2]}}" bindchange="bindTimeChange7" mode="{{newSwitchstate[1]}}">
+        <view class="startTime" style="background-color: {{newcolor[1]}};color:{{newfont[1]}}">
+        {{timeValue[2]}}</view>
     </picker>
-    <picker mode="time" start="00:00" end="23:59" value="{{endTimeValue[1]}}">
-        <view class="endTime">{{endTimeValue[1]}}</view>
+    <picker mode="time" start="00:00" end="23:59" value="{{timeValue[3]}}" bindchange="bindTimeChange8" mode="{{newSwitchstate[1]}}">
+        <view class="endTime" style="background-color: {{newcolor[1]}};color:{{newfont[1]}}">
+        {{timeValue[3]}}</view>
     </picker>
   </view>
   <!-- 光控 -->
   <view class="newlight">
     <text style="top:2%;letter-spacing:20px">光控</text>
-    <switch></switch>
-    <picker mode="time" start="00:00" end="23:59" value="{{lightstartTime}}">
-        <view class="lightstartTime">{{lightstartTime}}</view>
+    <switch bindchange="Controllinght3" checked="{{newSwitch[2]}}"></switch>
+    <picker mode="time" start="00:00" end="23:59" value="{{timeValue[4]}}" bindchange="bindTimeChange9" mode="{{newSwitchstate[2]}}">
+        <view class="lightstartTime" style="background-color: {{newcolor[2]}};color:{{newfont[2]}}">
+        {{timeValue[4]}}</view>
     </picker>
     <text style="left: 44%;">至</text>
-    <picker mode="time" start="00:00" end="23:59" value="{{lightendTime}}">
-        <view class="lightendTime">{{lightendTime}}</view>
+    <picker mode="time" start="00:00" end="23:59" value="{{timeValue[5]}}" bindchange="bindTimeChange10" mode="{{newSwitchstate[2]}}">
+        <view class="lightendTime" style="background-color: {{newcolor[2]}};color:{{newfont[2]}}">
+        {{timeValue[5]}}</view>
     </picker>
-    <picker mode="selector" range="{{weather}}" value="{{wIndex}}" >
-      <view class="weather">{{weather[wIndex]}}</view>
+    <picker mode="selector" range="{{weather}}" value="{{wIndex}}">
+      <view class="weather" style="background-color: {{newcolor[2]}};color:{{newfont[2]}}">{{weather[wIndex]}}</view>
     </picker>
     <text style="bottom:7%;letter-spacing:10px">(生效时间)</text>
   </view>

+ 26 - 17
utils/loop.js

@@ -1,3 +1,4 @@
+const {getloop,getDevice} = require ('../api/device')
 // 分组下拉
 function Groupdrop() {
   var group = wx.getStorageSync('group')
@@ -10,10 +11,7 @@ function Groupdrop() {
     let GroupName = groups
     for (let n = 0; n < GroupName.length; n++) {
       if (GroupName[n] == wx.getStorageSync('groupName')) {
-        return {
-          n,
-          groups
-        }
+        return {n,groups}
       }
     }
   } else {
@@ -37,17 +35,12 @@ function Devicedrop(groupName, groupIndex) {
         if (wx.getStorageSync('deviceName') != '') {
           for (let m = 0; m < device.length; m++) {
             if (device[m] == wx.getStorageSync('deviceName')) {
-              return {
-                m,
-                device
-              }
+              return {m,device}
             }
           }
         } else {
           wx.setStorageSync('deviceName', device[0])
-          return {
-            device
-          }
+          return {device}
         }
       } else {
         return '离线'
@@ -61,16 +54,23 @@ function deviceMessage(groupNames, deviceNames) {
   var group = wx.getStorageSync('group')
   for (let d = 0; d < group.length; d++) {
     if (groupNames == group[d].groupName) {
+      var id = group[d].id
       for (let g = 0; g < group[d].devices.length; g++) {
         if (deviceNames == group[d].devices[g].deviceName) {
-          console.log(group[d].devices[g].module)
+          var Device = group[d].devices[g].id
+          //旧设备
           if (group[d].devices[g].module == 0) {
             var loopnum = group[d].devices[g].circuits
             var deviceId = group[d].devices[g].deviceId
             var deviceKey = group[d].devices[g].deviceKey
-            return [loopnum, deviceId, deviceKey]
+            var modules = group[d].devices[g].module
+            return {loopnum, deviceId, deviceKey, modules}
+          //新设备
           } else {
-
+            var loopNum = group[d].devices[g].circuits
+            var loopnum = loopNum.split(',')
+            var modules = group[d].devices[g].module
+            return {id,Device,loopnum,modules}
           }
         }
       }
@@ -78,8 +78,8 @@ function deviceMessage(groupNames, deviceNames) {
   }
 }
 
-//设备信息
-function deviceinfo(data,arr,brr,time,state,state1,
+//设备信息
+function deviceinfo(data,loopnum,arr,brr,time,state,state1,
                     fixed1,fixed2,fixed3,fixed4,address,
                     radio1,radio2,radio3,index,indexs) {
   //以下为回路
@@ -390,9 +390,18 @@ function deviceinfo(data,arr,brr,time,state,state1,
           radio1,radio2,radio3,index,indexs}
 }
 
+//新设备信息
+function newDeviceinfo(Device,Group){
+  getDevice(Device,Group).then(res => {
+  })
+}
+
+//时间开关选择器(新设备)
+
 module.exports = {
   Groupdrop: Groupdrop,
   Devicedrop: Devicedrop,
   deviceMessage: deviceMessage,
-  deviceinfo:deviceinfo
+  deviceinfo:deviceinfo,
+  newDeviceinfo:newDeviceinfo
 }