浏览代码

feature: 处理跳转,摧毁当前界面的问题

Damon 8 月之前
父节点
当前提交
b4f01d9a6e
共有 7 个文件被更改,包括 676 次插入714 次删除
  1. 523 523
      devices/ble_manager.js
  2. 12 5
      pages/deviceConMode/index.js
  3. 68 68
      pages/deviceConMode/index.wxss
  4. 12 17
      pages/index/index.js
  5. 10 9
      pages/login/login.js
  6. 10 6
      utils/route_constant.js
  7. 41 86
      utils/route_util.js

文件差异内容过多而无法显示
+ 523 - 523
devices/ble_manager.js


+ 12 - 5
pages/deviceConMode/index.js

@@ -18,8 +18,7 @@ Page({
     isNotruter: false,
     model: 0,
     connectDevice: {},
-    typeList: [
-      {
+    typeList: [{
         "icon": "../../images/device/mode_2.png",
         "text": "WiFi模式",
         "type": 2,
@@ -36,6 +35,7 @@ Page({
       },
     ],
   },
+
   getModeName(curItem) {
     // 设备类型:1-蓝牙,2-Wifi,3-传统蓝牙,4-4G
     var str = "";
@@ -48,10 +48,12 @@ Page({
     }
     return str;
   },
+
   nextTap(e) {
     let device = this.data.typeList[0];
     let type = device.type ?? 0;
     console.log("选择模式", type)
+    ///蓝牙模式
     if (type == 1) {
       // let device = e.currentTarget.dataset.data
       let json = JSON.stringify(this.data.connectDevice)
@@ -59,16 +61,21 @@ Page({
       // wx.navigateTo({
       //   url: './../deviceDetail/detail',
       // });
-    } else if (type == 2) {
+    }
+    ///Wifi模式
+    else if (type == 2) {
       wx.navigateTo({
         url: './../deviceConnect0/deviceConnect0',
       });
     } else if (type == 3) {
       // btHelper.stopSearch()
-    } else {
+    }
+    ///4G模式
+    else {
 
     }
   },
+
   async selectDeviceModelTap(e) {
     let device = e.currentTarget.dataset.device;
     // console.log(e)
@@ -105,7 +112,7 @@ Page({
 
     if (getApp().globalData.isIOS) {
 
-    } else { }
+    } else {}
   },
 
 })

+ 68 - 68
pages/deviceConMode/index.wxss

@@ -1,121 +1,121 @@
 /* pages/deviceConMode/index.wxss */
 
 .main {
-	position: relative;
-	width: 100vw;
-	height: 100vh;
+  position: relative;
+  width: 100vw;
+  height: 100vh;
 }
 
 .model_bg {
-	top: 80;
-	left: 0;
-	position: absolute;
-	width: 100%;
-	height: 100%;
-	z-index: -1;
-	background-size: cover;
-	background-position: center;
+  top: 80;
+  left: 0;
+  position: absolute;
+  width: 100%;
+  height: 100%;
+  z-index: -1;
+  background-size: cover;
+  background-position: center;
 }
 
 .select_tips {
-	position: relative;
-	z-index: 1;
-	padding: 20px;
+  position: relative;
+  z-index: 1;
+  padding: 20px;
 }
 
 .devicePicItem {
-	display: flex;
-	align-items: center;
-	padding: 10px;
+  display: flex;
+  align-items: center;
+  padding: 10px;
 
 }
 
 .setDeviceModel {
-	padding: 10px;
-	text-align: center;
-	left: 0;
-	font-size: 32rpx;
+  padding: 10px;
+  text-align: center;
+  left: 0;
+  font-size: 32rpx;
 }
 
 .setDeviceModelTips {
-	color: #FFFFFFB3;
-	text-align: center;
-	font-size: 24rpx;
+  color: #FFFFFFB3;
+  text-align: center;
+  font-size: 24rpx;
 }
 
 .deviceList {
-	margin-top: 60px;
+  margin-top: 60px;
 }
 
 .devicePicItem {
-	position: relative;
+  position: relative;
 
-	display: flex;
-	flex-direction: row;
-	align-items: center;
-	justify-content: center;
+  display: flex;
+  flex-direction: row;
+  align-items: center;
+  justify-content: center;
 
-	border-radius: 5px;
-	height: 100rpx;
-	margin-top: 32rpx;
-	background-color: #ffffff0d;
+  border-radius: 5px;
+  height: 100rpx;
+  margin-top: 32rpx;
+  background-color: #ffffff0d;
 }
 
 .select_icon {
-	width: 32rpx;
-	height: 32rpx;
-	position: absolute;
-	z-index: 1;
-	top: 16rpx;
-	right: 16rpx;
+  width: 32rpx;
+  height: 32rpx;
+  position: absolute;
+  z-index: 1;
+  top: 16rpx;
+  right: 16rpx;
 }
 
 .device_text {
-	display: flex;
-	flex-direction: row;
-	align-items: center;
-	justify-content: center;
+  display: flex;
+  flex-direction: row;
+  align-items: center;
+  justify-content: center;
 }
 
 .model_icon {
-	width: 48rpx;
-	height: 48rpx;
-	margin-right: 10rpx;
+  width: 48rpx;
+  height: 48rpx;
+  margin-right: 10rpx;
 
 }
 
 .model_text {
-	font-size: 32rpx;
-	color: white;
+  font-size: 32rpx;
+  color: white;
 }
 
 .devicePicItem_0 {
-	margin-left: 32rpx;
-	margin-right: 32rpx;
+  margin-left: 32rpx;
+  margin-right: 32rpx;
 }
 
 .devicePicItem_1 {
-	margin-left: 64rpx;
-	margin-right: 64rpx;
+  margin-left: 64rpx;
+  margin-right: 64rpx;
 }
 
 .devicePicItem_2 {
-	margin-left: 96rpx;
-	margin-right: 96rpx;
+  margin-left: 96rpx;
+  margin-right: 96rpx;
 }
 
 .connect_button {
-	position: fixed;
-	display: flex;
-	justify-content: center;
-	align-items: center;
-	bottom: 100rpx;
-	left: 60rpx;
-	right: 60rpx;
-	font-size: 32rpx;
-	font-weight: Medium;
-	color: white;
-	text-align: center;
-	border-radius: 44rpx;
-	height: 88rpx;
+  position: fixed;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  bottom: 100rpx;
+  left: 60rpx;
+  right: 60rpx;
+  font-size: 32rpx;
+  font-weight: Medium;
+  color: white;
+  text-align: center;
+  border-radius: 44rpx;
+  height: 88rpx;
 }

+ 12 - 17
pages/index/index.js

@@ -6,6 +6,7 @@ const {
 
 import timeUtil from '../../utils/time_util.js';
 import strings from '../../utils/strings.js';
+import route_constant from '../../utils/route_constant.js';
 import route_util from '../../utils/route_util.js';
 
 Page({
@@ -84,7 +85,7 @@ Page({
     var devicelist = wx.getStorageSync("devicelist") || "";
     if (!strings.isEmpty(devicelist)) {
       var list = JSON.parse(devicelist);
-      that.updateDeviceList(list, false);
+      that.updateDeviceList(list, true);
     }
   },
 
@@ -490,9 +491,7 @@ Page({
     }
     // 登录
     else {
-      wx.navigateTo({
-        url: './../login/login',
-      });
+      route_util.jump(route_constant.login);
     }
   },
 
@@ -528,21 +527,15 @@ Page({
     });
   },
 
+  ///添加设备
   addDevice() {
     var that = this;
     if (!that.data.isLogin) {
-      wx.navigateTo({
-        url: './../login/login'
-      });
+      route_util.jump(route_constant.login);
       return;
     }
-    that.goDeviceConnect();
-  },
-
-  goDeviceConnect() {
-    wx.navigateTo({
-      url: './../deviceList/deviceList',
-    });
+    ///跳转设备列表
+    route_util.jump(route_constant.deviceList);
   },
 
   ///点击item
@@ -550,9 +543,7 @@ Page({
   onTapItem(e) {
     var that = this;
     if (!that.data.isLogin) {
-      wx.navigateTo({
-        url: './../login/login'
-      });
+      route_util.jump(route_constant.login);
       return;
     }
     var item = e.currentTarget.dataset.item;
@@ -631,6 +622,7 @@ Page({
     var item = e.currentTarget.dataset.item;
   },
 
+  ///删除当前设备
   deleteDevice(e) {
     var that = this;
     wx.showModal({
@@ -720,6 +712,8 @@ Page({
   /// 连接方式:bt-0,ble-1,upnp-2,mqtt-3
   /// clientType
   // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
+
+  ///新添加蓝牙设备
   addConnectBlueDevice(newDevice) {
     var that = this;
     // 同一个设备
@@ -756,6 +750,7 @@ Page({
     }
   },
 
+  ///新添加wifi设备
   addConnectWifiDevice(deviceList) {
     var that = this;
     ///在线排序前面,wifi设备排序前面

+ 10 - 9
pages/login/login.js

@@ -5,6 +5,9 @@ const {
   register
 } = require('./../../utils/api.js')
 
+import route_constant from '../../utils/route_constant.js';
+import route_util from '../../utils/route_util.js';
+
 Page({
 
   data: {
@@ -78,15 +81,8 @@ Page({
 
                     getCurrentPages()[0].onUserInfoLoad();
                     setTimeout(() => {
-                      wx.redirectTo({
-                        url: './../deviceList/deviceList'
-                      });
+                      route_util.redirectTo(route_constant.deviceList);
                     }, 2000);
-
-                    // 需要用授权登录
-                    // if ((res.isNewUser && res.isNewUser === true) || !phone) {
-                    //   return;
-                    // };
                   });
                 },
                 fail(fail4) {
@@ -109,4 +105,9 @@ Page({
       icon: "none"
     })
   }
-})
+})
+
+// 需要用授权登录
+// if ((res.isNewUser && res.isNewUser === true) || !phone) {
+//   return;
+// };

+ 10 - 6
utils/route_constant.js

@@ -1,20 +1,24 @@
+///路由
 const indexRoot = "pages/index/index";
+const loginRoot = "pages/login/login";
 
+const index = "../index/index";
+///登录界面
+const login = "../login/login";
 /// 抽奖记录
 const deviceList = "../deviceList/deviceList";
 // 连接模式
 const connectMode = "../deviceConMode/index";
 const connectBle = "../connectBle/connectBle";
 
-// // 主页
-// const home = "../home/home";
-// // 主页
-// const order = "../order/order";
 module.exports = {
+  ///路由
   indexRoot: indexRoot,
+
+  ///跳转路径
+  index: index,
+  login: login,
   deviceList: deviceList,
   connectMode: connectMode,
   connectBle: connectBle,
-  // deviceList: detail,
-  // home: home
 }

+ 41 - 86
utils/route_util.js

@@ -1,34 +1,21 @@
-// import loginUtil from './login_util.js';
-
-//返回页面个数
-async function goBack(pages) {
-
-  const cPages = getCurrentPages();
-  const currentPage = cPages[cPages.length - 1];
-
-  if (currentPage.route.lastIndexOf("detail/detail")) {
-    setTimeout(() => {
-      wx.redirectTo({
-        url: '/pages/index/index'
-      });
-    }, 300);
-  } else {
-    // 执行返回操作
-    if (pages == null) pages = 1;
-    await wx.navigateBack({
-      delta: pages,
-    });
-  }
-
-};
+module.exports = {
+  goBackHomePage: goBackHomePage,
+  goBackRoute: goBackRoute,
+  removeRoute: removeRoute,
+  jump: jump,
+  jumpParam: jumpParam,
+  goBack: goBack,
+  redirectTo: redirectTo,
+}
 
-///跳转界面
+///跳转,不摧毁界面
 async function jump(url) {
   await wx.navigateTo({
     url: url,
-  })
+  });
 };
 
+///跳转带参,不摧毁界面
 async function jumpParam(url, param) {
   if (param) {
     await wx.navigateTo({
@@ -39,60 +26,41 @@ async function jumpParam(url, param) {
   }
 };
 
-//界面跳转
-async function jumpLogin(url, isNeedLogin) {
-  if (isNeedLogin) {
-    // if (loginUtil.getUserBean() == null) {
-    //     return;
-    // }
-  }
-  await wx.navigateTo({
+//跳转,并且摧毁当前界面
+async function redirectTo(url) {
+  await wx.redirectTo({
     url: url,
   });
 };
 
-//跳转到Tab页面
-async function switchTo(url) {
-  console.log(url)
-  await wx.switchTab({
-    //跳转目标
-    url: url,
-    //跳转成功后
-    success: function () {
-      //让多个tabl显示出来
-      // wx.showTabBar({
-      //     animation: false,
-      // });
-    },
-    fail: function (res) {
-      console.log(res)
-    }
-  })
+//返回页面个数
+async function goBack(pages) {
+  if (pages == null) pages == 1;
+  await wx.navigateBack({
+    delta: pages,
+  });
 };
 
-//跳转摧毁当前界面
-async function redirectTo(url) {
-  await wx.redirectTo({
-    url: url,
-  });
+///返回到首页
+async function goBackHomePage() {
+  const route_constant = require('./route_constant.js');
+  await goBackRoute(route_constant.indexRoot);
 };
 
-/**
- * 跳转到其他小程序
- * @param {*} item
- */
-function jump2Other(item) {
-  wx.navigateToMiniProgram({
-    appId: item.app_id,
-    path: item.page_path,
-    // extraData: {
-    //   foo: 'bar'
-    // },
-    // envVersion: 'develop',
-    envVersion: 'release',
-    success() {},
-    fail() {}
-  });
+//移除掉多层级中的某一个
+async function removeRoute(route) {
+  const pages = getCurrentPages();
+  const pageCount = pages.length;
+  console.log("gadfasdfqwerqewrqr===00=" + route);
+  console.log("gadfasdfqwerqewrqr===aaa=" + pageCount);
+  for (var i = pageCount - 1; i > -1; i--) {
+    console.log("gadfasdfqwerqewrqr==11==" + pages[i].route);
+    if (pages[i].route == route) {
+      console.log("gadfasdfqwerqewrqr==22==" + route);
+      pages.remove(route);
+      break;
+    }
+  }
 };
 
 ///返回到某个界面,不替换当前界面
@@ -109,19 +77,6 @@ async function goBackRoute(route) {
     }
   }
   if (pageNuble > 0) {
-    await wx.navigateBack({
-      delta: pageNuble,
-    });
+    await goBack(pageNuble);
   }
-};
-
-module.exports = {
-  goBackRoute: goBackRoute,
-  jump: jump,
-  jumpParam: jumpParam,
-  goBack: goBack,
-  switchTo: switchTo,
-  jump2Other: jump2Other,
-  redirectTo: redirectTo,
-  jumpLogin: jumpLogin,
-}
+};