|
@@ -132,10 +132,7 @@ Page({
|
|
|
// BtHelper.getInstance().initBluetoothAdapter();
|
|
|
var l = store.getStore("deviceList");
|
|
|
if (!strings.isEmpty(l)) {
|
|
|
- try {
|
|
|
- that.updateDeviceList(l, true);
|
|
|
- } catch (e) {}
|
|
|
- // that.tryConnectBle()
|
|
|
+ that.updateDeviceList(l, true);
|
|
|
}
|
|
|
|
|
|
///监听蓝牙设备
|
|
@@ -152,15 +149,15 @@ Page({
|
|
|
|
|
|
async compareList() {
|
|
|
var that = this;
|
|
|
- var tempList = that.data.deviceList;
|
|
|
- if (tempList.length > 0) {
|
|
|
+ var deviceList = that.data.deviceList;
|
|
|
+ if (deviceList.length > 0) {
|
|
|
if (BtHelper.getInstance().getCallBackConnect() == null) {
|
|
|
var compareList = BtHelper.getInstance().getCompareList();
|
|
|
if (compareList.length > 0) {
|
|
|
///对比在线的蓝牙设备
|
|
|
var isChanged = false;
|
|
|
- for (var i = 0; i < tempList.length; i++) {
|
|
|
- var tempItem = tempList[i];
|
|
|
+ for (var i = 0; i < deviceList.length; i++) {
|
|
|
+ var tempItem = deviceList[i];
|
|
|
if (tempItem.connectType != 3) {
|
|
|
var has = false;
|
|
|
for (var j = 0; j < compareList.length; j++) {
|
|
@@ -185,7 +182,7 @@ Page({
|
|
|
}
|
|
|
}
|
|
|
if (isChanged) {
|
|
|
- that.updateDeviceList(tempList, false);
|
|
|
+ that.updateDeviceList(deviceList, false);
|
|
|
}
|
|
|
|
|
|
///没有连接则连接第一个在线的蓝牙
|
|
@@ -445,7 +442,6 @@ Page({
|
|
|
if (!strings.isEmpty(deviceList)) {
|
|
|
for (var i = 0; i < deviceList.length; i++) {
|
|
|
if (deviceList[i].connectType == 3) {
|
|
|
-
|
|
|
let topic = `/AIrSMArT_${deviceList[i].deviceId.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
app.subscribe(topic);
|
|
|
}
|
|
@@ -470,12 +466,12 @@ Page({
|
|
|
return
|
|
|
};
|
|
|
|
|
|
- var tempDevice = that.data.deviceList[deviceListIndex];
|
|
|
- var tempDeviceId = tempDevice.deviceId;
|
|
|
+ var device = that.data.deviceList[deviceListIndex];
|
|
|
+ var tempDeviceId = device.deviceId;
|
|
|
///删除当前选中这个
|
|
|
deviceList.splice(deviceListIndex, 1);
|
|
|
///添加到第一个去
|
|
|
- deviceList.unshift(tempDevice);
|
|
|
+ deviceList.unshift(device);
|
|
|
that.setData({
|
|
|
deviceListIndex: 0,
|
|
|
autoConnected: true,
|
|
@@ -619,9 +615,9 @@ Page({
|
|
|
///有设备在线被选中,则让它不被选择
|
|
|
var deviceListIndex = that.data.deviceListIndex;
|
|
|
if (deviceListIndex != null) {
|
|
|
- var list = that.data.deviceList;
|
|
|
- if (list.length > deviceListIndex) {
|
|
|
- if (list[deviceListIndex].connectType == 3) {
|
|
|
+ var deviceList = that.data.deviceList;
|
|
|
+ if (deviceList.length > deviceListIndex) {
|
|
|
+ if (deviceList[deviceListIndex].connectType == 3) {
|
|
|
if (that.data.thisDeviceMac !== null) {
|
|
|
app.unsubscribe(`/${that.data.thisDeviceMac}/user/pub_response`);
|
|
|
that.setData({
|
|
@@ -926,7 +922,6 @@ Page({
|
|
|
|
|
|
///在线排序前面,wifi设备排序前面
|
|
|
that.updateDeviceList(deviceList, false);
|
|
|
-
|
|
|
var indexPage = that.data.indexPage;
|
|
|
if (indexPage != 0) {
|
|
|
that.setData({
|
|
@@ -981,8 +976,6 @@ Page({
|
|
|
|
|
|
///更新列表排序
|
|
|
updateDeviceList(deviceList, isInit) {
|
|
|
- console.log("更新设备列表0:", deviceList);
|
|
|
-
|
|
|
if (deviceList.length <= 0) {
|
|
|
return;
|
|
|
}
|
|
@@ -996,17 +989,15 @@ Page({
|
|
|
var onNoLineList = [];
|
|
|
|
|
|
///区分在线和离线
|
|
|
- for (var i = 0; i < deviceList.length; i++) {
|
|
|
+ for (var i = 1; i < deviceList.length; i++) {
|
|
|
+ var device = deviceList[i];
|
|
|
if (isInit) {
|
|
|
- deviceList[i].state = "offline";
|
|
|
+ device.state = "offline";
|
|
|
+ }
|
|
|
+ if (device.state == "online") {
|
|
|
+ onLineList.push(device)
|
|
|
} else {
|
|
|
- if (i > 0) {
|
|
|
- if (deviceList[i].state == "online") {
|
|
|
- onLineList.push(deviceList[i])
|
|
|
- } else {
|
|
|
- onNoLineList.push(deviceList[i])
|
|
|
- }
|
|
|
- }
|
|
|
+ onNoLineList.push(device)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1041,7 +1032,7 @@ Page({
|
|
|
finalList = finalList.concat(onNoLineWifiList);
|
|
|
finalList = finalList.concat(onNoLineBlueList);
|
|
|
|
|
|
- store.setStore("deviceList", deviceList);
|
|
|
+ store.setStore("deviceList", finalList);
|
|
|
that.setData({
|
|
|
deviceList: finalList
|
|
|
});
|