litian
2024-03-29 4b5f1f7ed3460df9465e5071a59b8105cbc9146e
pages/personalCenter/index.js
@@ -1,4 +1,7 @@
const app = getApp()
const app = getApp();
import {
  loginInfo
} from '../../assets/js/login';
const menuData = [{
    title: '我的订单',
    icon: '/static/images/personal/order.png',
@@ -132,25 +135,30 @@
      barHeight: systInfo.statusBarHeight,
      navBarHeight: navBarHeight,
    });
    if (wx.getStorageSync(app.config.tokenKey)) {
      this.setData({
        currAuthStep: 2,
      });
      this.getUserInfo()
    } else {
      this.setData({
        currAuthStep: 1,
      });
      wx.navigateTo({
        url: "/pages/testLogin/index",
      });
    }
  },
  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        active: 4
      })
    }
    // 检查登录状态
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
          this.setData({
            currAuthStep: 2,
          });
          this.getUserInfo()
        }
      })
    } else {
      this.setData({
        currAuthStep: 1,
      });
      this.getUserInfo()
    }
  },
  /**
@@ -180,19 +188,18 @@
          });
          type = userTypeList.find((item) => item.value === this.data.userTypeActive)?.lable;
        } else {
          type = '-'
          type = ''
        }
        let defaultUser = {};
        let nickNameData = res.infoList.find((item) => item.type == 'nickName')
        let teacherRole = res.roleLinks.find((item) => item.role.refCode == 'teacher')
        let teacherInfos = res.infoList.find((item) => item.type == 'teacherInfo')
        let secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword')
        let WeChatInfo = res.infoList.find((item) => item.type === "WeChat");
        if (teacherRole && teacherInfos) {
          defaultUser = {
            ...teacherInfos,
            nickName: nickNameData ? JSON.parse(nickNameData.data).nickName : teacherInfos.name,
            icon: nickNameData ? JSON.parse(nickNameData.data).icon : WeChatInfo ? WeChatInfo.icon : '',
            nickName: nickNameData && JSON.parse(nickNameData.data).nickName ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name,
            icon: nickNameData && JSON.parse(nickNameData.data).icon ? JSON.parse(nickNameData.data).icon : WeChatInfo.icon,
            userId: res.userId,
            role: 'Teacher',
            roleId: teacherRole.role.id,
@@ -205,8 +212,8 @@
        } else if (WeChatInfo) {
          defaultUser = {
            ...WeChatInfo,
            nickName: nickNameData ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name,
            icon: nickNameData ? JSON.parse(nickNameData.data).icon : WeChatInfo.icon,
            nickName: nickNameData && JSON.parse(nickNameData.data).nickName ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name,
            icon: nickNameData && JSON.parse(nickNameData.data).icon ? JSON.parse(nickNameData.data).icon : WeChatInfo.icon,
            userId: res.userId,
            userType: type,
            role: 'Student',
@@ -214,14 +221,6 @@
          this.setData({
            currAuthStep: 3,
          });
        } else if (secretData) {
          defaultUser = {
            nickName: nickNameData ? JSON.parse(nickNameData.data).nickName : secretData.credential,
            icon: nickNameData ? JSON.parse(nickNameData.data).icon : "",
            userId: res.userId,
            userType: type,
            role: 'Student',
          }
        }
        this.setData({
          userInfo: defaultUser