|
@@ -14,6 +14,7 @@ Page({
|
|
showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示
|
|
showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示
|
|
title: 'OhPlay', //导航栏 中间的标题
|
|
title: 'OhPlay', //导航栏 中间的标题
|
|
},
|
|
},
|
|
|
|
+
|
|
///下午好
|
|
///下午好
|
|
isLogin: false,
|
|
isLogin: false,
|
|
greeting: "",
|
|
greeting: "",
|
|
@@ -194,15 +195,11 @@ Page({
|
|
that.data.deviceList[index].devName = payloads.other.devName;
|
|
that.data.deviceList[index].devName = payloads.other.devName;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
// 更新缓存
|
|
// 更新缓存
|
|
- wx.setStorage({
|
|
|
|
- key: "devicelist",
|
|
|
|
- data: JSON.stringify(that.data.deviceList),
|
|
|
|
- success() {
|
|
|
|
- that.setData({
|
|
|
|
- deviceList: that.data.deviceList
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ wx.setStorageSync("devicelist", JSON.stringify(that.data.deviceList));
|
|
|
|
+ that.setData({
|
|
|
|
+ deviceList: that.data.deviceList
|
|
});
|
|
});
|
|
} else if (payloads.type === "battery" && payloads.other) {
|
|
} else if (payloads.type === "battery" && payloads.other) {
|
|
that.setData({
|
|
that.setData({
|
|
@@ -241,42 +238,53 @@ Page({
|
|
|
|
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
|
|
|
|
- ///连上就调用2次
|
|
|
|
|
|
+ ///连上就调用2次 处理离线在线问题 wifi设备 BLUFI_
|
|
/// payloads:{"uuid":"AIrSMArT_7cdfa1fcbb24","state":"online","userid":"1"}
|
|
/// payloads:{"uuid":"AIrSMArT_7cdfa1fcbb24","state":"online","userid":"1"}
|
|
|
|
+ // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
online(payloads) {
|
|
online(payloads) {
|
|
// 设置在线状态
|
|
// 设置在线状态
|
|
var that = this;
|
|
var that = this;
|
|
console.log("gadsfadsfadsfa==777===" + JSON.stringify(payloads));
|
|
console.log("gadsfadsfadsfa==777===" + JSON.stringify(payloads));
|
|
- that.data.deviceList.map((v, index) => {
|
|
|
|
- if (payloads.uuid && payloads.uuid.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
|
|
|
|
- that.data.deviceList[index].state = payloads.state;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
|
|
- that.setData({
|
|
|
|
- deviceList: that.data.deviceList,
|
|
|
|
- });
|
|
|
|
- // 更新缓存
|
|
|
|
- wx.setStorage({
|
|
|
|
- key: "devicelist",
|
|
|
|
- data: JSON.stringify(that.data.deviceList)
|
|
|
|
- });
|
|
|
|
- // 如没有选中,选中最新的
|
|
|
|
- (() => {
|
|
|
|
- if (that.data.deviceListIndex === null) {
|
|
|
|
- let itue = false;
|
|
|
|
- that.data.deviceList.map((v, index) => {
|
|
|
|
- if (v.state === "online" && !itue) {
|
|
|
|
- itue = true;
|
|
|
|
- that.actionDevice(index);
|
|
|
|
|
|
+ var isUpdate = false;
|
|
|
|
+ var deviceList = that.data.deviceList;
|
|
|
|
+ if (!strings.isEmpty(deviceList)) {
|
|
|
|
+ for (var i = 0; i < deviceList.length; i++) {
|
|
|
|
+ if (payloads.uuid) {
|
|
|
|
+ var deviceId = deviceList[i].deviceId;
|
|
|
|
+ var splitDeviceId = deviceId.split("BLUFI_");
|
|
|
|
+ if (splitDeviceId.length == 2) {
|
|
|
|
+ var index = payloads.uuid.indexOf(splitDeviceId[1]);
|
|
|
|
+ if (index !== -1) {
|
|
|
|
+ if (deviceList[i].state != payloads.state) {
|
|
|
|
+ isUpdate = true;
|
|
|
|
+ deviceList[i].state = payloads.state;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- // else {
|
|
|
|
- // that.actionDevice(that.data.deviceListIndex);
|
|
|
|
- // };
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- })();
|
|
|
|
|
|
+ ///数据有更新
|
|
|
|
+ if (isUpdate) {
|
|
|
|
+ var finalList = that.updateDeviceList(deviceList);
|
|
|
|
+ that.setData({
|
|
|
|
+ deviceList: finalList,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ///当前没有连接设备,则去连接第一个wifi设备
|
|
|
|
+ if (that.data.deviceListIndex === null) {
|
|
|
|
+ var list = that.data.deviceList;
|
|
|
|
+ for (var i = 0; i < list.length; i++) {
|
|
|
|
+ if (list[i].state === "online" && list[i].ProdModel == "MW-2AX(WIFI-N)") {
|
|
|
|
+ that.actionDevice(i);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
// 当前播放设备离线
|
|
// 当前播放设备离线
|
|
if (that.data.deviceListIndex !== null && that.data.deviceList[that.data.deviceListIndex].state !== "online") {
|
|
if (that.data.deviceListIndex !== null && that.data.deviceList[that.data.deviceListIndex].state !== "online") {
|
|
@@ -306,9 +314,11 @@ Page({
|
|
}, 500);
|
|
}, 500);
|
|
return;
|
|
return;
|
|
};
|
|
};
|
|
|
|
+
|
|
if (that.data.deviceList.length === 0 || that.data.deviceListIndex === null) {
|
|
if (that.data.deviceList.length === 0 || that.data.deviceListIndex === null) {
|
|
return
|
|
return
|
|
};
|
|
};
|
|
|
|
+
|
|
let topic = `/AIrSMArT_${that.data.deviceList[that.data.deviceListIndex].name.split("BLUFI_")[1]}/user/pub_response`;
|
|
let topic = `/AIrSMArT_${that.data.deviceList[that.data.deviceListIndex].name.split("BLUFI_")[1]}/user/pub_response`;
|
|
app.subscribe(topic);
|
|
app.subscribe(topic);
|
|
const obj = {
|
|
const obj = {
|
|
@@ -379,10 +389,8 @@ Page({
|
|
type: "get_position",
|
|
type: "get_position",
|
|
...obj
|
|
...obj
|
|
});
|
|
});
|
|
- wx.setStorage({
|
|
|
|
- key: "channelData",
|
|
|
|
- data: res
|
|
|
|
- });
|
|
|
|
|
|
+
|
|
|
|
+ wx.setStorageSync("channelData", res);
|
|
|
|
|
|
// 有新设备
|
|
// 有新设备
|
|
if (app.globalData.newDeviceId) {
|
|
if (app.globalData.newDeviceId) {
|
|
@@ -412,20 +420,10 @@ Page({
|
|
|
|
|
|
goChannel() {
|
|
goChannel() {
|
|
var that = this;
|
|
var that = this;
|
|
- wx.setStorage({
|
|
|
|
- key: "channelDeta",
|
|
|
|
- data: that.data.channelData[that.data.actionIndex],
|
|
|
|
- success() {
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: './../channelDetails/channelDetails'
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- updata() {
|
|
|
|
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
|
|
- wx.getUpdateManager().applyUpdate()
|
|
|
|
|
|
+ wx.setStorageSync("channelDeta", that.data.channelData[that.data.actionIndex]);
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: './../channelDetails/channelDetails'
|
|
|
|
+ });
|
|
},
|
|
},
|
|
|
|
|
|
onUnload() {
|
|
onUnload() {
|
|
@@ -507,18 +505,22 @@ Page({
|
|
var item = e.currentTarget.dataset.item;
|
|
var item = e.currentTarget.dataset.item;
|
|
var ProdModel = item.ProdModel;
|
|
var ProdModel = item.ProdModel;
|
|
if (ProdModel == "MW-2AX(WIFI-N)") {
|
|
if (ProdModel == "MW-2AX(WIFI-N)") {
|
|
- console.log("gadfadsfadsfaf===aa");
|
|
|
|
if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
- console.log("gadfadsfadsfaf===bbb");
|
|
|
|
that.goWake();
|
|
that.goWake();
|
|
} else {
|
|
} else {
|
|
- console.log("gadfadsfadsfaf===ccc");
|
|
|
|
that.actionDevice(e.currentTarget.dataset.index)
|
|
that.actionDevice(e.currentTarget.dataset.index)
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
console.log(e)
|
|
console.log(e)
|
|
|
|
+
|
|
///去蓝牙连接处理
|
|
///去蓝牙连接处理
|
|
|
|
+ // if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
|
|
+ // that.goWake();
|
|
|
|
+ // } else {
|
|
|
|
+ // that.actionDevice(e.currentTarget.dataset.index)
|
|
|
|
+ // }
|
|
|
|
+
|
|
if (item.state !== "online") {
|
|
if (item.state !== "online") {
|
|
that.addConnectBlueDevice({
|
|
that.addConnectBlueDevice({
|
|
deviceId: item.deviceId,
|
|
deviceId: item.deviceId,
|
|
@@ -547,7 +549,7 @@ Page({
|
|
|
|
|
|
that.setData({
|
|
that.setData({
|
|
deviceListIndex: index,
|
|
deviceListIndex: index,
|
|
- thisDeviceMac: `AIrSMArT_${that.data.deviceList[index].name.split("BLUFI_")[1]}`
|
|
|
|
|
|
+ thisDeviceMac: `AIrSMArT_${that.data.deviceList[index].deviceId.split("BLUFI_")[1]}`
|
|
});
|
|
});
|
|
|
|
|
|
// app.PubMsg({
|
|
// app.PubMsg({
|
|
@@ -585,22 +587,17 @@ Page({
|
|
return id !== item.deviceId
|
|
return id !== item.deviceId
|
|
});
|
|
});
|
|
|
|
|
|
- wx.setStorage({
|
|
|
|
- key: "devicelist",
|
|
|
|
- data: JSON.stringify(deviceList),
|
|
|
|
- success() {
|
|
|
|
- that.setData({
|
|
|
|
- deviceList,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 当前没有设备
|
|
|
|
- if (deviceList.length === 0) {
|
|
|
|
- that.setData({
|
|
|
|
- deviceListIndex: null,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ wx.setStorageSync("devicelist", JSON.stringify(deviceList));
|
|
|
|
+ that.setData({
|
|
|
|
+ deviceList,
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ // 当前没有设备
|
|
|
|
+ if (deviceList.length === 0) {
|
|
|
|
+ that.setData({
|
|
|
|
+ deviceListIndex: null,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -614,53 +611,48 @@ Page({
|
|
// 取消订阅
|
|
// 取消订阅
|
|
app.unsubscribe(`/AIrSMArT_${that.data.deviceList[e.currentTarget.dataset.index].name.split("BLUFI_")[1]}/user/pub_response`);
|
|
app.unsubscribe(`/AIrSMArT_${that.data.deviceList[e.currentTarget.dataset.index].name.split("BLUFI_")[1]}/user/pub_response`);
|
|
|
|
|
|
- wx.setStorage({
|
|
|
|
- key: "devicelist",
|
|
|
|
- data: JSON.stringify(deviceList),
|
|
|
|
- success() {
|
|
|
|
|
|
+ wx.setStorageSync("devicelist", JSON.stringify(deviceList));
|
|
|
|
+ that.setData({
|
|
|
|
+ deviceList,
|
|
|
|
+ thisDeviceMac: null
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 当前没有设备
|
|
|
|
+ if (deviceList.length === 0) {
|
|
|
|
+ that.setData({
|
|
|
|
+ actionIndex: null,
|
|
|
|
+ deviceListIndex: null,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (that.data.deviceListIndex === null) {
|
|
|
|
+ return
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
|
|
+ let index_ = null;
|
|
|
|
+ deviceList.map((v, index) => {
|
|
|
|
+ if (v.state === "online" && index_ === null) {
|
|
|
|
+ index_ = index;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (index_ !== null) {
|
|
|
|
+ that.actionDevice(index_);
|
|
|
|
+ } else {
|
|
that.setData({
|
|
that.setData({
|
|
- deviceList,
|
|
|
|
- thisDeviceMac: null
|
|
|
|
|
|
+ actionIndex: null,
|
|
|
|
+ deviceListIndex: null,
|
|
});
|
|
});
|
|
-
|
|
|
|
- // 当前没有设备
|
|
|
|
- if (deviceList.length === 0) {
|
|
|
|
|
|
+ };
|
|
|
|
+ } else {
|
|
|
|
+ deviceList.map((v, index) => {
|
|
|
|
+ if (v.name === name) {
|
|
that.setData({
|
|
that.setData({
|
|
- actionIndex: null,
|
|
|
|
- deviceListIndex: null,
|
|
|
|
|
|
+ deviceListIndex: index,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (that.data.deviceListIndex === null) {
|
|
|
|
- return
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
|
|
- let index_ = null;
|
|
|
|
- deviceList.map((v, index) => {
|
|
|
|
- if (v.state === "online" && index_ === null) {
|
|
|
|
- index_ = index;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (index_ !== null) {
|
|
|
|
- that.actionDevice(index_);
|
|
|
|
- } else {
|
|
|
|
- that.setData({
|
|
|
|
- actionIndex: null,
|
|
|
|
- deviceListIndex: null,
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
- } else {
|
|
|
|
- deviceList.map((v, index) => {
|
|
|
|
- if (v.name === name) {
|
|
|
|
- that.setData({
|
|
|
|
- deviceListIndex: index,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -692,6 +684,7 @@ Page({
|
|
mac: newDevice.mac,
|
|
mac: newDevice.mac,
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ ///在线排序前面,wifi设备排序前面
|
|
var finalList = that.updateDeviceList(deviceList);
|
|
var finalList = that.updateDeviceList(deviceList);
|
|
var indexPage = that.data.indexPage;
|
|
var indexPage = that.data.indexPage;
|
|
if (indexPage != 0) {
|
|
if (indexPage != 0) {
|
|
@@ -706,16 +699,11 @@ Page({
|
|
deviceList: finalList,
|
|
deviceList: finalList,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 更新缓存
|
|
|
|
- wx.setStorage({
|
|
|
|
- key: "devicelist",
|
|
|
|
- data: JSON.stringify(finalList)
|
|
|
|
- });
|
|
|
|
},
|
|
},
|
|
|
|
|
|
addConnectWifiDevice(deviceList) {
|
|
addConnectWifiDevice(deviceList) {
|
|
var that = this;
|
|
var that = this;
|
|
|
|
+ ///在线排序前面,wifi设备排序前面
|
|
var finalList = that.updateDeviceList(deviceList);
|
|
var finalList = that.updateDeviceList(deviceList);
|
|
var indexPage = that.data.indexPage;
|
|
var indexPage = that.data.indexPage;
|
|
if (indexPage != 0) {
|
|
if (indexPage != 0) {
|
|
@@ -730,14 +718,9 @@ Page({
|
|
deviceList: finalList,
|
|
deviceList: finalList,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 更新缓存
|
|
|
|
- wx.setStorage({
|
|
|
|
- key: "devicelist",
|
|
|
|
- data: JSON.stringify(finalList)
|
|
|
|
- });
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ ///更新列表排序
|
|
updateDeviceList(deviceList) {
|
|
updateDeviceList(deviceList) {
|
|
if (deviceList.length == 0) return [];
|
|
if (deviceList.length == 0) return [];
|
|
|
|
|
|
@@ -787,6 +770,8 @@ Page({
|
|
});
|
|
});
|
|
finalList = finalList.concat(onNoLineWifiList);
|
|
finalList = finalList.concat(onNoLineWifiList);
|
|
finalList = finalList.concat(onNoLineWifiList);
|
|
finalList = finalList.concat(onNoLineWifiList);
|
|
|
|
+ // 更新缓存
|
|
|
|
+ wx.setStorageSync("devicelist", JSON.stringify(finalList));
|
|
return finalList;
|
|
return finalList;
|
|
},
|
|
},
|
|
|
|
|