Selaa lähdekoodia

feature: wifi连接数据处理

Damon 7 kuukautta sitten
vanhempi
commit
ad3cf1c289
7 muutettua tiedostoa jossa 223 lisäystä ja 219 poistoa
  1. 8 1
      app.js
  2. 11 12
      devices/ble_manager.js
  3. 176 149
      pages/index/index.js
  4. 2 4
      utils/blufi/xBlufi-wx-impl.js
  5. 6 23
      utils/store.js
  6. 18 19
      utils/toast_util.js
  7. 2 11
      utils/update.js

+ 8 - 1
app.js

@@ -82,7 +82,7 @@ App({
     update.update();
   },
 
-  onHide: function () { },
+  onHide: function () {},
 
   ///连接设备
   connect() {
@@ -122,6 +122,13 @@ App({
             payload
           });
         }
+        ///多个界面回调首页
+        if (getCurrentPages().length != 1) {
+          getCurrentPages()[0].mqttCallback("message", {
+            topic,
+            payload
+          });
+        }
       }
     });
 

+ 11 - 12
devices/ble_manager.js

@@ -3,7 +3,6 @@
 class bleManager {
   constructor() {
     var that = this;
-    that.isAvailable = false;
     that.hasPermission = false;
     that.scanDevices = [];
     that.publicDevice = null;
@@ -43,18 +42,9 @@ 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;
-      if (!that.isAvailable) {
+      var isAvailable = res.available;
+      if (!isAvailable) {
         getCurrentPages()[0].updateDeviceList([], false, true);
       }
     })
@@ -697,6 +687,15 @@ class bleManager {
 // 导出 bleManager 类
 module.exports = bleManager;
 
+// wx.openBluetoothAdapter({
+//   success: (res) => {
+//     that.isAvailable = true;
+//   },
+//   fail: (err) => {
+//     that.isAvailable = false;
+//   }
+// });
+
 // wx.getSetting({
 //   success(res) {
 //     if (res.authSetting["scope.userFuzzyLocation"]) {

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 176 - 149
pages/index/index.js


+ 2 - 4
utils/blufi/xBlufi-wx-impl.js

@@ -333,17 +333,15 @@ function init() {
   })
 
   mDeviceEvent.listenStartDiscoverBle(true, function (options) {
-
     if (options.isStart) {
       //第一步检查蓝牙适配器是否可用
       wx.onBluetoothAdapterStateChange(function (res) {
-        if (!res.available) {
-
-        }
+        if (!res.available) {}
       });
       if (!itue) {
         return;
       };
+
       itue = false;
       //第二步关闭适配器,重新来搜索
       wx.closeBluetoothAdapter({

+ 6 - 23
utils/store.js

@@ -1,45 +1,28 @@
 module.exports = {
   setStore: setStore,
   getStore: getStore,
-  clearAll: clearAll,
   remove: remove,
 }
 
 //同步储存缓存数据
 function setStore(key, value) {
   try {
-    // console.log("gasdfasfqwerqwerqr===0000==" + JSON.stringify(value));
     wx.setStorageSync(key, value);
-  } catch (e) {
-    // console.log("gasdfasfqwerqwerqr===111==" + JSON.stringify(e));
-  }
+  } catch (e) {}
 };
 
 //同步取出缓存数据
 function getStore(key) {
   try {
-    // 使用同步方法获取数据
-    const list = wx.getStorageSync(key);
-    // console.log("gasdfasfqwerqwerqr===222==" + JSON.stringify(list));
-    if (list) {
+    const strings = require('../utils/strings');
+    var list = wx.getStorageSync(key);
+    if (!strings.isEmpty(strings)) {
       return list;
-    } else {
-      return [];
     }
-  } catch (e) {
-    return [];
-  }
+  } catch (e) {}
+  return [];
 };
 
-///不清除的有
-// {token,chatRecord,freeTimes}
-
-//清空数据
-function clearAll() {
-  const constant = require('./constant.js');
-  removeByKey(constant.param.userInfo);
-}
-
 //移除指定key
 function remove(key) {
   try {

+ 18 - 19
utils/toast_util.js

@@ -1,22 +1,21 @@
-function show(title,icon="none", duration) {
-    wx.hideLoading();
-    setTimeout(() => {
-        if (duration == null) {
-            wx.showToast({
-                icon: icon,
-                title: title,
-            });
-        } else {
-            wx.showToast({
-                icon: icon,
-                title: title,
-                duration: 1000,
-            });
-        }
-    }, 300)
-
+module.exports = {
+  show,
 }
 
-module.exports = {
-    show,
+function show(title, icon = "none", duration) {
+  wx.hideLoading();
+  setTimeout(() => {
+    if (duration == null) {
+      wx.showToast({
+        icon: icon,
+        title: title,
+      });
+    } else {
+      wx.showToast({
+        icon: icon,
+        title: title,
+        duration: 1000,
+      });
+    }
+  }, 300)
 }

+ 2 - 11
utils/update.js

@@ -3,21 +3,15 @@ module.exports = {
 }
 
 var isShowed = false;
-
 //检测版本是否更新
 function update() {
   if (isShowed) {
     return;
   }
-
   //检测版本更新
   const manager = wx.getUpdateManager();
-
   //检测版本是否更新
-  manager.onCheckForUpdate(function (e) {
-
-  });
-
+  manager.onCheckForUpdate(function (e) {});
   //版本更新
   manager.onUpdateReady(function (e) {
     isShowed = true;
@@ -31,9 +25,6 @@ function update() {
       }
     });
   });
-
   //版本更新失败
-  manager.onUpdateFailed(function (e) {
-
-  });
+  manager.onUpdateFailed(function (e) {});
 };