Quellcode durchsuchen

feature:还原mqtt问题

zeng.chen vor 8 Monaten
Ursprung
Commit
848875cc61
1 geänderte Dateien mit 42 neuen und 8 gelöschten Zeilen
  1. 42 8
      app.js

+ 42 - 8
app.js

@@ -2,7 +2,9 @@
 import btHelper from './devices/bt_helper';
 import mqtt from './utils/mqtt';
 //连接的服务器域名
-const host = 'wxs://mqtt.test.radio1964.com';
+// const host = 'wxs://mqtt.test.radio1964.com';
+const host = 'wxs://mqtt.ssl.keepradioon.net:8884'
+
 // const host = 'wxs://mqtt.test.radio1964.com:8884';
 // const host = 'wxs://mqtt.ssl.keepradioon.net:8884'
 App({
@@ -216,14 +218,46 @@ App({
   // 获取蓝牙权限
   getBluetoothStatus() {
     const _this = this;
-    btHelper.initBluetooth((adpter, hasPermission) => {
-      console.log("蓝牙权限", adpter, hasPermission);
-      _this.globalData.scopeBluetooth = hasPermission;
-      if (getCurrentPages()[getCurrentPages().length - 1].getBluetoothStatusCallck) {
-        getCurrentPages()[getCurrentPages().length - 1].getBluetoothStatusCallck(_this.globalData.scopeBluetooth);
+    wx.getSetting({
+      success(res) {
+        if (res.authSetting["scope.bluetooth"]) {
+          _this.globalData.scopeBluetooth = true;
+        } else if (res.authSetting["scope.bluetooth"] === undefined) {
+          _this.globalData.scopeBluetooth = false;
+          wx.authorize({
+            scope: "scope.bluetooth",
+            complete() {
+              _this.getBluetoothStatus();
+            }
+          });
+        } else {
+          _this.globalData.scopeBluetooth = false;
+          wx.showModal({
+            title: '请打开系统蓝牙进行配网',
+            content: '如已打开蓝牙仍然弹框,请尝试重启小程序',
+            success(res) {
+              if (res.confirm) {
+                console.log('用户点击确定')
+                wx.openSetting({
+                  complete() {
+                    // _this.getBluetoothStatus();
+                  }
+                })
+              } else if (res.cancel) {
+                console.log('用户点击取消')
+              }
+            }
+          })
+        };
+        if (getCurrentPages()[getCurrentPages().length - 1].getBluetoothStatusCallck) {
+          getCurrentPages()[getCurrentPages().length - 1].getBluetoothStatusCallck(_this.globalData.scopeBluetooth);
+        }
+        // res.authSetting = {
+        //   "scope.userInfo": true,
+        //   "scope.userLocation": true
+        // }
       }
-    });
-
+    })
   },
 })