Przeglądaj źródła

feature: 调整添加蓝牙设备连接成功后数据处理

332777428@qq.com 6 miesięcy temu
rodzic
commit
616d87ebbc
1 zmienionych plików z 33 dodań i 5 usunięć
  1. 33 5
      pages/pageA/index/index.js

+ 33 - 5
pages/pageA/index/index.js

@@ -517,11 +517,22 @@ Page({
     }
 
     ///去蓝牙连接处理
-    if (index === deviceListSelect) {
-      var param = '?param=' + JSON.stringify(device);
-      route_util.jumpParam('/pages/pageC/deviceDetail/detail', param);
+    // {"connectType":1,"deviceId":"E4:9F:80:09:40:EC","name":"E4:9F:80:09:40:EC","state":"online","ProdModel":"MW-SR1(4G_WIFI)","devName":"猫王音响x阿基米德 SR1 妙播收音机"}
+    if (index === deviceListSelect && device.state === "online") {
+      route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(device))
     } else if (device.state === "offline") {
-      console.log("去连接蓝牙", device)
+
+      var deviceList = that.getDeviceList();
+      var deviceListSelect = that.getDeviceListSelect();
+      if (deviceListSelect != null && deviceList.length > deviceListSelect) {
+        that.setData({
+          deviceListSelect: null,
+        });
+        var currentDevice = deviceList[deviceListSelect];
+        await BtHelper.getInstance().disconnect(currentDevice);
+        // await time_util.delayMills(500);
+      }
+
       device.name = device.devName;
       BtHelper.getInstance().connect(device, function (isConnected, d) {
         if (isConnected) {
@@ -530,7 +541,24 @@ Page({
         }
       });
     } else {
-      // {"connectType":1,"deviceId":"E4:9F:80:09:40:EC","name":"E4:9F:80:09:40:EC","state":"online","ProdModel":"MW-SR1(4G_WIFI)","devName":"猫王音响x阿基米德 SR1 妙播收音机"}
+      var deviceList = that.getDeviceList();
+      var deviceListSelect = that.getDeviceListSelect();
+      if (deviceListSelect != null && deviceList.length > deviceListSelect) {
+        that.setData({
+          deviceListSelect: null,
+        });
+        var currentDevice = deviceList[deviceListSelect];
+        await BtHelper.getInstance().disconnect(currentDevice);
+        // await time_util.delayMills(500);
+      }
+
+      device.name = device.devName;
+      BtHelper.getInstance().connect(device, function (isConnected, d) {
+        if (isConnected) {
+          device.state = "online";
+          that.addBlueDevice(device);
+        }
+      });
     }
   },