123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- const {postData} = require('../api/intell')
- const {putDevice} = require('../api/device')
- function getlooplist(){
- var group = wx.getStorageSync('group')
- //获取分组下拉
- var groups = []//分组列表
- var device = []//设备列表
- for(let i = 0;i < group.length;i++){
- groups.push(group[i].groupName)
- }
- //改变分组下标
- if(wx.getStorageSync('groupName') != ''){
- for(let n = 0;n < groups.length;n++){
- if(groups[n] == wx.getStorageSync('groupName')){
- var groupsIndex = n//分组下标
- }
- }
- }
- for(let j = 0;j < group.length;j++){
- if(groups[groupsIndex] == group[j].groupName){
- if(group[j].devices != null && group[j].devices.length != 0){
- for(let p = 0;p < group[j].devices.length;p++){
- device.push(group[j].devices[p].deviceName)
- }
- if(wx.getStorageSync('deviceName') != ''){
- for(let m = 0;m < device.length;m++){
- if(device[m] == wx.getStorageSync('deviceName')){
- var deviceIndex = m//设备下标
- }
- }
- }
- //根据分组名和设备名获取key和id以及回路名称
- for(let d = 0;d < group.length;d++){
- if(groups[groupsIndex] == group[d].groupName){
- for(let g = 0;g < group[d].devices.length;g++){
- if(device[deviceIndex] == group[d].devices[g].deviceName){
- var loopnum = group[d].devices[g].circuits
- var deviceId = group[d].devices[g].deviceId
- var deviceKey = group[d].devices[g].deviceKey
- }
- }
- }
- }
- }
- }
- }
- return [groups,groupsIndex,device,deviceIndex,loopnum,deviceId,deviceKey]
- }
- //回路开/关
- function Switch(deviceId,deviceKey,Rel){
- postData(deviceId,deviceKey,Rel).then(res => {
- if(res.data.errno == 10){
- wx.showModal({
- title:'错误',
- content:'设备处于离线状态',
- showCancel:false
- })
- }
- })
- }
- //回路开/关读取
- function switchReal(police,lamp,index){
- switch(police.length){
- case 1:
- police = '000' + police
- break;
- case 2:
- police = '00' + police
- break;
- case 3:
- police = '0' + police
- break;
- default:
- police = police
- break;
- }
- if(police.substring(2,3) == '0' && police.substring(3,4) == '0'){
- lamp[index] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
- }
- else if(police.substring(2,3) == '0' && police.substring(3,4) == '1'){
- lamp[index] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png'
- }
- return lamp
- }
- //回路名称调整(未解决)
- function loopname(deviceid,groupid,loop,loops,slice,groupName,deviceName,group,content){
- if(content == ''){
- wx.showModal({
- title:'提示',
- content:'请输入名称',
- showCancel:false
- })
- }
- else if(content.length > 10){
- wx.showModal({
- title:'提示',
- content:'回路名称不能大于10个字符',
- showCancel:false
- })
- }
- else{
- loop[0] = content
- slice = loop.slice(0,loops)
- slice = slice.toString()
- putDevice({id:deviceid,groupId:groupid,circuits:slice}).then(ever => {
- if(ever.data.code == 200){
- for(let i = 0;i < group.length;i++){
- if(groupName == group[i].groupName){
- for(let j = 0;j < group[i].devices.length;j++){
- if(deviceName == group[i].devices[j].deviceName){
- group[i].devices[j].circuits = slice
- wx.setStorageSync('group', group)
- return loop
- }
- }
- }
- }
- }
- else{
- wx.showModal({
- title:'错误',
- content:ever.data.msg,
- showCancel:false
- })
- }
- })
- }
- }
- module.exports = {
- getlooplist:getlooplist,
- Switch:Switch,
- switchReal:switchReal,
- loopname:loopname,
- }
|