litian
2024-04-11 f00c1cca98455a036548672d28e7e8ad13729a21
pages/bindInfo/index.js
@@ -1,4 +1,7 @@
// pages/index/bindInfo/index.js
import {
  setSessionGuid
} from "../../assets/js/userAction"
const app = getApp();
Page({
@@ -8,7 +11,7 @@
  data: {
    avatarUrl: "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0",
    nickName: "",
    wxCode: null,
    redirectPage: ""
  },
  onChooseAvatar(res) {
@@ -46,15 +49,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,
                });
              }
            })
          },
@@ -64,12 +76,11 @@
  },
  // 获取登录用户身份
  getUserInfo() {
    let that = this;
    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,19 +91,20 @@
            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'
      })
      if (that.data.redirectPage == "" || that.data.redirectPage == "/pages/home/home" || that.data.redirectPage == "/pages/bookServices/assort/index" || that.data.redirectPage == "/pages/study/index" || that.data.redirectPage == "/pages/cart/index" || that.data.redirectPage == "/pages/personalCenter/index") {
        wx.switchTab({
          url: that.data.redirectPage != "" ? that.data.redirectPage : '/pages/home/home'
        })
      } else {
        wx.navigateTo({
          url: that.data.redirectPage
        })
      }
    });
  },
@@ -101,8 +113,9 @@
   */
  onLoad(options) {
    console.log(options, "options");
    console.log(decodeURIComponent(options.page));
    this.setData({
      wxCode: options.code
      redirectPage: decodeURIComponent(options.page)
    })
  },