111
litian
2024-03-20 0555dd7dc2edc553030b7a6d03d6a1cda4b1e336
pages/personalCenter/index.js
@@ -77,21 +77,37 @@
    type: 'contact',
  }
];
const userTypeList = [
  {
    lable: '中职教师',
    value: 'vocSchoolTeachers'
  },
  {
    lable: '高职教师',
    value: 'vocCollegeTeachers'
  },
  {
    lable: '普通高校教师',
    value: 'ordUniversityTeachers'
  },
  {
    lable: '其他读者',
    value: 'otherReaders'
  }
];
Page({
  /**
   * 页面的初始数据
   */
  data: {
    barHeight: '',
    navBarHeight: '',
    isWhite: false,
    show: false,
    userInfo: {
      avatarUrl:
        'https://we-retail-static-1300977798.cos.ap-guangzhou.myqcloud.com/retail-ui/components-exp/avatar/avatar-1.jpg',
      nickName: 'TDesign',
      phoneNumber: '13438358888',
    },
    userInfo: {},
    currAuthStep: 1,
    userTypeActive: '',
    userTypeList,
    teacherState: {
      state: '',
      reasonTxt: '',
@@ -99,56 +115,109 @@
    integral: 0,
    menuData,
    moreMenu,
    moreMenu1
    moreMenu1,
    visible: false,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (wx.getStorageSync(app.config.userInfoKey)) {
  onLoad() {
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
      this.setData({
        show: true,
        userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
      })
      if (typeof this.getTabBar === 'function' && this.getTabBar()) {
        this.getTabBar().setData({
          selected: 4 //这个数字是当前页面在tabBar中list数组的索引
        })
      }
      this.getTeacherInfo()
      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",
      });
    }
  },
  /**
 * 生命周期函数--监听页面隐藏
 */
  onHide() {
    this.setData({
      show: false
    })
  onShow() {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.init();
    this.getUserInfo()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  },
  // 获取登录用户身份
  getUserInfo() {
    app.MG.identity.getCurrentAppUser().then(res => {
      // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认)
      if (res) {
        //获取用户类型
        let userTypeData = res.infoList.find((item) => item.type == 'userType')
        let type = "";
        if (userTypeData) {
          this.data.userTypeActive = JSON.parse(userTypeData.data).userType;
          type = userTypeList.find((item) => item.value === this.data.userTypeActive)?.lable;
        } else {
          type = '-'
        }
        let defaultUser = {};
        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,
            fullName: teacherInfos.fullName,
            icon: teacherInfos.icon,
            userId: res.userId,
            role: 'Teacher',
            roleId: teacherRole.role.id,
            userType: type
          }
          this.setData({
            currAuthStep: 2,
          });
        } else if (WeChatInfo) {
          defaultUser = {
            ...WeChatInfo,
            fullName: WeChatInfo.name,
            icon: WeChatInfo.icon,
            userId: res.userId,
            userType: type
          }
          this.setData({
            currAuthStep: 3,
          });
        } else if (secretData) {
          defaultUser = {
            fullName: secretData.credential,
            icon: "",
            userId: res.userId,
            userType: type
          }
        }
        this.setData({
          userInfo: defaultUser
        })
        this.getTeacherInfo()
        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo));
      }
    });
  },
  //教师信息
  getTeacherInfo() {
@@ -163,7 +232,6 @@
      }
    }
    app.MG.ugc.getTopicMessageList(data).then((res) => {
      console.log(this.data.userInfo, "userInfo")
      const resData = res.datas.find((i) => i.appUserCreator.userId == this.data.userInfo.userId)
      if (resData) {
        this.setData({
@@ -179,6 +247,23 @@
  toCertification() {
    wx.navigateTo({
      url: "/packageDomain/pages/teacherCertification/index",
    });
  },
  //修改用户类型
  editUserType() {
    this.setData({
      visible: true,
    });
  },
  onVisibleChange(e) {
    this.setData({
      visible: e.detail.visible,
    });
  },
  //设置
  gotoUserEditPage() {
    wx.navigateTo({
      url: "/packagePersonal/pages/userSetting/index",
    });
  },
@@ -203,13 +288,6 @@
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  },
  onPageScroll(e) {
    this.setData({
      isWhite: e.scrollTop > 50 ? true : false
    })
  },
  //跳转关于我们和联系我们