|
@@ -1,6 +1,9 @@
|
|
|
+const {postGroup,getGroup,putGroup,delGroup} = require('../../api/group')
|
|
|
+const {postDevice,getDevice,putDevice,delDevice} = require('../../api/device')
|
|
|
+const {getBasic,getData,postData} = require('../../api/intell')
|
|
|
+
|
|
|
// pages/scene/scene.js
|
|
|
Page({
|
|
|
-
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
@@ -18,6 +21,89 @@ Page({
|
|
|
developline:[],
|
|
|
status:0,
|
|
|
Status:"",
|
|
|
+ phone:'',
|
|
|
+ displaypicture:"https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/ling.png",
|
|
|
+ display:[]
|
|
|
+ },
|
|
|
+ //刷新列表
|
|
|
+ Refreshlist:function(){
|
|
|
+ wx.showToast({
|
|
|
+ title:'刷新中',
|
|
|
+ icon:'loading',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ var that = this
|
|
|
+ let token = wx.getStorageSync('token')
|
|
|
+ wx.request({
|
|
|
+ url: 'https://cloud.long-chi.com/api/minigrogram/lightcontrol/groups',
|
|
|
+ method:'GET',
|
|
|
+ header:{'Content-Type': 'application/json',
|
|
|
+ 'Authorization': token},
|
|
|
+ success:res =>{
|
|
|
+ console.log('刷新成功' + res.data.msg)
|
|
|
+ if(res.data.code == 200){
|
|
|
+ var data = res.data.data
|
|
|
+ if(data != null){
|
|
|
+ for(let i = 0;i <data.length;i++){
|
|
|
+ if(data[i].devices != null){
|
|
|
+ for(let j = 0;j < data[i].devices.length;j++){
|
|
|
+ let id = data[i].devices[j].deviceId
|
|
|
+ let key = data[i].devices[j].deviceKey
|
|
|
+ console.log('id为' + id)
|
|
|
+ console.log('key为' + key)
|
|
|
+ wx.request({
|
|
|
+ url: 'https://api.heclouds.com/devices/' + id,
|
|
|
+ method:'GET',
|
|
|
+ header:{"api-key": key},
|
|
|
+ success:(res) =>{
|
|
|
+ console.log(res.data.data.online)
|
|
|
+ if (res.data.data.online == true) {
|
|
|
+ data[i].devices[j].status = '在线'
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ data[i].devices[j].status = '离线'
|
|
|
+ }
|
|
|
+ wx.setStorageSync('group',data)
|
|
|
+ var group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < group.length;i++){
|
|
|
+ if(group[i].groupName.length > 10){
|
|
|
+ group[i].groupName = group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ array:group,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ wx.setStorageSync('group',data)
|
|
|
+ var group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < group.length;i++){
|
|
|
+ if(group[i].groupName.length > 10){
|
|
|
+ group[i].groupName = group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ array:group,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:res.data.msg,
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail:(bug) =>{
|
|
|
+ console.log(bug)
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
//添加分组
|
|
|
apption:function(){
|
|
@@ -35,38 +121,41 @@ Page({
|
|
|
showCancel:false
|
|
|
})
|
|
|
}
|
|
|
+ else if(ever.content.length > 15){
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:'分组名称不能大于15个字符',
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
+ }
|
|
|
else{
|
|
|
- let token = wx.getStorageSync('token')
|
|
|
- wx.request({
|
|
|
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/groups',
|
|
|
- method:'POST',
|
|
|
- header:{'Content-Type': 'application/json',
|
|
|
- 'Authorization': token},
|
|
|
- data:{
|
|
|
- groupName:ever.content
|
|
|
- },
|
|
|
- success:res => {
|
|
|
- console.log(res)
|
|
|
- if(res.data.code == 200){
|
|
|
- if(wx.getStorageSync('group') == ''){
|
|
|
- wx.setStorageSync('group', [])
|
|
|
- var a = wx.getStorageSync('group')
|
|
|
- a.push({id:res.data.data.id,name:ever.content,device:[]})
|
|
|
- wx.setStorageSync('group', a)
|
|
|
- }
|
|
|
- else{
|
|
|
- var b = wx.getStorageSync('group')
|
|
|
- b.push({id:res.data.data.id,name:ever.content,device:[]})
|
|
|
- wx.setStorageSync('group', b)
|
|
|
- }
|
|
|
- that.setData({
|
|
|
- array:wx.getStorageSync('group'),
|
|
|
- })
|
|
|
- console.log(wx.getStorageSync('group'))
|
|
|
- }
|
|
|
+ postGroup({groupName:ever.content}).then((res)=>{
|
|
|
+ if(res.data.code == 200){
|
|
|
+ if(wx.getStorageSync('group') == ''){
|
|
|
+ wx.setStorageSync('group', [])
|
|
|
+ var a = wx.getStorageSync('group')
|
|
|
+ a.push({id:res.data.data.id,groupName:ever.content,devices:[]})
|
|
|
+ wx.setStorageSync('group', a)
|
|
|
+ }
|
|
|
else{
|
|
|
- console.log("添加分组失败")
|
|
|
+ var b = wx.getStorageSync('group')
|
|
|
+ b.push({id:res.data.data.id,groupName:ever.content,devices:[]})
|
|
|
+ wx.setStorageSync('group', b)
|
|
|
}
|
|
|
+ var group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < group.length;i++){
|
|
|
+ if(group[i].groupName.length > 10){
|
|
|
+ group[i].groupName = group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({array:group})
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ wx.showModal({
|
|
|
+ title:'错误',
|
|
|
+ content:res.data.msg,
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -84,26 +173,30 @@ Page({
|
|
|
if (res.confirm) {
|
|
|
var index = e.currentTarget.dataset.indexdel//获取对应下标
|
|
|
var Idindex = that.data.array[index].id
|
|
|
- var token = wx.getStorageSync('token')
|
|
|
- wx.request({
|
|
|
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/groups?id=' + Idindex,//
|
|
|
- method:'DELETE',
|
|
|
- header:{'Content-Type': 'application/json',
|
|
|
- 'Authorization': token},
|
|
|
- success:res => {
|
|
|
- if(res.data.code == 200){
|
|
|
- if(wx.getStorageSync('group') != ''){
|
|
|
- var deleteid = wx.getStorageSync('group')
|
|
|
- deleteid.splice(index,1)
|
|
|
- wx.setStorageSync('group', deleteid)
|
|
|
- that.setData({
|
|
|
- array:wx.getStorageSync('group'),
|
|
|
- })
|
|
|
- }
|
|
|
+ var groupName = that.data.array[index].groupName
|
|
|
+ delGroup(Idindex).then((res)=>{
|
|
|
+ if(res.data.code == 200){
|
|
|
+ if(groupName == wx.getStorageSync('groupName')){
|
|
|
+ wx.setStorageSync('groupName', '')
|
|
|
+ wx.setStorageSync('deviceName', '')
|
|
|
}
|
|
|
- else{
|
|
|
- console.log('删除分组失败')
|
|
|
+ var deleteid = wx.getStorageSync('group')
|
|
|
+ deleteid.splice(index,1)
|
|
|
+ wx.setStorageSync('group', deleteid)
|
|
|
+ var Group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < Group.length;i++){
|
|
|
+ if(Group[i].groupName.length > 10){
|
|
|
+ Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
}
|
|
|
+ that.setData({array: Group})
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:res.data.msg,
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -113,15 +206,16 @@ Page({
|
|
|
//修改分组名称
|
|
|
ShowChanges:function(e){
|
|
|
var that = this
|
|
|
+ console.log('缓存的分组名称为' + wx.getStorageSync('groupName'))
|
|
|
wx.showModal({
|
|
|
title:'修改工程名称',
|
|
|
editable:true,
|
|
|
placeholderText:'请输入名称',
|
|
|
success:res =>{
|
|
|
- console.log(res)
|
|
|
if (res.confirm) {
|
|
|
var index = e.currentTarget.dataset.indexdel//获取对应下标
|
|
|
var Idindex = that.data.array[index].id//获取对应下标的id值
|
|
|
+ var groupName = that.data.array[index].name
|
|
|
if (res.content == '') {
|
|
|
wx.showModal({
|
|
|
title:'提示',
|
|
@@ -129,32 +223,37 @@ Page({
|
|
|
showCancel:false
|
|
|
})
|
|
|
}
|
|
|
+ else if(res.content.length > 15){
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:'分组名称不能大于15个字符',
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
+ }
|
|
|
else{
|
|
|
- var token = wx.getStorageSync('token')
|
|
|
- wx.request({
|
|
|
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/groups',
|
|
|
- method:'PUT',
|
|
|
- header:{
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- 'Authorization': token
|
|
|
- },
|
|
|
- data:{
|
|
|
- groupName:res.content,
|
|
|
- id:Idindex
|
|
|
- },
|
|
|
- success:ever =>{
|
|
|
- console.log(ever)
|
|
|
- if (ever.data.code == 200) {
|
|
|
- let group = wx.getStorageSync('group')
|
|
|
- group[index].name = res.content
|
|
|
- wx.setStorageSync('group',group)
|
|
|
- that.setData({
|
|
|
- array:wx.getStorageSync('group')
|
|
|
- })
|
|
|
+ putGroup({id:Idindex,groupName:res.content}).then(ever=>{
|
|
|
+ console.log(ever)
|
|
|
+ if (ever.data.code == 200) {
|
|
|
+ if(groupName == wx.getStorageSync('groupName')){
|
|
|
+ wx.setStorageSync('groupName',res.content)
|
|
|
}
|
|
|
- else{
|
|
|
- console.log('修改分组名称失败')
|
|
|
+ let group = wx.getStorageSync('group')
|
|
|
+ group[index].groupName = res.content
|
|
|
+ wx.setStorageSync('group',group)
|
|
|
+ var Group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < Group.length;i++){
|
|
|
+ if(Group[i].groupName.length > 10){
|
|
|
+ Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
}
|
|
|
+ that.setData({array:Group})
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:ever.data.msg,
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -171,17 +270,16 @@ Page({
|
|
|
//获取设备
|
|
|
wx.scanCode({
|
|
|
success(res){
|
|
|
- var arr = res.result.split(' ');
|
|
|
- var a = arr[0]//设备id
|
|
|
- var b = arr[1]//设备key
|
|
|
- //获取该设备的在线状态和编码
|
|
|
- wx.request({
|
|
|
- url: 'https://api.heclouds.com/devices/' + a,
|
|
|
- method:'GET',
|
|
|
- header:{
|
|
|
- 'api-key':b,
|
|
|
- },
|
|
|
- success(ever){
|
|
|
+ //console.log(res.result.match(/\d+(\.\d+)?/g))
|
|
|
+ if(res.result.substring(0,1) == '{'){
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ var arr = res.result.split(' ');
|
|
|
+ var a = arr[0]//设备id
|
|
|
+ var b = arr[1]//设备key
|
|
|
+ //获取该设备的在线状态和编码
|
|
|
+ getBasic(a,b).then(ever=>{
|
|
|
var online = ever.data.data.online//设备在线状态
|
|
|
switch (online) {
|
|
|
case true:
|
|
@@ -194,49 +292,85 @@ Page({
|
|
|
break;
|
|
|
}
|
|
|
var title = ever.data.data.title//设备编码
|
|
|
- let token = wx.getStorageSync('token')
|
|
|
- wx.request({
|
|
|
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/devices',
|
|
|
- method:'POST',
|
|
|
- header:{'Content-Type': 'application/json',
|
|
|
- 'Authorization': token},
|
|
|
- data:{
|
|
|
- groupId:Idindex,//分组id
|
|
|
- deviceSn:title,//设备编码
|
|
|
- deviceName:title,//设备名称
|
|
|
- deviceId:a,//设备id
|
|
|
- deviceKey:b,//设备key
|
|
|
- status:that.data.status//设备在线状态
|
|
|
- },
|
|
|
- success:su =>{
|
|
|
+ getData(a,b).then(gu =>{
|
|
|
+ let trys = gu.data.data
|
|
|
+ for(let w = 0;w < trys.length;w++){
|
|
|
+ if(trys[w].id == "RelayCount"){
|
|
|
+ var num = trys[w].current_value
|
|
|
+ num = parseInt(num)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var numName = ''
|
|
|
+ for(let p = 0;p < num;p++){
|
|
|
+ numName = numName + '回路' + (p + 1) + ','
|
|
|
+ }
|
|
|
+ numName = numName.slice(0,numName.length - 1)
|
|
|
+ //添加设备
|
|
|
+ postDevice({groupId:Idindex,deviceSn:title,deviceName:title,deviceId:a,deviceKey:b,status:that.data.status,circuitNum:num,circuits:numName})
|
|
|
+ .then(su => {
|
|
|
if (su.data.code == 200){
|
|
|
- //将设备的信息储存至本地
|
|
|
+ //将设备的信息储存至本地
|
|
|
let group = wx.getStorageSync('group')
|
|
|
- group[index].device.push({id:su.data.data.id,deviceSn:title,deviceName:title,status:that.data.Status,deviceId:a,
|
|
|
- deviceKey:b})
|
|
|
+ if(group[index].devices != null){
|
|
|
+ group[index].devices.push({
|
|
|
+ id:su.data.data.id,
|
|
|
+ deviceSn:title,
|
|
|
+ deviceName:title,
|
|
|
+ status:that.data.Status,
|
|
|
+ deviceId:a,
|
|
|
+ deviceKey:b,
|
|
|
+ circuitNum:num,
|
|
|
+ circuits:numName
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ group[index].devices = []
|
|
|
+ group[index].devices.push({
|
|
|
+ id:su.data.data.id,
|
|
|
+ deviceSn:title,
|
|
|
+ deviceName:title,
|
|
|
+ status:that.data.Status,
|
|
|
+ deviceId:a,
|
|
|
+ deviceKey:b,
|
|
|
+ circuitNum:num,
|
|
|
+ circuits:numName
|
|
|
+ })
|
|
|
+ }
|
|
|
wx.setStorageSync('group', group)
|
|
|
+ var Group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < Group.length;i++){
|
|
|
+ if(Group[i].groupName.length > 10){
|
|
|
+ Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
+ }
|
|
|
that.setData({
|
|
|
- array:wx.getStorageSync('group')
|
|
|
+ array: Group
|
|
|
})
|
|
|
- console.log(that.data.array)
|
|
|
}
|
|
|
else{
|
|
|
- console.log('添加设备失败')
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:su.data.msg,
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
}
|
|
|
- }
|
|
|
+ })
|
|
|
})
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//修改设备名称
|
|
|
modifyequipmentname:function(e){
|
|
|
var that = this
|
|
|
+ console.log('缓存的设备名称为' + wx.getStorageSync('deviceName'))
|
|
|
var key = e.currentTarget.dataset.indexdel
|
|
|
var group = wx.getStorageSync('group')
|
|
|
- var deviceId = group[key[0]].device[key[1]].id
|
|
|
- var token = wx.getStorageSync('token')
|
|
|
+ var deviceId = group[key[0]].devices[key[1]].id
|
|
|
+ var groupName = group[key[0]].groupName//获取当前的分组名称
|
|
|
+ var groupId = group[key[0]].id
|
|
|
+ var deviceName = group[key[0]].devices[key[1]].deviceName//获取当前的设备名称
|
|
|
wx.showModal({
|
|
|
title:'修改设备名称',
|
|
|
editable:true,
|
|
@@ -250,27 +384,36 @@ Page({
|
|
|
content:'请输入名称'
|
|
|
})
|
|
|
}
|
|
|
+ else if(res.content.length > 10){
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ showCancel:false,
|
|
|
+ content:'设备名称不能大于10个字符'
|
|
|
+ })
|
|
|
+ }
|
|
|
else{
|
|
|
- wx.request({
|
|
|
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/devices',
|
|
|
- method:'PUT',
|
|
|
- header:{'Content-Type': 'application/json','Authorization': token},
|
|
|
- data:{
|
|
|
- deviceName:res.content,
|
|
|
- id:deviceId
|
|
|
- },
|
|
|
- success:ever =>{
|
|
|
- console.log(ever)
|
|
|
- if(ever.data.code == 200){
|
|
|
- group[key[0]].device[key[1]].deviceName = res.content
|
|
|
- wx.setStorageSync('group', group)
|
|
|
- that.setData({
|
|
|
- array:wx.getStorageSync('group')
|
|
|
- })
|
|
|
+ putDevice({deviceName:res.content,id:deviceId,groupId:groupId}).then(ever=>{
|
|
|
+ console.log('修改设备名称' + ever.data.msg)
|
|
|
+ if(ever.data.code == 200){
|
|
|
+ if(groupName == wx.getStorageSync('groupName') && deviceName == wx.getStorageSync('deviceName')){
|
|
|
+ wx.setStorageSync('deviceName',res.content)
|
|
|
}
|
|
|
- else{
|
|
|
- console.log('修改设备名称失败')
|
|
|
+ group[key[0]].devices[key[1]].deviceName = res.content
|
|
|
+ wx.setStorageSync('group', group)
|
|
|
+ var Group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < Group.length;i++){
|
|
|
+ if(Group[i].groupName.length > 10){
|
|
|
+ Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
}
|
|
|
+ that.setData({array: Group})
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:ever.data.msg,
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -281,7 +424,6 @@ Page({
|
|
|
//删除设备
|
|
|
Deletedevice:function(e){
|
|
|
var that = this
|
|
|
- var token = wx.getStorageSync('token')
|
|
|
wx.showModal({
|
|
|
title:'删除设备',
|
|
|
content:'确定删除该设备吗?',
|
|
@@ -289,82 +431,127 @@ Page({
|
|
|
if(res.confirm){
|
|
|
let key = e.currentTarget.dataset.indexdel//获得分组和设备的下标值([分组下标,设备下标])
|
|
|
let group = wx.getStorageSync('group')
|
|
|
- let subscript = group[key[0]].device[key[1]].id//设备对应的id
|
|
|
- wx.request({
|
|
|
- url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/devices?id=' + subscript,
|
|
|
- method:'DELETE',
|
|
|
- header:{'Content-Type': 'application/json','Authorization': token},
|
|
|
- success:nrg => {
|
|
|
- console.log(nrg)
|
|
|
- if (nrg.data.code == 200) {
|
|
|
- group[key[0]].device.splice(key[1],1)
|
|
|
- wx.setStorageSync('group', group)
|
|
|
+ let subscript = group[key[0]].devices[key[1]].id//设备对应的id
|
|
|
+ var groupName = group[key[0]].groupName
|
|
|
+ var deviceName = group[key[0]].devices[key[1]].deviceName
|
|
|
+ delDevice(subscript).then(nrg=>{
|
|
|
+ if (nrg.data.code == 200) {
|
|
|
+ group[key[0]].devices.splice(key[1],1)
|
|
|
+ wx.setStorageSync('group', group)
|
|
|
+ var Group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < Group.length;i++){
|
|
|
+ if(Group[i].groupName.length > 10){
|
|
|
+ Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
+ }
|
|
|
that.setData({
|
|
|
- array:wx.getStorageSync('group')
|
|
|
+ array: Group
|
|
|
})
|
|
|
- }
|
|
|
- else{
|
|
|
- console.log('删除列表失败')
|
|
|
+ if(groupName == wx.getStorageSync('groupName') && deviceName == wx.getStorageSync('deviceName')){
|
|
|
+ wx.setStorageSync('deviceName','')
|
|
|
}
|
|
|
}
|
|
|
+ else{
|
|
|
+ wx.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:nrg.data.msg,
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- Refresh:function(){
|
|
|
-
|
|
|
- },
|
|
|
- //展开设备
|
|
|
- develops:function(){
|
|
|
-
|
|
|
+ //设备的显示隐藏
|
|
|
+ Develop:function(e){
|
|
|
+ var that = this
|
|
|
+ let array = that.data.array
|
|
|
+ var pd = e.currentTarget.dataset.indexdel
|
|
|
+ for(let item =0;item < array.length;item++){
|
|
|
+ if (array[item].id == array[pd].id) {
|
|
|
+ //判断当前对象中的insert是否为true(true为显示,其他为隐藏) insert是新增的一个值然后进行判断
|
|
|
+ if (array[item].insert == "" || array[item].insert == undefined) {
|
|
|
+ array[item].insert = "true"
|
|
|
+ } else {
|
|
|
+ array[item].insert = ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ array:array
|
|
|
+ })
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
+ wx.showToast({
|
|
|
+ title:'获取数据中',
|
|
|
+ icon:'loading',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
var that = this
|
|
|
- let token = wx.getStorageSync('token')
|
|
|
- // wx.request({
|
|
|
- // url:'http://110.40.223.170:8120/api/minigrogram/lightcontrol/groups',
|
|
|
- // method:'GET',
|
|
|
- // header:{'Content-Type': 'application/json','Authorization': token},
|
|
|
- // success:tp => {
|
|
|
- // console.log(tp)
|
|
|
- // }
|
|
|
- // })
|
|
|
- // wx.request({
|
|
|
- // url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/devices?id=' + '5',
|
|
|
- // method:'DELETE',
|
|
|
- // header:{'Content-Type': 'application/json','Authorization': token},
|
|
|
- // success:nrg => {
|
|
|
- // console.log(nrg)
|
|
|
- // }
|
|
|
- // })
|
|
|
- console.log(wx.getStorageSync('group'))
|
|
|
- // that.data.array = []
|
|
|
- // wx.setStorageSync('information', )
|
|
|
- // console.log(wx.getStorageSync('information'))
|
|
|
- // wx.setStorageSync('id', [])
|
|
|
- // wx.setStorageSync('values', [])
|
|
|
- that.setData({
|
|
|
- array:wx.getStorageSync('group'),
|
|
|
+ getGroup().then(res => {
|
|
|
+ if(res.data.code == 200){
|
|
|
+ var data = res.data.data
|
|
|
+ if(data != null){
|
|
|
+ for(let i = 0;i <data.length;i++){
|
|
|
+ if(data[i].devices != null){
|
|
|
+ for(let j = 0;j < data[i].devices.length;j++){
|
|
|
+ let id = data[i].devices[j].deviceId
|
|
|
+ let key = data[i].devices[j].deviceKey
|
|
|
+ getBasic(id,key).then(ever =>{
|
|
|
+ if(ever.data.data.online == true){
|
|
|
+ data[i].devices[j].status = '在线'
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ data[i].devices[j].status = '离线'
|
|
|
+ }
|
|
|
+ wx.setStorageSync('group',data)
|
|
|
+ var tgroups = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < tgroups.length;i++){
|
|
|
+ if(tgroups[i].groupName.length > 10){
|
|
|
+ tgroups[i].groupName = tgroups[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({array:tgroups})
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ wx.setStorageSync('group',data)
|
|
|
+ let group = wx.getStorageSync('group')
|
|
|
+ for(let i = 0;i < group.length;i++){
|
|
|
+ if(group[i].groupName.length > 10){
|
|
|
+ group[i].groupName = group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({array:group})
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ wx.showModal({
|
|
|
+ title:'错误',
|
|
|
+ content:res.data.msg,
|
|
|
+ showCancel:false
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
- console.log(that.data.array)
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady() {
|
|
|
-
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
-
|
|
|
},
|
|
|
|
|
|
/**
|