Преглед на файлове

feature: 首页第一次自动连接和搜索

Damon преди 7 месеца
родител
ревизия
cc5f817e20
променени са 1 файла, в които са добавени 28 реда и са изтрити 47 реда
  1. 28 47
      devices/ble_manager.js

+ 28 - 47
devices/ble_manager.js

@@ -209,59 +209,39 @@ class bleManager {
   // 开始搜索蓝牙设备
   async startScan(connectWillDevice, boolean, callBackConnect) {
     var that = this;
-    if (that.doStartScaning == true) {
-      that.doStartScaning = false;
-      if (boolean != null) {
-        boolean(false);
-      }
+    const route_util = require('../utils/route_util');
+    const route_constant = require('../utils/route_constant');
+    const indexRoot = route_constant.indexRoot;
+    const connectBleRoot = route_constant.connectBleRoot;
+    var lastPageRoute = route_util.getLastPageRoute();
+    if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
       return;
     }
-    that.doStartScaning = true;
-
-    // const route_util = require('../utils/route_util');
-    // const route_constant = require('../utils/route_constant');
-    // const indexRoot = route_constant.indexRoot;
-    // const connectBleRoot = route_constant.connectBleRoot;
-    // var lastPageRoute = route_util.getLastPageRoute();
-    // if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
-    //   return;
-    // }
-
-    // if (!that.isAvailable) {
-    //   if (lastPageRoute == connectBleRoot) {
-    //     wx.showToast({
-    //       title: '蓝牙未打开',
-    //       icon: "none",
-    //       duration: 2000
-    //     })
-    //   }
-    //   return;
-    // }
 
     ///蓝牙连接 做限制
-    // if (lastPageRoute == indexRoot) {
-    //   if (that.doStartScaning == true) {
-    //     return;
-    //   }
-    // }
+    if (lastPageRoute == indexRoot) {
+      if (that.doStartScaning == true) {
+        return;
+      }
+    }
 
-    // that.doStartScaning = true;
-    // var currentMill = that.getCurrentMills();
-    // var waitMills = 0;
-    // var reduce = currentMill - that.requestBlueTime;
-    // const delayMiliis = 5 * 1000;
-    // if (reduce > 0 && reduce < delayMiliis) {
-    //   waitMills = delayMiliis - reduce;
-    // }
+    that.doStartScaning = true;
+    var currentMill = that.getCurrentMills();
+    var waitMills = 0;
+    var reduce = currentMill - that.requestBlueTime;
+    const delayMiliis = 5 * 1000;
+    if (reduce > 0 && reduce < delayMiliis) {
+      waitMills = delayMiliis - reduce;
+    }
 
-    // if (waitMills > 0) {
-    //   await that.delay(waitMills);
-    // }
+    if (waitMills > 0) {
+      await that.delay(waitMills);
+    }
 
-    // if (callBackConnect == null && lastPageRoute == connectBleRoot) {
-    //   that.doStartScaning = false;
-    //   return;
-    // }
+    if (callBackConnect == null && lastPageRoute == connectBleRoot) {
+      that.doStartScaning = false;
+      return;
+    }
 
     wx.openBluetoothAdapter({
       success: function (res) {
@@ -271,6 +251,7 @@ class bleManager {
           },
           fail: (err) => {
             that.doStartScaning = false;
+            that.requestBlueTime = that.getCurrentMills();
             if (boolean != null) {
               boolean(false);
             }
@@ -299,6 +280,7 @@ class bleManager {
       allowDuplicatesKey: true,
       success: function (res) {
         that.getConnectedDevices();
+
         that.doStartScaning = false;
         that.requestBlueTime = that.getCurrentMills();
         if (boolean != null) {
@@ -309,7 +291,6 @@ class bleManager {
         that.compareList = [];
       },
       fail(err) {
-        console.log("gadsfqwerqewrqrqr===" + JSON.stringify(err));
         that.doStartScaning = false;
         that.requestBlueTime = that.getCurrentMills();
         if (boolean != null) {