浏览代码

feature: 处理数据

Damon 8 月之前
父节点
当前提交
ecb26e7f17
共有 5 个文件被更改,包括 56 次插入8 次删除
  1. 44 2
      devices/ble_manager.js
  2. 2 2
      pages/connectBle/connectBle.js
  3. 2 1
      pages/deviceConnect3/deviceConnect3.js
  4. 7 2
      pages/index/index.js
  5. 1 1
      pages/index/index.wxml

+ 44 - 2
devices/ble_manager.js

@@ -35,6 +35,14 @@ class bleManager {
   /// 监控蓝牙打开状态
   initBluetoothAdapter() {
     var that = this;
+    wx.openBluetoothAdapter({
+      success: (res) => {
+        that.isAvailable = true;
+      },
+      fail: (err) => {
+        that.isAvailable = false;
+      }
+    });
     wx.onBluetoothAdapterStateChange(function (res) {
       that.isAvailable = res.available;
     })
@@ -149,8 +157,6 @@ class bleManager {
     return new Promise(resolve => setTimeout(resolve, ms));
   }
 
-
-
   // 开始搜索蓝牙设备
   async startScan(connectWillDevice, boolean, callBackConnect) {
     var that = this;
@@ -163,6 +169,17 @@ class bleManager {
       return;
     }
 
+    if (!that.isAvailable) {
+      if (lastPageRoute == connectBleRoot) {
+        wx.showToast({
+          title: '蓝牙未打开',
+          icon: "none",
+          duration: 2000
+        })
+      }
+      return;
+    }
+
     ///蓝牙连接 做限制
     if (lastPageRoute == indexRoot) {
       if (that.doStartScaning == true) {
@@ -188,6 +205,27 @@ class bleManager {
       return;
     }
 
+    // wx.startBluetoothDevicesDiscovery({
+    //   allowDuplicatesKey: true,
+    //   success: function (res) {
+    //     that.doStartScaning = false;
+    //     that.requestBlueTime = that.getCurrentMills();
+    //     if (boolean != null) {
+    //       boolean(true);
+    //     }
+    //     that.setConnectWillDevice(connectWillDevice);
+    //     that.setCallBackConnect(callBackConnect);
+    //     that.compareList = [];
+    //   },
+    //   fail(err) {
+    //     that.doStartScaning = false;
+    //     that.requestBlueTime = that.getCurrentMills();
+    //     if (boolean != null) {
+    //       boolean(false);
+    //     }
+    //   },
+    // })
+
     wx.closeBluetoothAdapter({
       complete: function (res) {
         wx.openBluetoothAdapter({
@@ -195,9 +233,11 @@ class bleManager {
             wx.getBluetoothAdapterState({
               success: function (res) {
                 that.doStartScaning = false;
+                console.log("gadsfasdfqwerqwerqwerqr==xxx==" + JSON.stringify(res));
               },
               fail(err) {
                 that.doStartScaning = false;
+                console.log("gadsfasdfqwerqwerqwerqr==yyyy==" + JSON.stringify(res));
                 if (boolean != null) {
                   boolean(false);
                 }
@@ -206,6 +246,7 @@ class bleManager {
             wx.startBluetoothDevicesDiscovery({
               allowDuplicatesKey: false,
               success: function (res) {
+                console.log("gadsfasdfqwerqwerqwerqr==mmmm==" + JSON.stringify(res));
                 that.doStartScaning = false;
                 that.requestBlueTime = that.getCurrentMills();
                 if (boolean != null) {
@@ -216,6 +257,7 @@ class bleManager {
                 that.compareList = [];
               },
               fail(err) {
+                console.log("gadsfasdfqwerqwerqwerqr==nnnn==" + JSON.stringify(err));
                 that.doStartScaning = false;
                 that.requestBlueTime = that.getCurrentMills();
                 if (boolean != null) {

+ 2 - 2
pages/connectBle/connectBle.js

@@ -61,8 +61,8 @@ Page({
       console.log("连接成功:", data)
       that.setStatus(data ? 3 : 4)
       if (data) {
-        that.data.connectDevice.connectType = 1
-        that.data.connectDevice.state = 'online'
+        that.data.connectDevice.connectType = 1;
+        that.data.connectDevice.state = 'online';
         var connectDevice = that.data.connectDevice;
         getCurrentPages()[0].addConnectBlueDevice(connectDevice);
         route_util.goBackRoute(route_constant.indexRoot);

+ 2 - 1
pages/deviceConnect3/deviceConnect3.js

@@ -126,7 +126,8 @@ Page({
                     connectType: 3,
                     deviceId: _this.data.name,
                     name: _this.data.name,
-                    state: "online"
+                    state: "online",
+                    image: "./../../img/min.png",
                   });
 
                   getCurrentPages()[0].addConnectWifiDevice(arr);

+ 7 - 2
pages/index/index.js

@@ -141,12 +141,14 @@ Page({
     ///3秒去处理一下
     BtHelper.getInstance().startScan(null, null, null);
     ///先接收数据
+    var isFirst = true;
     setTimeout(() => {
       that.compareList();
       ///再秒再对比一次
       that.data.intervalId = setInterval(async function () {
+        isFirst = false;
         that.compareList();
-      }, 5 * 1000);
+      }, isFirst ? 5 * 1000 : 10 * 1000);
     }, 3 * 1000);
   },
 
@@ -154,6 +156,7 @@ Page({
     var that = this;
     if (BtHelper.getInstance().getCallBackConnect() == null) {
       var compareList = BtHelper.getInstance().getCompareList();
+      console.log("gadsfasdfqwerqwerqwerqr==000==" + compareList.length);
       if (compareList.length > 0) {
         ///对比在线的蓝牙设备
         var isChanged = false;
@@ -167,6 +170,7 @@ Page({
                 // "state":"online" "offline"
                 if (tempItem.deviceId === compareList[j].deviceId) {
                   has = true;
+                  console.log("gadsfasdfqwerqwerqwerqr==111==" + JSON.stringify(tempItem));
                   break;
                 }
               }
@@ -208,6 +212,7 @@ Page({
           }
         }
       }
+      await BtHelper.getInstance().stopSearch();
       BtHelper.getInstance().startScan(null, null, null);
     }
   },
@@ -675,7 +680,7 @@ Page({
       return;
     }
 
-    if (item.connectType != "1") {
+    if (item.connect != "1") {
       return
     }
     ///去蓝牙连接处理

+ 1 - 1
pages/index/index.wxml

@@ -23,7 +23,7 @@
         <block wx:key="key" wx:for-item="item" wx:for-index="index" wx:for="{{deviceList}}">
           <view class="item_public" style="width: calc(100vw - 72rpx);border: {{item.state && item.state === 'online'&&deviceListIndex === index  ? '4rpx solid #6546A3' : item.state && item.state === 'online'?'2rpx solid #6546A3':'2rpx solid #F2F5F7'}}; margin-left: {{item.state && item.state === 'online'&&deviceListIndex === index  ?0:4}}rpx;" data-item="{{item}}" data-index="{{index}}" bind:tap="onTapItem">
 
-            <image class="item_public_image" src="{{item.image}}" style="opacity: {{item.state && item.state === 'online' ? '1' : '0.5'}};"></image>
+            <image class="item_public_image" src="./../../img/min.png" style="opacity: {{item.state && item.state === 'online' ? '1' : '0.5'}};"></image>
             <view class="item_public_right" style="margin-right: 26rpx; opacity: {{item.state && item.state === 'online' ? '1' : '0.5'}};">
               <view style="height: 190rpx; margin-top: 37rpx; margin-left: 32rpx; flex-direction: column; display: flex;">
                 <view style="flex: 1;">