Jelajahi Sumber

feature: 蓝牙和wifi仅仅关闭上层页面,不替换当前页面

Damon 8 bulan lalu
induk
melakukan
7ab31bfdb4
4 mengubah file dengan 57 tambahan dan 23 penghapusan
  1. 14 8
      pages/connectBle/connectBle.js
  2. 11 6
      pages/index/index.js
  3. 8 6
      utils/route_constant.js
  4. 24 3
      utils/route_util.js

+ 14 - 8
pages/connectBle/connectBle.js

@@ -3,8 +3,9 @@ const {
   BtHelper
 } = require('../../devices/bt_helper');
 const toastUtil = require('../../utils/toast_util');
-import routeUtil from '../../utils/route_util'
+
 import route_constant from '../../utils/route_constant.js'
+import route_util from '../../utils/route_util.js';
 Page({
 
   /**
@@ -118,11 +119,15 @@ Page({
 
         var connectDevice = _this.data.connectDevice;
         getCurrentPages()[0].addConnectBlueDevice(connectDevice);
-        setTimeout(() => {
-          wx.redirectTo({
-            url: '/pages/index/index'
-          });
-        }, 200);
+        route_util.goBackRoute(route_constant.indexRoot);
+        // setTimeout(() => {
+        //   // wx.redirectTo({
+        //   //   url: '/pages/index/index'
+        //   // });
+
+        //   route_util.goBackRoute("");
+        //   console.log("gadfasdfasdfaf==22222222222=");
+        // }, 200);
       }
 
     })
@@ -137,7 +142,7 @@ Page({
         _this.didFindDevice(element)
 
       });
-    } else { }
+    } else {}
     return connectedDevices;
   },
   async startSearch() {
@@ -161,7 +166,8 @@ Page({
         _this.didFindDevice(element)
       });
     })
-  }, didFindDevice(element) {
+  },
+  didFindDevice(element) {
     let deviceId = element.deviceId
     let _this = this
     // todo 暂定这样

+ 11 - 6
pages/index/index.js

@@ -67,10 +67,6 @@ Page({
       // 获取设备本地数据
       if (app.globalData.newDeviceId) {
         that.addNewDeviceId();
-      }
-      // 更新
-      else if (that.data.deviceListIndex !== null) {
-        that.actionDevice(that.data.deviceListIndex);
       } else if (app.globalData.client == null) {
         app.connect();
       } else if (that.data.deviceListIndex == null && that.data.deviceList.length > 0) {
@@ -83,9 +79,9 @@ Page({
     }
   },
 
-  ///开始时home的
   onDeviceLoad() {
     var that = this;
+    console.log("gadfqrqwerqwerqrrqwer===222=");
     var devicelist = wx.getStorageSync("devicelist") || "";
     if (!strings.isEmpty(devicelist)) {
       var list = JSON.parse(devicelist);
@@ -133,13 +129,13 @@ Page({
 
   // 回调
   mqttCallback(type, option) {
+    console.log("gadsfadsfadsfa==888===" + type);
     var that = this;
     let payloads = null;
     if (option) {
       payloads = JSON.parse(option.payload);
     };
 
-    console.log("gadsfadsfadsfa==8888===" + type);
     switch (type) {
       ///连接成功订阅
       case "connect":
@@ -690,6 +686,8 @@ Page({
       deviceList = deviceList.filter((v) => v.deviceId !== newDevice.deviceId);
     };
 
+    console.log("gadsfqwerqr==00==" + deviceList.length);
+    console.log("gadsfqwerqr==11==" + JSON.stringify(deviceList));
     deviceList.unshift({
       /// 蓝牙ble连接
       connectType: 1,
@@ -701,8 +699,14 @@ Page({
       mac: newDevice.mac,
     });
 
+    console.log("gadsfqwerqr==222==" + deviceList.length);
+    console.log("gadsfqwerqr==333==" + JSON.stringify(deviceList));
+
     ///在线排序前面,wifi设备排序前面
     that.updateDeviceList(deviceList, false);
+
+    console.log("gadsfqwerqr==444==" + that.data.deviceList.length);
+    console.log("gadsfqwerqr==555==" + JSON.stringify(that.data.deviceList));
     var indexPage = that.data.indexPage;
     if (indexPage != 0) {
       that.setData({
@@ -746,6 +750,7 @@ Page({
 
     ///区分在线和离线
     for (var i = 0; i < deviceList.length; i++) {
+      console.log("gadfqrqwerqwerqrrqwer===111=" + isInit);
       if (isInit) {
         deviceList[i].state = "offline";
       } else {

+ 8 - 6
utils/route_constant.js

@@ -1,18 +1,20 @@
+const indexRoot = "pages/index/index";
 
 /// 抽奖记录
 const deviceList = "../deviceList/deviceList";
 // 连接模式
 const connectMode = "../deviceConMode/index";
 const connectBle = "../connectBle/connectBle";
+
 // // 主页
 // const home = "../home/home";
 // // 主页
 // const order = "../order/order";
 module.exports = {
-
-    deviceList: deviceList,
-    connectMode: connectMode,
-    connectBle: connectBle,
-    // deviceList: detail,
-    // home: home
+  indexRoot: indexRoot,
+  deviceList: deviceList,
+  connectMode: connectMode,
+  connectBle: connectBle,
+  // deviceList: detail,
+  // home: home
 }

+ 24 - 3
utils/route_util.js

@@ -8,9 +8,9 @@ async function goBack(pages) {
 
   if (currentPage.route.lastIndexOf("detail/detail")) {
     setTimeout(() => {
-          wx.redirectTo({
-            url: '/pages/index/index'
-          });
+      wx.redirectTo({
+        url: '/pages/index/index'
+      });
     }, 300);
   } else {
     // 执行返回操作
@@ -95,7 +95,28 @@ function jump2Other(item) {
   });
 };
 
+///返回到某个界面,不替换当前界面
+async function goBackRoute(route) {
+  const pages = getCurrentPages(); // 获取当前页面栈
+  const pageCount = pages.length; // 页面栈中的页面数量
+  var pageNuble = 0;
+  for (var i = pageCount - 1; i > -1; i--) {
+    if (pages[i].route != route) {
+      pageNuble++;
+    } else {
+      break;
+    }
+  }
+  if (pageNuble > 0) {
+    await wx.navigateBack({
+      delta: pageNuble,
+    });
+  }
+
+};
+
 module.exports = {
+  goBackRoute: goBackRoute,
   jump: jump,
   jumpParam: jumpParam,
   goBack: goBack,