微信小程序登录后回调页面函数 - Page Execution in Login Callback

app.js

{
  login: function (emoji_enabled, avatar, nickName) {
    var that = this;
    wx.request({
      url: that.globalData.webservice_url + 'sys/user/login',
      data: JSON.stringify(that.encode({
        openId: wx.getStorageSync('openid'),
        header: avatar,
        nickname: nickName
      }, emoji_enabled)),
      dataType: "json",
      success: function (res) {
        if (res.data.code === 1) {
          wx.setStorageSync('token', res.data.data.token);
          wx.setStorageSync('balance', res.data.data.balance);
          wx.setStorageSync('businessId', res.data.data.businessId);
          wx.setStorageSync('userId', res.data.data.id);
          /**** KEY PART START ****/
          var pages = getCurrentPages() // get all current pages
          var currentPage = pages[pages.length - 1]  // Get current loading page
          currentPage.callback(); // Callback
          that.oncallback = false; // Callback called
          /**** KEY PART END ****/
        } else {
          that.showModal('提示', res.data.desc);
        }
      },
      fail: function (res) {
        that.showModal('提示', res.data.desc);
      },
      complete: function (res) {
        console.log(res)
      },
      method: 'POST'
    })
  }
}

page.js

{
  onLoad: function (options) {
    var that = this;
    this.setData({
      activityid: options.activityid,
      tab: options.tab || '0',
      share: options.share || false,
      paymentNo: options.no || ''
    }, function() {
      if (!app.oncallback) {
        that.load_activity();
        that.load_participants();
      }
    });
  },
  callback: function () {
    var that = this;
    that.load_activity();
    that.load_participants();
  },
}

你可能感兴趣的:(微信小程序登录后回调页面函数 - Page Execution in Login Callback)