|
@@ -86,50 +86,9 @@ Page({
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- tryConnectBle() {
|
|
|
|
- var hasBle = false;
|
|
|
|
- var hasConnectBle = false;
|
|
|
|
- var hasWifi = false;
|
|
|
|
- var bleDevice;
|
|
|
|
- let that = this
|
|
|
|
- that.data.deviceList.forEach(device => {
|
|
|
|
- if (device.connectType == 1) {
|
|
|
|
- hasBle = true
|
|
|
|
- if (device.state == "online") {
|
|
|
|
- hasConnectBle = true
|
|
|
|
- }
|
|
|
|
- bleDevice = device
|
|
|
|
- } else if (device.connectType == 3 && device.state == "online") {
|
|
|
|
- // wifi
|
|
|
|
- hasWifi = true;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (!hasWifi && !hasConnectBle && hasBle) {
|
|
|
|
- // 没有wifi 没有连接的ble 有未连接的ble
|
|
|
|
- console.log("去连接蓝牙")
|
|
|
|
- let bt_helper = BtHelper.getInstance()
|
|
|
|
- bt_helper.initBluetooth(function (adapterState, hasPermission) {
|
|
|
|
- console.log("蓝牙状态", adapterState, hasPermission)
|
|
|
|
- if (adapterState && hasPermission) {
|
|
|
|
- bt_helper.connect(bleDevice, function (data) {
|
|
|
|
- console.log("连接成功:", data)
|
|
|
|
- if (data == true) {
|
|
|
|
- // 蓝牙模式
|
|
|
|
- bleDevice.connectType = 1
|
|
|
|
- // 在线
|
|
|
|
- bleDevice.state = 'online'
|
|
|
|
- bleDevice.ProdModel = bleDevice.clientType
|
|
|
|
- that.addConnectBlueDevice(connectDevice);
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- } else {}
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
onDeviceLoad() {
|
|
onDeviceLoad() {
|
|
var that = this;
|
|
var that = this;
|
|
- // BtHelper.getInstance().initBluetoothAdapter();
|
|
|
|
|
|
+ BtHelper.getInstance().initBluetoothAdapter();
|
|
var l = store.getStore("deviceList");
|
|
var l = store.getStore("deviceList");
|
|
if (!strings.isEmpty(l)) {
|
|
if (!strings.isEmpty(l)) {
|
|
that.updateDeviceList(l, true);
|
|
that.updateDeviceList(l, true);
|
|
@@ -153,6 +112,18 @@ Page({
|
|
if (deviceList.length > 0) {
|
|
if (deviceList.length > 0) {
|
|
if (BtHelper.getInstance().getCallBackConnect() == null) {
|
|
if (BtHelper.getInstance().getCallBackConnect() == null) {
|
|
var compareList = BtHelper.getInstance().getCompareList();
|
|
var compareList = BtHelper.getInstance().getCompareList();
|
|
|
|
+ var dissmissDevice = BtHelper.getInstance().getDissmissDevice();
|
|
|
|
+
|
|
|
|
+ ///去掉未连接的离线的
|
|
|
|
+ for (var i = 0; i < dissmissDevice.length; i++) {
|
|
|
|
+ for (var j = 0; j < compareList.length; j++) {
|
|
|
|
+ if (compareList[j].deviceId == dissmissDevice[i].deviceId) {
|
|
|
|
+ compareList.splice(j, 1);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (compareList.length > 0) {
|
|
if (compareList.length > 0) {
|
|
///对比在线的蓝牙设备
|
|
///对比在线的蓝牙设备
|
|
var isChanged = false;
|
|
var isChanged = false;
|
|
@@ -163,7 +134,6 @@ Page({
|
|
for (var j = 0; j < compareList.length; j++) {
|
|
for (var j = 0; j < compareList.length; j++) {
|
|
// "state":"online" "offline" MW-SR1(4G_WIFI)
|
|
// "state":"online" "offline" MW-SR1(4G_WIFI)
|
|
if (tempItem.deviceId === compareList[j].deviceId) {
|
|
if (tempItem.deviceId === compareList[j].deviceId) {
|
|
- console.log("gasdfqwerqwerqdfasdfr==00==" + JSON.stringify(compareList[j]));
|
|
|
|
has = true;
|
|
has = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -182,6 +152,7 @@ Page({
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
if (isChanged) {
|
|
if (isChanged) {
|
|
that.updateDeviceList(deviceList, false);
|
|
that.updateDeviceList(deviceList, false);
|
|
}
|
|
}
|
|
@@ -252,7 +223,7 @@ Page({
|
|
|
|
|
|
// 回调
|
|
// 回调
|
|
mqttCallback(type, option) {
|
|
mqttCallback(type, option) {
|
|
- console.log("gadsfadsfadsfa==888===" + type);
|
|
|
|
|
|
+ // console.log("gadsfadsfadsfa==888===" + type);
|
|
var that = this;
|
|
var that = this;
|
|
let payloads = null;
|
|
let payloads = null;
|
|
if (option) {
|
|
if (option) {
|
|
@@ -386,7 +357,7 @@ Page({
|
|
onlineDevice(payloads) {
|
|
onlineDevice(payloads) {
|
|
// 设置在线状态
|
|
// 设置在线状态
|
|
var that = this;
|
|
var that = this;
|
|
- console.log("gadsfadsfadsfa==777===" + JSON.stringify(payloads));
|
|
|
|
|
|
+ // console.log("gadsfadsfadsfa==777===" + JSON.stringify(payloads));
|
|
|
|
|
|
///是否更新过在线离线状态
|
|
///是否更新过在线离线状态
|
|
var isUpdate = false;
|
|
var isUpdate = false;
|
|
@@ -986,21 +957,34 @@ Page({
|
|
if (isInit) {
|
|
if (isInit) {
|
|
deviceList[0].state = "offline";
|
|
deviceList[0].state = "offline";
|
|
}
|
|
}
|
|
- finalList.push(deviceList[0]);
|
|
|
|
- console.log("online", deviceList[0].deviceId, deviceList[0].state);
|
|
|
|
|
|
|
|
- var onLineList = [];
|
|
|
|
- var onNoLineList = [];
|
|
|
|
|
|
+ var isFirstOnline = false;
|
|
|
|
+ if (deviceList[0].state == "online") {
|
|
|
|
+ isFirstOnline = true;
|
|
|
|
+ finalList.push(deviceList[0]);
|
|
|
|
+ }
|
|
|
|
|
|
///区分在线和离线
|
|
///区分在线和离线
|
|
- for (var i = 1; i < deviceList.length; i++) {
|
|
|
|
- var device = deviceList[i];
|
|
|
|
|
|
+ for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
|
|
if (isInit) {
|
|
if (isInit) {
|
|
- device.state = "offline";
|
|
|
|
|
|
+ deviceList[i].state = "offline";
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var onLineList = [];
|
|
|
|
+ var onNoLineList = [];
|
|
|
|
+ ///添加在线的
|
|
|
|
+ for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
|
|
|
|
+ var device = deviceList[i];
|
|
if (device.state == "online") {
|
|
if (device.state == "online") {
|
|
onLineList.push(device)
|
|
onLineList.push(device)
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ///添加离线的
|
|
|
|
+ for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
|
|
|
|
+ var device = deviceList[i];
|
|
|
|
+ if (device.state != "online") {
|
|
onNoLineList.push(device)
|
|
onNoLineList.push(device)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1008,13 +992,19 @@ Page({
|
|
// 区分在线wifi和蓝牙 wifi在前 离线在后
|
|
// 区分在线wifi和蓝牙 wifi在前 离线在后
|
|
var onLineWifiList = [];
|
|
var onLineWifiList = [];
|
|
var onLineBlueList = [];
|
|
var onLineBlueList = [];
|
|
|
|
+ ///添加在线wifi
|
|
onLineList.forEach(element => {
|
|
onLineList.forEach(element => {
|
|
if (element.connectType == 3) {
|
|
if (element.connectType == 3) {
|
|
- onLineWifiList.push(element)
|
|
|
|
- } else {
|
|
|
|
|
|
+ onLineWifiList.push(element);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ ///添加在线蓝牙
|
|
|
|
+ onLineList.forEach(element => {
|
|
|
|
+ if (element.connectType != 3) {
|
|
onLineBlueList.push(element)
|
|
onLineBlueList.push(element)
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
finalList = finalList.concat(onLineWifiList);
|
|
finalList = finalList.concat(onLineWifiList);
|
|
finalList = finalList.concat(onLineBlueList);
|
|
finalList = finalList.concat(onLineBlueList);
|
|
|
|
|
|
@@ -1026,13 +1016,19 @@ Page({
|
|
///区分离线wifi和蓝牙 wifi在前 离线在后
|
|
///区分离线wifi和蓝牙 wifi在前 离线在后
|
|
var onNoLineWifiList = [];
|
|
var onNoLineWifiList = [];
|
|
var onNoLineBlueList = [];
|
|
var onNoLineBlueList = [];
|
|
|
|
+ ///添加离线wifi
|
|
onNoLineList.forEach(element => {
|
|
onNoLineList.forEach(element => {
|
|
if (element.connectType == 3) {
|
|
if (element.connectType == 3) {
|
|
onNoLineWifiList.push(element)
|
|
onNoLineWifiList.push(element)
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ ///添加离线蓝牙
|
|
|
|
+ onNoLineList.forEach(element => {
|
|
|
|
+ if (element.connectType != 3) {
|
|
onNoLineBlueList.push(element)
|
|
onNoLineBlueList.push(element)
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
finalList = finalList.concat(onNoLineWifiList);
|
|
finalList = finalList.concat(onNoLineWifiList);
|
|
finalList = finalList.concat(onNoLineBlueList);
|
|
finalList = finalList.concat(onNoLineBlueList);
|
|
|
|
|
|
@@ -1127,6 +1123,48 @@ Page({
|
|
},
|
|
},
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+
|
|
|
|
+// tryConnectBle() {
|
|
|
|
+// var hasBle = false;
|
|
|
|
+// var hasConnectBle = false;
|
|
|
|
+// var hasWifi = false;
|
|
|
|
+// var bleDevice;
|
|
|
|
+// let that = this
|
|
|
|
+// that.data.deviceList.forEach(device => {
|
|
|
|
+// if (device.connectType == 1) {
|
|
|
|
+// hasBle = true
|
|
|
|
+// if (device.state == "online") {
|
|
|
|
+// hasConnectBle = true
|
|
|
|
+// }
|
|
|
|
+// bleDevice = device
|
|
|
|
+// } else if (device.connectType == 3 && device.state == "online") {
|
|
|
|
+// // wifi
|
|
|
|
+// hasWifi = true;
|
|
|
|
+// }
|
|
|
|
+// });
|
|
|
|
+// if (!hasWifi && !hasConnectBle && hasBle) {
|
|
|
|
+// // 没有wifi 没有连接的ble 有未连接的ble
|
|
|
|
+// console.log("去连接蓝牙")
|
|
|
|
+// let bt_helper = BtHelper.getInstance()
|
|
|
|
+// bt_helper.initBluetooth(function (adapterState, hasPermission) {
|
|
|
|
+// console.log("蓝牙状态", adapterState, hasPermission)
|
|
|
|
+// if (adapterState && hasPermission) {
|
|
|
|
+// bt_helper.connect(bleDevice, function (data) {
|
|
|
|
+// console.log("连接成功:", data)
|
|
|
|
+// if (data == true) {
|
|
|
|
+// // 蓝牙模式
|
|
|
|
+// bleDevice.connectType = 1
|
|
|
|
+// // 在线
|
|
|
|
+// bleDevice.state = 'online'
|
|
|
|
+// bleDevice.ProdModel = bleDevice.clientType
|
|
|
|
+// that.addConnectBlueDevice(connectDevice);
|
|
|
|
+// }
|
|
|
|
+// })
|
|
|
|
+// } else {}
|
|
|
|
+// })
|
|
|
|
+// }
|
|
|
|
+// },
|
|
|
|
+
|
|
// 去掉此功能,先留着吧
|
|
// 去掉此功能,先留着吧
|
|
// const other= {
|
|
// const other= {
|
|
// "url": "",
|
|
// "url": "",
|