柒零 1 سال پیش
والد
کامیت
479988c528
2فایلهای تغییر یافته به همراه31 افزوده شده و 6 حذف شده
  1. 1 1
      project.private.config.json
  2. 30 5
      subpages/addMattresses/addMattresses.js

+ 1 - 1
project.private.config.json

@@ -104,5 +104,5 @@
       ]
     }
   },
-  "libVersion": "3.5.8"
+  "libVersion": "3.6.4"
 }

+ 30 - 5
subpages/addMattresses/addMattresses.js

@@ -162,7 +162,7 @@ Page({
         console.log(res);
         wx.showToast({
           icon: 'none',
-          title: "请打开系统蓝牙"
+          title: `${JSON.stringify(res)}`
         });
       }
     })
@@ -542,12 +542,28 @@ Page({
       self.getResultType(util.ab2hex(res.value));
     })
   },
+
   getCharCodeat: function (str) {
-    var list = [];
-    for (var i = 0; i < str.length; i++) {
-      list.push(str.charCodeAt(i));
+    let utf8Bytes = [];
+    for (let i = 0; i < str.length; i++) {
+      let char = str.charCodeAt(i);
+      if (char < 0x80) {
+        utf8Bytes.push(char);
+      } else if (char < 0x800) {
+        utf8Bytes.push(0xc0 | (char >> 6));
+        utf8Bytes.push(0x80 | (char & 0x3f));
+      } else if (char < 0x10000) {
+        utf8Bytes.push(0xe0 | (char >> 12));
+        utf8Bytes.push(0x80 | ((char >> 6) & 0x3f));
+        utf8Bytes.push(0x80 | (char & 0x3f));
+      }
     }
-    return list;
+    return utf8Bytes;
+    // var list = [];
+    // for (var i = 0; i < str.length; i++) {
+    //   list.push(str.charCodeAt(i));
+    // }
+    // return list;
   },
   // 设备数据开始写入
   writeDevice: function (deviceId, serviceId, characteristicId, data) {
@@ -689,6 +705,15 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    wx.authorize({
+      scope: 'scope.bluetooth',
+      success() {
+        // 用户同意授权后再次获取位置  
+      },
+      fail() {
+        // 用户拒绝授权  
+      }
+    });
     this.getWifiInfo();
     if (options.type && options.type == "edit") {
       wx.setNavigationBarTitle({