Explorar o código

feature: 解决请求蓝牙权限弹窗两次的问题

Damon hai 7 meses
pai
achega
26d92d513e
Modificáronse 2 ficheiros con 13 adicións e 17 borrados
  1. 13 13
      app.js
  2. 0 4
      utils/util.js

+ 13 - 13
app.js

@@ -32,11 +32,12 @@ App({
       clientId: "wx_" + parseInt(Math.random() * 100 + 800, 10),
       reconnectPeriod: 1000, //1000毫秒,两次重新连接之间的间隔
       connectTimeout: 30 * 1000, //1000毫秒,两次重新连接之间的间隔
-      resubscribe: true, //如果连接断开并重新连接,则会再次自动订阅已订阅的主题(默认true
+      resubscribe: true, //如果连接断开并重新连接,则会再次自动订阅已订阅的主题(默认true)
       keepalive: 3, //每3秒发送一次心跳
     },
   },
 
+  ///全局初始化
   onLaunch() {
     var that = this;
     var userInfo = wx.getStorageSync("userInfo") || "";
@@ -44,32 +45,29 @@ App({
       that.globalData.userInfo = userInfo;
     }
 
-    wx.onAppHide(() => {
-      if (that.globalData.client && that.globalData.client.connected) {
-        that.globalData.client.end(true);
-        that.globalData.client.end(true);
-        console.log("断开");
-      };
-    });
-
+    ///显示界面
     wx.onAppShow(() => {
-      console.log("加载")
       if (that.globalData.userInfo !== null) {
         if (that.globalData.client) {
           that.globalData.client.end(true);
-          that.globalData.client.end(true);
         }
         console.log("重连");
         that.connect();
       };
     });
 
-    that.getBluetoothStatus();
+    ///界面后台化
+    wx.onAppHide(() => {
+      if (that.globalData.client && that.globalData.client.connected) {
+        that.globalData.client.end(true);
+      };
+    });
+
+    // that.getBluetoothStatus();
     //自定义导航栏 获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度)
     wx.getSystemInfo({
       success: (res) => {
         let custom = wx.getMenuButtonBoundingClientRect();
-
         that.globalData.navBarHeight = res.statusBarHeight + custom.height + (custom.top - res.statusBarHeight) * 2;
         that.globalData.MenuButtonheight = custom.height;
         that.globalData.MenuButtonTop = custom.top;
@@ -84,6 +82,8 @@ App({
     update.update();
   },
 
+  onHide: function () {},
+
   /**
    * 连接设备
    * mqttCallback:mqtt回调统一方法

+ 0 - 4
utils/util.js

@@ -77,8 +77,6 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
     });
   }
   console.log("请求参数:", fullurl, data)
-  console.log("gadsfwqerqewqr====aaa==" + fullurl);
-  console.log("gadsfwqerqewqr====bbb==" + JSON.stringify(data));
   return new Promise((resolve, reject) => {
     wx.request({
       url: fullurl,
@@ -91,7 +89,6 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
       }, header),
       success(res) {
         console.log("接口:", fullurl, res)
-        console.log("gadsfwqerqewqr====00==" + JSON.stringify(res));
         if (res.statusCode !== 200) {
           wx.hideLoading();
           wx.showToast({
@@ -129,7 +126,6 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
       },
       fail: (err) => {
         console.log("请求失败" + JSON.stringify(err));
-        console.log("gadsfwqerqewqr====11==" + JSON.stringify(err));
         _show_error("1");
         wx.hideLoading();
         reject({