Browse Source

feature: 解决多个设备蓝牙切换效果不明显的问题

332777428@qq.com 6 months ago
parent
commit
5b45dee398
1 changed files with 16 additions and 4 deletions
  1. 16 4
      pages/index/index.js

+ 16 - 4
pages/index/index.js

@@ -4,7 +4,7 @@ const {
   listByDevice
 } = require('../../utils/api.js');
 
-import timeUtil from '../../utils/time_util.js';
+import time_util from '../../utils/time_util.js';
 import strings from '../../utils/strings.js';
 import store from '../../utils/store.js';
 import route_constant from '../../utils/route_constant.js';
@@ -587,11 +587,12 @@ Page({
       var deviceList = that.getDeviceList();
       var deviceListSelect = that.getDeviceListSelect();
       if (deviceListSelect != null && deviceList.length > deviceListSelect) {
-        var currentDevice = deviceList[deviceListSelect];
-        await that.disconnect(currentDevice);
         that.setData({
           deviceListSelect: null,
         });
+        var currentDevice = deviceList[deviceListSelect];
+        await BtHelper.getInstance().disconnect(currentDevice);
+        // await time_util.delayMills(500);
       }
 
       device.name = device.devName;
@@ -602,6 +603,17 @@ Page({
         }
       });
     } else {
+      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) {
@@ -994,7 +1006,7 @@ Page({
   },
 
   getGreetBuNickName(nickName) {
-    var greeting = timeUtil.getGreet();
+    var greeting = time_util.getGreet();
     if (nickName != "" && nickName != "未登录") {
       greeting = greeting + ',' + nickName;;
     }