Просмотр исходного кода

feature: 解决偶现界面消失的问题

Damon 7 месяцев назад
Родитель
Сommit
eafc4efe65
2 измененных файлов с 24 добавлено и 24 удалено
  1. 22 24
      pages/index/index.js
  2. 2 0
      pages/index/index.wxml

+ 22 - 24
pages/index/index.js

@@ -90,7 +90,7 @@ Page({
   onDeviceLoad() {
     var that = this;
     var deviceList = store.getStore("deviceList");
-    if (!strings.isEmpty(deviceList)) { 
+    if (!strings.isEmpty(deviceList)) {
       that.updateDeviceList(deviceList, true, false);
     }
 
@@ -136,9 +136,11 @@ Page({
         lexin_connect.searchOnlineDevice(payloads, function (list) {
           that.updateDeviceList(list, false, false);
         }, function () {
+          var indexPage = that.data.indexPage;
           that.setData({
             actionIndex: null,
             deviceListSelect: null,
+            indexPage: indexPage == 1 ? 0 : indexPage,
           });
         });
         break;
@@ -330,10 +332,12 @@ Page({
       if (!strings.isEmpty(deviceMacId)) {
         var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
         app.unsubscribe(pubResponse);
+        var indexPage = that.data.indexPage;
         that.setData({
           deviceMacId: null,
           actionIndex: null,
           deviceListSelect: null,
+          indexPage: indexPage == 1 ? 0 : indexPage,
         });
       };
     }
@@ -476,17 +480,12 @@ Page({
     });
 
     store.setStore("deviceList", deviceList);
-    if (isCurrentIndex) {
-      that.setData({
-        deviceListSelect: null,
-        deviceList: deviceList,
-      });
-    } else {
-      that.setData({
-        deviceList: deviceList,
-      });
-    }
-
+    var indexPage = that.data.indexPage;
+    that.setData({
+      deviceList: deviceList,
+      indexPage: indexPage == 1 ? 0 : indexPage,
+      deviceListSelect: isCurrentIndex ? null : deviceListSelect,
+    });
   },
 
   /// 断开连接wifi
@@ -517,18 +516,14 @@ Page({
     });
 
     store.setStore("deviceList", deviceList);
-    if (isCurrentIndex) {
-      that.setData({
-        deviceList: deviceList,
-        deviceMacId: null,
-        actionIndex: null,
-        deviceListSelect: null,
-      });
-    } else {
-      that.setData({
-        deviceList: deviceList,
-      });
-    }
+    var indexPage = that.data.indexPage;
+    that.setData({
+      deviceList: deviceList,
+      deviceMacId: isCurrentIndex ? null : deviceMacId,
+      actionIndex: isCurrentIndex ? null : actionIndex,
+      deviceListSelect: isCurrentIndex ? null : deviceListSelect,
+      indexPage: indexPage == 1 ? 0 : indexPage,
+    });
   },
 
   /// 新添加蓝牙设备
@@ -558,9 +553,12 @@ Page({
     var deviceId = device.deviceId;
     var addDeviceList = lexin_add.addWifiDevice(device);
     that.updateDeviceList(addDeviceList, false, false);
+
+    var indexPage = that.data.indexPage;
     that.setData({
       deviceListSelect: null,
       connectDeviceIding: deviceId,
+      indexPage: indexPage == 1 ? 0 : indexPage,
     });
     lexin_subscribe.subscribeSingleDevice(device);
   },

+ 2 - 0
pages/index/index.wxml

@@ -182,10 +182,12 @@
           首页
         </view>
       </view>
+      
       <view wx:if="{{deviceListSelect!=null&&deviceList.length>deviceListSelect&&deviceList[deviceListSelect].connectType===3}}" class="bottom_view" data-index="1" bind:tap="onTapIndex">
         <image class="bottom_image" mode="widthFix" src="{{indexPage==1?'./../../img/channel_action.png':'./../../img/channel_unaction.png'}}"></image>
         <view style="font-size: 20rpx;color: {{indexPage==1?'#A4D099':'black'}};">频道</view>
       </view>
+
       <view class="bottom_view" data-index="2" bind:tap="onTapIndex">
         <image class="bottom_image" mode="widthFix" src="{{indexPage==2?'./../../img/me_action.png':'./../../img/me_unaction.png'}}"></image>
         <view style="font-size: 20rpx;color: {{indexPage==2?'#A4D099':'black'}};">我的</view>