Browse Source

fix[litemall-wx]: 当后台服务返回未登录信息时,清除当前的登录相关信息。

Junling Bu 7 years ago
parent
commit
67b386deeb
1 changed files with 11 additions and 1 deletions
  1. 11 1
      litemall-wx/utils/util.js

+ 11 - 1
litemall-wx/utils/util.js

@@ -1,4 +1,5 @@
 var api = require('../config/api.js');
+var app = getApp();
 
 function formatTime(date) {
   var year = date.getFullYear()
@@ -36,7 +37,16 @@ function request(url, data = {}, method = "GET") {
         if (res.statusCode == 200) {
 
           if (res.data.errno == 401) {
-            //需要登录后才可以操作
+            // 清除登录相关内容
+            try {
+              wx.removeStorageSync('userInfo');
+              wx.removeStorageSync('token');
+            } catch (e) {
+              // Do something when catch error
+            }
+            // 重置app的未登录状态
+            app.globalData.hasLogin = false;
+            // 切换到登录页面
             wx.navigateTo({
               url: '/pages/auth/login/login'
             });