1
闫增涛
2024-03-27 b2a6887c94cc7887b03ba1cce578e3fc59a62259
pages/home/home.js
@@ -1,6 +1,6 @@
import { fetchHome } from '../../services/home/home';
import moment from 'moment'
import { checkLoginInfo } from '../../assets/js/login';
import { loginInfo } from '../../assets/js/login';
const app = getApp()
Page({
  data: {
@@ -8,7 +8,6 @@
    navBarHeight: '',
    searchVal: '',
    isWhite: false,
    backUrl: null,
    userInfo: {},
    tabList: [], //目录
    current: 1,//轮播图参数
@@ -39,7 +38,7 @@
  },
  onLoad(options) {
  onLoad() {
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
@@ -47,24 +46,22 @@
      barHeight: systInfo.statusBarHeight,
      navBarHeight: navBarHeight,
    });
    if (options.backUrl) {
      let backUrl = JSON.parse(decodeURIComponent(options.backUrl));
      if (backUrl.options) {
        for (let key in backUrl.options) {
          const value = backUrl.options[key]
          backUrl.backUrl += `${key}=${value}&`
        }
      }
      this.setData({
        backUrl: backUrl.backUrl
      })
    }
    // checkLoginInfo(app, (data) => {
    //   if (data) {
    //     this.getCurrentUserInfo();
    //   }
    // })
    // 首页测试登录功能,后续注释
    // 检查登录状态
    // const token = wx.getStorageSync(app.config.tokenKey)
    // if (!token) {
    //   loginInfo(app, (data) => {
    //     // 如果不是第一次登录,会执行回调
    //     if (data) {
    //       // 登录成功,自动记录token和用户信息,并返回true
    //     } else {
    //       // 出现错误,返回false
    //     }
    //   })
    // } else {
    //   // 如果是第一次登录,会跳转至绑定用户信息页面,填写完用户信息后进行登录并储存token和用户信息,结束后跳转回当前页面(携带页面参数)
    // }
    this.init();
  },
@@ -91,39 +88,6 @@
    }, 500);
  },
  getCurrentUserInfo() {
    app.MG.identity.getCurrentAppUser().then(res => {
      // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认)
      if (res) {
        let defaultUser = {};
        let WeChatInfo = res.infoList.find((item) => item.type === "WeChat");
        let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone')
        if (WeChatInfo) {
          defaultUser = {
            nickName: WeChatInfo.name,
            avatarUrl: WeChatInfo.icon,
            weChatId: WeChatInfo.id
          }
        }
        if (phoneNumber) {
          defaultUser.phoneNumber = phoneNumber.credential
        }
        this.setData({
          userInfo: defaultUser,
        })
        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo));
      }
      if (this.data.backUrl) {
        wx.navigateTo({
          url: this.data.backUrl,
        })
      } else {
        wx.switchTab({
          url: '/pages/home/home'
        })
      }
    });
  },
  getBannerList() {
    const list = []
    app.MG.resource.getItem({