// pages/me/me.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { userInfo: { avatarUrl:"../../images/person.png" }, loginif:false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(app.globalData); if(wx.getStorageSync('openid')){ this.setData({ loginif:true }) }else{ this.setData({ loginif:false }) } if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, }) } else if (this.data.canIUse) { app.userInfoReadyCallback = res => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } } else { // 在没有 open-type=getUserInfo 版本的兼容处理 wx.getUserInfo({ success: res => { app.globalData.userInfo = res.userInfo this.setData({ userInfo: res.userInfo, }) } }) }; }, login:function(){ wx.navigateTo ({ url: '/pages/auth/auth', }) }, getUserInfo: function(e) { //点击取消按钮 if (e.detail.userInfo == null) { console.log("授权失败") } else {//点击允许按钮 this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) } //全局对象用户信息赋值 app.globalData.userInfo = e.detail.userInfo }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.onLoad() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, gotoAttention(){ if(wx.getStorageSync('openid')){ wx.navigateTo({ url: '../attention/attention', }) }else{ wx.showLoading({title: '请先授权登录'}) setTimeout(function(){ wx.hideLoading() },600); } }, gotoAbout(){ wx.showToast({ title: '正在开发中', icon:'loading', duration:500 }) } })