|
@@ -28,7 +28,7 @@ Page({
|
|
|
//刷新列表
|
|
|
Refreshlist:function(){
|
|
|
wx.showToast({
|
|
|
- title:'刷新中',
|
|
|
+ title:'获取数据中',
|
|
|
icon:'loading',
|
|
|
duration: 2000
|
|
|
})
|
|
@@ -51,14 +51,6 @@ Page({
|
|
|
else{
|
|
|
data[i].devices[j].status = '离线'
|
|
|
}
|
|
|
- wx.setStorageSync('group',data)
|
|
|
- let 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.showModal({
|
|
@@ -79,14 +71,6 @@ Page({
|
|
|
data[i].devices[j].status = '在线'
|
|
|
break
|
|
|
}
|
|
|
- wx.setStorageSync('group',data)
|
|
|
- let 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})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -102,6 +86,11 @@ Page({
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ setTimeout(function(){
|
|
|
+ wx.setStorageSync('group',data)
|
|
|
+ let tgroups = wx.getStorageSync('group')
|
|
|
+ that.nameRestriction(tgroups)
|
|
|
+ },1500)
|
|
|
}
|
|
|
else{
|
|
|
wx.showModal({
|
|
@@ -150,12 +139,7 @@ Page({
|
|
|
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})
|
|
|
+ that.nameRestriction(group)
|
|
|
}
|
|
|
else{
|
|
|
wx.showModal({
|
|
@@ -191,12 +175,7 @@ Page({
|
|
|
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})
|
|
|
+ that.nameRestriction(Group)
|
|
|
}
|
|
|
else{
|
|
|
wx.showModal({
|
|
@@ -246,12 +225,7 @@ Page({
|
|
|
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})
|
|
|
+ that.nameRestriction(Group)
|
|
|
}
|
|
|
else{
|
|
|
wx.showModal({
|
|
@@ -303,12 +277,7 @@ Page({
|
|
|
}
|
|
|
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})
|
|
|
+ that.nameRestriction(Group)
|
|
|
})
|
|
|
}
|
|
|
else{
|
|
@@ -330,7 +299,6 @@ Page({
|
|
|
//查询设备
|
|
|
getDevice(add.data.data.id,Idindex).then(get =>{
|
|
|
var Get = get.data.data
|
|
|
- console.log(Get)
|
|
|
switch(Get.status){
|
|
|
case 0:
|
|
|
Get.status = '离线'
|
|
@@ -348,12 +316,7 @@ Page({
|
|
|
}
|
|
|
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})
|
|
|
+ that.nameRestriction(Group)
|
|
|
})
|
|
|
}
|
|
|
else{
|
|
@@ -432,12 +395,7 @@ Page({
|
|
|
}
|
|
|
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})
|
|
|
+ that.nameRestriction(Group)
|
|
|
}
|
|
|
else{
|
|
|
wx.showModal({
|
|
@@ -507,12 +465,7 @@ Page({
|
|
|
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})
|
|
|
+ that.nameRestriction(Group)
|
|
|
}
|
|
|
else{
|
|
|
wx.showModal({
|
|
@@ -545,12 +498,7 @@ Page({
|
|
|
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: Group})
|
|
|
+ that.nameRestriction(Group)
|
|
|
if(groupName == wx.getStorageSync('groupName') && deviceName == wx.getStorageSync('deviceName')){
|
|
|
wx.setStorageSync('deviceName','')
|
|
|
}
|
|
@@ -586,94 +534,31 @@ Page({
|
|
|
array:array
|
|
|
})
|
|
|
},
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- onLoad(options) {
|
|
|
- wx.showToast({
|
|
|
- title:'获取数据中',
|
|
|
- icon:'loading',
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
+ //分组和设备名称的显示限制
|
|
|
+ nameRestriction:function(Group){
|
|
|
var that = this
|
|
|
- getGroup().then(res => {
|
|
|
- if(res.data.code == 0){
|
|
|
- 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++){
|
|
|
- if(data[i].devices[j].module == 0){
|
|
|
- let id = data[i].devices[j].deviceId
|
|
|
- let key = data[i].devices[j].deviceKey
|
|
|
- getBasic(id,key).then(ever =>{
|
|
|
- if(ever.data.errno == 0){
|
|
|
- if(ever.data.data.online == true){
|
|
|
- data[i].devices[j].status = '在线'
|
|
|
- }
|
|
|
- else{
|
|
|
- data[i].devices[j].status = '离线'
|
|
|
- }
|
|
|
- wx.setStorageSync('group',data)
|
|
|
- let 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.showModal({
|
|
|
- title:'错误',
|
|
|
- content:ever.data.error,
|
|
|
- showCancel:false
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- else{
|
|
|
- let status = data[i].devices[j].status
|
|
|
- switch(status){
|
|
|
- case 0:
|
|
|
- data[i].devices[j].status = '离线'
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- data[i].devices[j].status = '在线'
|
|
|
- break
|
|
|
- }
|
|
|
- wx.setStorageSync('group',data)
|
|
|
- let 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})
|
|
|
- }
|
|
|
+ for(let i = 0;i < Group.length;i++){
|
|
|
+ if(Group[i].groupName.length > 10){
|
|
|
+ Group[i].groupName = Group[i].groupName.slice(0,9) + '....'
|
|
|
+ }
|
|
|
+ if(Group[i].devices != null){
|
|
|
+ for(let j = 0;j < Group[i].devices.length;j++){
|
|
|
+ if(Group[i].devices[j].deviceName.length > 10){
|
|
|
+ Group[i].devices[j].deviceName = Group[i].devices[j].deviceName.substr(-4)
|
|
|
+ }
|
|
|
+ if(Group[i].devices[j].deviceSn.length > 10){
|
|
|
+ Group[i].devices[j].deviceSn = Group[i].devices[j].deviceSn.substr(-4)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else{
|
|
|
- wx.showModal({
|
|
|
- title:'错误',
|
|
|
- content:res.data.msg,
|
|
|
- showCancel:false
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ }
|
|
|
+ that.setData({array: Group})
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad(options) {
|
|
|
+ this.Refreshlist()
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -686,6 +571,12 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
+ var that = this
|
|
|
+ setTimeout(function(){
|
|
|
+ if(that.data.array.length == 0){
|
|
|
+ that.Refreshlist()
|
|
|
+ }
|
|
|
+ },1000)
|
|
|
},
|
|
|
|
|
|
/**
|