闫增涛
2024-03-27 696a0561d73970efdef2136d111269f626369fc9
pages/bindInfo/index.js
@@ -1,4 +1,5 @@
// pages/index/bindInfo/index.js
import { setSessionGuid } from "../../assets/js/userAction"
const app = getApp();
Page({
@@ -8,7 +9,7 @@
  data: {
    avatarUrl: "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0",
    nickName: "",
    wxCode: null,
    redirectPage: ""
  },
  onChooseAvatar(res) {
@@ -46,15 +47,24 @@
            app.MG.identity.loginByWeChatAppCode({
              code: res.code,
              appRefCode: app.config.appRefCode,
              platform: "weChatApp",
              platform: "WeChatAppCustom",
              icon: this.data.avatarUrl,
              encryptedData: infoRes.encryptedData,
              iv: infoRes.iv,
              name: this.data.nickName,
            }).then(res => {
              if (res && res.status == "Ok") {
                // 储存token
                wx.setStorageSync(app.config.tokenKey, res.token);
                // 获取用户信息
                this.getUserInfo()
                // 记录登录统计
                setSessionGuid()
              } else {
                wx.showToast({
                  icon: "error",
                  title: res.message,
                });
              }
            })
          },
@@ -65,11 +75,9 @@
  // 获取登录用户身份
  getUserInfo() {
    app.MG.identity.getCurrentAppUser().then(res => {
      // console.log(res, "userInfo");
      // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认)
      if (res) {
        let defaultUser = {};
        // let secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword')
        let WeChatInfo = res.infoList.find((item) => item.type === "WeChat");
        let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone')
@@ -80,18 +88,13 @@
            weChatId: WeChatInfo.id
          }
        }
        if (phoneNumber) {
          defaultUser.phoneNumber = phoneNumber.credential
        }
        this.setData({
          userInfo: defaultUser,
          loading: false
        })
        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo));
        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser));
      }
      wx.switchTab({
        url: '/pages/index/index'
      wx.navigateTo({
        url: this.data.redirectPage ? this.data.redirectPage : '/pages/home/home'
      })
    });
  },
@@ -101,8 +104,9 @@
   */
  onLoad(options) {
    console.log(options, "options");
    console.log(decodeURIComponent(options.page));
    this.setData({
      wxCode: options.code
      redirectPage: decodeURIComponent(options.page)
    })
  },