Browse Source

feature: 处理在线和离线问题,搜索频率太多的问题

Damon 8 months ago
parent
commit
c16f20c251
2 changed files with 21 additions and 12 deletions
  1. 7 8
      devices/ble_manager.js
  2. 14 4
      pages/index/index.js

+ 7 - 8
devices/ble_manager.js

@@ -153,16 +153,18 @@ class bleManager {
 
 
   // 开始搜索蓝牙设备
   // 开始搜索蓝牙设备
   async startScan(connectWillDevice, boolean, callBackConnect) {
   async startScan(connectWillDevice, boolean, callBackConnect) {
-
-
     var that = this;
     var that = this;
+    const route_util = require('../utils/route_util');
     const route_constant = require('../utils/route_constant');
     const route_constant = require('../utils/route_constant');
+    const indexRoot = route_constant.indexRoot;
     const connectBleRoot = route_constant.connectBleRoot;
     const connectBleRoot = route_constant.connectBleRoot;
-    const route_util = require('../utils/route_util');
     var lastPageRoute = route_util.getLastPageRoute();
     var lastPageRoute = route_util.getLastPageRoute();
+    if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
+      return;
+    }
 
 
     ///蓝牙连接 做限制
     ///蓝牙连接 做限制
-    if (callBackConnect == null && lastPageRoute != connectBleRoot) {
+    if (lastPageRoute == indexRoot) {
       if (that.doStartScaning == true) {
       if (that.doStartScaning == true) {
         return;
         return;
       }
       }
@@ -177,15 +179,12 @@ class bleManager {
       waitMills = delayMiliis - reduce;
       waitMills = delayMiliis - reduce;
     }
     }
 
 
-    if (callBackConnect == null && lastPageRoute == connectBleRoot) {
-      return;
-    }
-
     if (waitMills > 0) {
     if (waitMills > 0) {
       await that.delay(waitMills);
       await that.delay(waitMills);
     }
     }
 
 
     if (callBackConnect == null && lastPageRoute == connectBleRoot) {
     if (callBackConnect == null && lastPageRoute == connectBleRoot) {
+      that.doStartScaning = false;
       return;
       return;
     }
     }
 
 

+ 14 - 4
pages/index/index.js

@@ -145,7 +145,7 @@ Page({
       ///再秒再对比一次
       ///再秒再对比一次
       that.data.intervalId = setInterval(async function () {
       that.data.intervalId = setInterval(async function () {
         that.compareList();
         that.compareList();
-      }, 10 * 1000);
+      }, 5 * 1000);
     }, 3 * 1000);
     }, 3 * 1000);
   },
   },
 
 
@@ -162,14 +162,24 @@ Page({
           if (tempItem.connectType != 3) {
           if (tempItem.connectType != 3) {
             var has = false;
             var has = false;
             for (var j = 0; j < compareList.length; j++) {
             for (var j = 0; j < compareList.length; j++) {
-              // "state":"online"
+              // "state":"online" "offline"
               if (tempItem.deviceId === compareList[j].deviceId) {
               if (tempItem.deviceId === compareList[j].deviceId) {
                 has = true;
                 has = true;
-                isChanged = true;
                 break;
                 break;
               }
               }
             }
             }
-            tempItem.state = has ? "online" : "offline";
+
+            if (has) {
+              if (tempItem.state != "online") {
+                isChanged = true;
+                tempItem.state = "online";
+              }
+            } else {
+              if (tempItem.state != "offline") {
+                isChanged = true;
+                tempItem.state = "offline";
+              }
+            }
           }
           }
         }
         }
         if (isChanged) {
         if (isChanged) {