瀏覽代碼

feature: 解决蓝牙,多个离线不能删除的问题

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

+ 10 - 17
pages/index/index.js

@@ -41,11 +41,11 @@ Page({
     isLogin: false,
     greeting: "",
     bannerList: [{
-      "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
-    },
-    {
-      "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
-    }
+        "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
+      },
+      {
+        "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
+      }
     ],
     autoplay: true,
     interval: 3000, // 切换时间间隔
@@ -235,7 +235,7 @@ Page({
       ///监听蓝牙设备
       BtHelper.getInstance().initBluetoothAdapter();
       BtHelper.getInstance().getBluetoothDevices();
-      BtHelper.getInstance().startScan(null, null, function (res) { });
+      BtHelper.getInstance().startScan(null, null, function (res) {});
       var isFirst = true;
       console.log("开始监听蓝牙设备");
       ///再秒再对比一次
@@ -319,7 +319,7 @@ Page({
       case "connect":
         lexin_subscribe.subscribeAllDevice();
         break;
-      ///再走有在线
+        ///再走有在线
       case "message_onoffline":
         lexin_connect.searchOnlineDevice(payloads, function (list) {
           that.updateDeviceList(list, false, false);
@@ -653,10 +653,6 @@ Page({
     var that = this;
     var deviceList = that.getDeviceList();
     var deviceListSelect = that.getDeviceListSelect();
-    if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
-      return;
-    };
-
     if (deviceList[deviceListSelect].connectType == 3) {
       that.cancelWifi(deviceListSelect, true);
     } else {
@@ -673,11 +669,6 @@ Page({
     var deviceList = that.getDeviceList();
     var deviceListSelect = that.getDeviceListSelect();
 
-    if (deviceList.length > 1 && (deviceListSelect === null || deviceList.length <= deviceListSelect)) {
-      // 2个设备才判断,1个直接删除
-      return;
-    };
-
     ///是否删除的当前播放这个
     var isCurrentIndex = false;
     deviceListSelect = deviceListSelect ?? 0;
@@ -692,7 +683,9 @@ Page({
     });
     console.log("断开蓝牙连接", deviceId)
 
-    BtHelper.getInstance().disconnect({ "deviceId": deviceId });
+    BtHelper.getInstance().disconnect({
+      "deviceId": deviceId
+    });
 
     store.setStore("deviceList", deviceList);
     var indexPage = that.data.indexPage;