Jelajahi Sumber

feature: 数据储存

332777428@qq.com 6 bulan lalu
induk
melakukan
0150f11d8e
2 mengubah file dengan 70 tambahan dan 49 penghapusan
  1. 60 49
      devices/ble_manager.js
  2. 10 0
      utils/lexin/devices.js

+ 60 - 49
devices/ble_manager.js

@@ -50,31 +50,7 @@ class bleManager {
         that.dissmissDevice = [];
         getCurrentPages()[0].closeBlueResetOffline(false, true);
       }
-    })
-    if (that.isAvailable) {
-      return;
-    }
-    wx.openBluetoothAdapter({
-      success: function (res) {
-        that.isAvailable = res.available;
-      },
-      fail: function (res) {
-        that.isAvailable = res.available;
-        console.log("打开蓝牙成功2", res);
-        // wx.showModal({
-        //   title: '提示',
-        //   content: '请检查手机蓝牙是否打开',
-        //   showCancel: false,
-        //   success: function (res) { }
-        // });
-
-        // that.doStartScaning = false;
-        // that.requestBlueTime = that.getCurrentMills();
-        // if (boolean != null) {
-        //   boolean(false);
-        // }
-      }
-    })
+    });
   }
 
   ///监听搜索设备列表
@@ -297,9 +273,17 @@ class bleManager {
     var that = this;
 
     ///限制搜索没有打开蓝牙一直询问打开蓝牙
-    var isAvailable = that.isAvailable;
-    if (!isAvailable && callBackConnect == null) {
-      return;
+    if (!that.isAvailable) {
+      if (callBackConnect == null) {
+        return;
+      }
+
+      ///连接设备
+      var isAvailable = await that.openBluetoothAdapter();
+      if (!isAvailable) {
+        boolean(false);
+        return;
+      }
     }
 
     const route_util = require('../utils/route_util');
@@ -337,6 +321,7 @@ class bleManager {
       that.doStartScaning = false;
       return;
     }
+
     wx.stopBluetoothDevicesDiscovery({
       success: (res) => {
         console.log("停止搜索设备0", res);
@@ -351,26 +336,52 @@ class bleManager {
         }
       }
     });
+  }
 
-    // wx.openBluetoothAdapter({
-    //   success: function (res) {
-
-    //   },
-    //   fail: function (res) {
-    //     console.log("打开蓝牙成功2", res);
-    //     // wx.showModal({
-    //     //   title: '提示',
-    //     //   content: '请检查手机蓝牙是否打开',
-    //     //   showCancel: false,
-    //     //   success: function (res) { }
-    //     // });
-    //     that.doStartScaning = false;
-    //     that.requestBlueTime = that.getCurrentMills();
-    //     if (boolean != null) {
-    //       boolean(false);
-    //     }
-    //   }
-    // })
+  ///打开蓝牙适配
+  openBluetoothAdapter() {
+    var that = this;
+    return new Promise((resolve, reject) => {
+      wx.openBluetoothAdapter({
+        success: function (res) {
+          that.isAvailable = res.available;
+          console.log("sdfasdfadsf==00==" + that.isAvailable + "===" + JSON.stringify(res));
+          resolve(that.isAvailable);
+        },
+        fail: function (res) {
+          console.log("sdfasdfadsf==11==" + that.isAvailable + "===" + JSON.stringify(res));
+          if (res.errno == 103) {
+            wx.showModal({
+              title: '提示',
+              content: '需要您的蓝牙权限才能使用此功能,是否前往设置授权?',
+              showCancel: true,
+              success: (modalRes) => {
+                if (modalRes.confirm) {
+                  wx.openSetting({
+                    success: (settingRes) => {
+                      console.log("sdfasdfadsf==222==" + that.isAvailable + "===" + JSON.stringify(settingRes));
+                      if (settingRes.authSetting['scope.bluetooth']) {
+                        that.isAvailable = true;
+                        resolve(that.isAvailable);
+                      } else {
+                        that.isAvailable = false;
+                        resolve(that.isAvailable);
+                      }
+                    }
+                  });
+                } else if (modalRes.cancel) {
+                  that.isAvailable = false;
+                  resolve(that.isAvailable);
+                }
+              }
+            });
+          } else {
+            that.isAvailable = false;
+            resolve(that.isAvailable);
+          }
+        }
+      })
+    });
   }
 
   search(connectWillDevice, boolean, callBackConnect) {
@@ -624,7 +635,7 @@ class bleManager {
     });
   }
 
-  connect() { }
+  connect() {}
 
   // 发现特征值 read / write
   discoverCharacteristics(deviceId, serviceId) {
@@ -724,4 +735,4 @@ class bleManager {
 // const ble = new bleManager();
 
 // 导出 bleManager 类
-module.exports = bleManager;
+module.exports = bleManager;

+ 10 - 0
utils/lexin/devices.js

@@ -1,5 +1,15 @@
 ///乐鑫
 const leXin = "BLUFI_";
+
+///君正标记
+const junZheng1 = "AIrSMArT_";
+const junZheng2 = "AS_";
+///君正过滤这个标记
+const junZheng3 = "AIrSMArT_CAST";
+
+// if ((name.startsWith(junZheng1) || name.startsWith(junZheng2)) &&
+// !name.startsWith(junZheng3)) {}
+
 const clientTypes = ["MW-2AX(WIFI)", "MW-2AX(WIFI-N)", "MW-2AX(A)",
   "MW-SR1(4G_WIFI)",
   "MW-SR1(4G_WIFI_MEIZU01)",