// pages/login/index.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { login: false, canIUseGetUserProfilefalse: false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let userInfo = wx.getStorageSync('userInfo') if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } }, getUserProfile(e) { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 app.login().then((res)=>{ if(res.data.success){ wx.navigateBack({ delta: 1, }) } }) }, getPhoneNumber(e) { if(e.detail.errMsg == 'getPhoneNumber:ok'){ app.http('post','wxapp/binding', {encryptedData: e.detail.encryptedData, iv: e.detail.iv }).then((res)=>{ if(res.data.success){ app.getInfo(); wx.showToast({ title: res.data.msg, duration: 1500 }) setTimeout(()=>{ wx.navigateBack({ delta: 1, }) },1500) } else{ wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) setTimeout(()=>{ wx.navigateBack({ delta: 1, }) },2000) } }) } }, back(){ wx.navigateBack({ delta: 1, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })