Browse Source

feature: 处理token过期界面显示

Damon 8 tháng trước cách đây
mục cha
commit
6360241e31
4 tập tin đã thay đổi với 54 bổ sung44 xóa
  1. 4 3
      pages/channelDetails/channelDetails.js
  2. 46 37
      pages/index/index.js
  3. 2 2
      pages/index/index.wxml
  4. 2 2
      utils/util.js

+ 4 - 3
pages/channelDetails/channelDetails.js

@@ -21,12 +21,13 @@ Page({
     var that = this;
     wx.getStorage({
       key: "channelDeta",
-      success(res) {
+      success(r) {
         that.setData({
-          thisChannel: res.data
+          thisChannel: r.data
         });
+
         pageByDevice({
-          channelId: res.data.channelId,
+          channelId: r.data.channelId,
           pageNum: 1,
           pageSize: 300
         }).then((res) => {

+ 46 - 37
pages/index/index.js

@@ -246,6 +246,7 @@ Page({
     var that = this;
     console.log("gadsfadsfadsfa==777===" + JSON.stringify(payloads));
 
+    ///是否更新过在线离线状态
     var isUpdate = false;
     var deviceList = that.data.deviceList;
     if (!strings.isEmpty(deviceList)) {
@@ -276,23 +277,24 @@ Page({
     }
 
     ///当前没有连接设备,则去连接第一个wifi设备
-    if (that.data.deviceListIndex === null) {
+    var deviceListIndex = that.data.deviceListIndex;
+    if (deviceListIndex === null) {
       var list = that.data.deviceList;
       for (var i = 0; i < list.length; i++) {
-        if (list[i].state === "online" && list[i].ProdModel == "MW-2AX(WIFI-N)") {
+        if (list[i].state === "online" && list[i].connectType == 3) {
           that.actionDevice(i);
           break;
         }
       }
+    } else {
+      // 当前播放设备离线
+      if (that.data.deviceList.length > deviceListIndex && that.data.deviceList[deviceListIndex].state !== "online") {
+        that.setData({
+          actionIndex: null,
+          deviceListIndex: null,
+        });
+      };
     }
-
-    // 当前播放设备离线
-    if (that.data.deviceListIndex !== null && that.data.deviceList[that.data.deviceListIndex].state !== "online") {
-      that.setData({
-        actionIndex: null,
-        deviceListIndex: null,
-      });
-    };
   },
 
   // 订阅设备在线状态
@@ -320,6 +322,7 @@ Page({
     };
 
     let topic = `/AIrSMArT_${that.data.deviceList[that.data.deviceListIndex].name.split("BLUFI_")[1]}/user/pub_response`;
+
     app.subscribe(topic);
     const obj = {
       DstDeviceName: that.getThisDeviceID()
@@ -418,12 +421,15 @@ Page({
     })
   },
 
-  goChannel() {
+  ///去频道详情
+  onTapToChannel() {
     var that = this;
-    wx.setStorageSync("channelDeta", that.data.channelData[that.data.actionIndex]);
-    wx.navigateTo({
-      url: './../channelDetails/channelDetails'
-    });
+    if (that.data.channelData.length > that.data.actionIndex) {
+      wx.setStorageSync("channelDeta", that.data.channelData[that.data.actionIndex]);
+      wx.navigateTo({
+        url: './../channelDetails/channelDetails'
+      });
+    }
   },
 
   onUnload() {
@@ -452,35 +458,35 @@ Page({
     })
   },
 
-  goMeLogin() {
+  onTapLogin() {
     var that = this;
+    ///退出登录
     if (that.data.isLogin) {
-      // 退出登录
-      wx.removeStorage({
-        key: 'userInfo',
-        success(res) {
-          var nickName = "未登录";
-          var greeting = that.getGreetBuNickName(nickName);
-
-          that.setData({
-            isLogin: false,
-            greeting: greeting,
-            nickName: nickName,
-            userPic: "./../../img/head_pic.png",
-          });
-        }
-      });
-      wx.removeStorage({
-        key: 'token',
-      })
-    } else {
-      // 登录
+      that.logOut();
+    }
+    // 登录
+    else {
       wx.navigateTo({
         url: './../login/login',
       });
     }
   },
 
+  ///退出登录
+  logOut() {
+    var that = this;
+    wx.removeStorageSync('userInfo');
+    wx.removeStorageSync('token');
+    var nickName = "未登录";
+    var greeting = that.getGreetBuNickName(nickName);
+    that.setData({
+      isLogin: false,
+      greeting: greeting,
+      nickName: nickName,
+      userPic: "./../../img/head_pic.png",
+    });
+  },
+
   addDevice() {
     var that = this;
     if (!that.data.isLogin) {
@@ -532,11 +538,14 @@ Page({
     } else {
       route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(item))
     }
-
   },
 
   actionDevice(index) {
     var that = this;
+    if (that.data.deviceList.length <= index) {
+      return;
+    };
+
     const device = that.data.deviceList[index];
     if (device.state !== "online") {
       return;

+ 2 - 2
pages/index/index.wxml

@@ -62,7 +62,7 @@
               <view wx:if="{{actionIndex !== null}}" style="opacity: 1;" class="fm">FM.{{actionIndex !== null ? (actionIndex + 1 < 10 ? "0" + (actionIndex + 1) : actionIndex + 1) : 00}} <image class="gochnnalList" mode="heightFix" src="./../../img/a6.png">
                   </image>
               </view>
-              <view class="fmMod" bindtap="goChannel"></view>
+              <view class="fmMod" bindtap="onTapToChannel"></view>
               <view wx:if="{{actionIndex !== null}}" class="thisMusic">
                 <text>当前播放:</text>
                 <view class="scroll-box">
@@ -153,7 +153,7 @@
           </view>
         </view>
         <view wx:if="{{isLogin}}" class="login">
-          <view bindtap="goMeLogin" class="{{!isLogin ? 'action' : ''}}">{{isLogin ? '退出登录' : "登录"}}</view>
+          <view bindtap="onTapLogin" class="{{!isLogin ? 'action' : ''}}">{{isLogin ? '退出登录' : "登录"}}</view>
         </view>
       </view>
     </view>

+ 2 - 2
utils/util.js

@@ -107,8 +107,7 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
         } else if (res.data.code === 401) {
           // token过期
           try {
-            // 删除过期token
-            wx.removeStorageSync('token');
+            getCurrentPages()[0].logOut();
           } catch (e) {
             console.log("可能没有这个缓存")
           };
@@ -119,6 +118,7 @@ function request(url, data = {}, method = "GET", header = urlencodeType, isToken
         }
       },
       fail: (err) => {
+        console.log("gadfadsfqweerqwerqewrqr==666==" + JSON.stringify(err));
         _show_error("1");
         wx.hideLoading();
       },