YM
2024-03-26 1c64c10f8dd88018c0d30de79237f3128173f118
pages/home/home.js
@@ -1,6 +1,6 @@
import { fetchHome } from '../../services/home/home';
import moment from 'moment'
import { setSessionGuid } from "../../assets/js/userAction"
import { checkLoginInfo } from '../../assets/js/login';
const app = getApp()
Page({
  data: {
@@ -11,6 +11,7 @@
    backUrl: null,
    userInfo: {},
    tabList: [], //目录
    current: 1,//轮播图参数
    autoplay: true, //轮播图参数
    duration: '500',//轮播图参数
    interval: 5000,//轮播图参数
@@ -28,12 +29,13 @@
    rankingList: [],//排行榜
    shoppingCartGetId: [],
    baseRefresh: {
      value: true
      value: false
    }
  },
  onShow() {
    this.loadHomePage();
    this.getBannerList()
  },
  onLoad(options) {
@@ -56,14 +58,20 @@
        backUrl: backUrl.backUrl
      })
    }
    this.getTestLoginInfo()
    // checkLoginInfo(app, (data) => {
    //   if (data) {
    //     this.getCurrentUserInfo();
    //   }
    // })
    this.init();
  },
  onReachBottom() {
  },
  onPullDownRefresh() {
    this.setData({
      isWhite: true
      'baseRefresh.value': true,
    })
    this.init();
  },
@@ -77,59 +85,9 @@
    setTimeout(() => {
      this.setData({
        baseRefresh: {
          value: false,
        },
        isWhite: false,
        'baseRefresh.value': false,
      })
    }, 500);
  },
  // 获取测试登录时的token
  getTestLoginInfo() {
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      wx.login({
        success: (res) => {
          wx.getUserInfo({
            success: (infoRes) => {
              app.MG.identity.checkWeChatAppAccount({
                code: res.code,
                appCode: app.config.appRefCode,
                encryptedData: infoRes.encryptedData,
                iv: infoRes.iv
              }).then(loginRes => {
                if (!loginRes) {
                  // wx.navigateTo({
                  //   url: "/pages/index/bindInfo/index?code=" + res.code,
                  // });
                } else {
                  wx.login({
                    success: (res) => {
                      app.MG.identity.loginByWeChatAppCode({
                        code: res.code,
                        appRefCode: app.config.appRefCode,
                        platform: "weChatApp",
                        encryptedData: infoRes.encryptedData,
                        iv: infoRes.iv
                      }).then(res => {
                        if (res && res.status == "Ok") {
                          wx.setStorageSync(app.config.tokenKey, res.token);
                          setSessionGuid()
                          this.getCurrentUserInfo()
                        }
                      })
                    },
                  })
                }
              })
            }
          })
        },
      })
    } else {
      this.getShoppingCartList();
    }
  },
  getCurrentUserInfo() {
@@ -164,7 +122,6 @@
          url: '/pages/home/home'
        })
      }
    });
  },
  getBannerList() {