zrug 6 tháng trước cách đây
mục cha
commit
2509430bd8
3 tập tin đã thay đổi với 41 bổ sung37 xóa
  1. 34 30
      app.js
  2. 1 1
      service/api.js
  3. 6 6
      utils/http.js

+ 34 - 30
app.js

@@ -27,37 +27,41 @@ App({
   onLaunch() {
 
     // 登录
-    wx.login({
-      success: res => {
-        // 发送 res.code 到后台换取 accessTokenDTO, userProfileDTO
-        console.log("code", res);
-        if (res.code){
-          wx.request({
-            url: baseUrl + '/api/store/wxlogin',
-            method: 'POST',
-            data: {
-              jsCode: res.code
-            },
-            header: {
-              'content-type': 'application/x-www-form-urlencoded',
-              'X-Referrer-Id': '', // 旧租户字段
-              'X-Store-Id': '', // 旧租户字段
-            },
-            success:(res)=> {
-              console.log(res);
-              this.globalData.mUser = res.data.data;
-              wx.setStorageSync('accessToken', this.globalData.mUser.accessTokenDTO.accessToken);
-            },
-            fail: function(res){
-              console.log(res);
-            }
-          })
+    if (wx.getStorageSync('accessToken')) {
+      this.globalData.loginSuccess = true;
+    } else {
+      wx.login({
+        success: res => {
+          // 发送 res.code 到后台换取 accessTokenDTO, userProfileDTO
+          console.log("code", res);
+          if (res.code){
+            wx.request({
+              url: baseUrl + '/api/store/wxlogin',
+              method: 'POST',
+              data: {
+                jsCode: res.code
+              },
+              header: {
+                'content-type': 'application/x-www-form-urlencoded',
+                'X-Referrer-Id': '', // 旧租户字段
+                'X-Store-Id': '', // 旧租户字段
+              },
+              success:(res)=> {
+                console.log(res);
+                this.globalData.mUser = res.data.data;
+                wx.setStorageSync('accessToken', this.globalData.mUser.accessTokenDTO.accessToken);
+              },
+              fail: function(res){
+                console.log(res);
+              }
+            })
+          }
+        },
+        fail: function(e){
+          console.log(e);
         }
-      },
-      fail: function(e){
-        console.log(e);
-      }
-    })
+      })
+    }
   },
 })
 

+ 1 - 1
service/api.js

@@ -45,7 +45,7 @@ export const HomepageApi = {
   }
   */
   getBanners: function (payload) {
-    return http.post("/api/store/homepage/banners", {
+    return http.get("/api/store/homepage/banners", {
       ...payload,
     });
   },

+ 6 - 6
utils/http.js

@@ -49,18 +49,18 @@ function getPromise(url, data, method) {
       },
     });
   }).catch((e) => {
-    if (401 === e) {
+    // if (401 === e) {
       // redirect to login page
-      wx.navigateTo({
-        url: "/pages/login/login",
-      });
-    } else {
+    //   wx.navigateTo({
+    //     url: "/pages/login/login",
+    //   });
+    // } else {
       console.error(`in promise error, url: ${baseUrl}${url}`);
       console.error(e);
       if (e) {
         showErrToast(e);
       }
-    }
+    // }
   });
 }