瀏覽代碼

feature: WiFi连接X2和蓝牙连接并选中黑胶音箱时,其他手机WiFi连接X2后,当前小程序X2设备会自选中

332777428@qq.com 5 月之前
父節點
當前提交
4920f52b1b
共有 1 個文件被更改,包括 17 次插入14 次删除
  1. 17 14
      pages/index/index.js

+ 17 - 14
pages/index/index.js

@@ -79,7 +79,7 @@ Page({
 
     deviceMacId: null,
     deviceListSelect: null,
-    deviceList:[],
+    deviceList: [],
     // deviceList: [{
     //   "connectType": 3,
     //   // "mac": "AIrSMArT_861210052356337",
@@ -630,14 +630,16 @@ Page({
     } else if (device.state === "offline") {
 
       var deviceListSelect = that.getDeviceListSelect();
-      if (deviceListSelect != null && deviceList.length > deviceListSelect) {
+      if (deviceListSelect != null) {
+        if (deviceList.length > deviceListSelect) {
+          var currentDevice = deviceList[deviceListSelect];
+          console.log("断开连接0", currentDevice)
+          // 现断线第一个
+          // that.disconnectFirst()
+        }
         that.setData({
           deviceListSelect: null,
         });
-        var currentDevice = deviceList[deviceListSelect];
-        console.log("断开连接0", currentDevice)
-        // 现断线第一个
-        // that.disconnectFirst()
       }
       console.log("断开连接2", device)
 
@@ -651,17 +653,18 @@ Page({
     } else {
       var deviceList = that.getDeviceList();
       var deviceListSelect = that.getDeviceListSelect();
-      if (deviceListSelect != null && deviceList.length > deviceListSelect) {
+      if (deviceListSelect != null) {
+        if (deviceList.length > deviceListSelect) {
+          var currentDevice = deviceList[deviceListSelect];
+          if (currentDevice.connectType === 1) {
+            console.log("断开连接1", currentDevice)
+            await BtHelper.getInstance().disconnect(currentDevice);
+          }
+          // await time_util.delayMills(500);
+        }
         that.setData({
           deviceListSelect: null,
         });
-        var currentDevice = deviceList[deviceListSelect];
-        if (currentDevice.connectType === 1) {
-          console.log("断开连接1", currentDevice)
-          await BtHelper.getInstance().disconnect(currentDevice);
-
-        }
-        // await time_util.delayMills(500);
       }
 
       device.name = device.devName;