Przeglądaj źródła

feature: 解决token过期的问题

Damon 8 miesięcy temu
rodzic
commit
b423af685c
3 zmienionych plików z 9 dodań i 9 usunięć
  1. 2 4
      pages/index/index.js
  2. 3 2
      pages/login/login.js
  3. 4 3
      utils/util.js

+ 2 - 4
pages/index/index.js

@@ -116,7 +116,6 @@ Page({
       //   app.subscribe(topic);
       // }
     }
-
   },
 
   // 回调
@@ -127,6 +126,7 @@ Page({
     if (option) {
       payloads = JSON.parse(option.payload);
     };
+
     switch (type) {
       case "connect":
         that.connectSuccess();
@@ -149,7 +149,6 @@ Page({
             actionIndex,
           });
         } else if (payloads.type === "play" || payloads.type === "play_state") {
-
           if (that.data.deviceListIndex === null) {
             return;
           }
@@ -309,7 +308,6 @@ Page({
     if (that.data.deviceList.length === 0 || that.data.deviceListIndex === null) {
       return
     };
-
     let topic = `/AIrSMArT_${that.data.deviceList[that.data.deviceListIndex].name.split("BLUFI_")[1]}/user/pub_response`;
     app.subscribe(topic);
     const obj = {
@@ -361,7 +359,7 @@ Page({
   },
 
   getchannelData(clientType) {
-    var that = this;Ï
+    var that = this;
     if (that.data.deviceListIndex === null) {
       return;
     };

+ 3 - 2
pages/login/login.js

@@ -71,10 +71,11 @@ Page({
                     });
                     app.globalData.userInfo = res5;
                     wx.setStorageSync("userInfo", res5);
-                    wx.setStorageSync("token", {
+                    wx.setStorageSync("token", JSON.stringify({
                       id: res5.userId,
                       token: res5.accessToken,
-                    });
+                    }), );
+
                     getCurrentPages()[0].onUserInfoLoad();
                     setTimeout(() => {
                       wx.redirectTo({

+ 4 - 3
utils/util.js

@@ -58,9 +58,10 @@ function _show_error(error_code) {
 function request(url, data = {}, method = "GET", header = urlencodeType, isToken = true) {
   if (isToken) {
     try {
-      var token = wx.getStorageSync("token") || "";
-      if (!strings.isEmpty(token)) {
-        Authorization = value.token;
+      var value = wx.getStorageSync('token') || "";
+      if (!strings.isEmpty(value)) {
+        const resData = JSON.parse(value);
+        Authorization = resData.token;
       }
     } catch (e) {
       Authorization = "";