// pages/me/me.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { baseImgUrl: app.globalData.baseImgUrl, thumbnail: app.globalData.thumbnail, hiddenModel: false, level:3, ageGroup:2, statusBar: app.globalData.statusBar, meList:[ { id:'', img:'../../image/pai_hang_bang.png', url:'ranking', }, { id: '', img: '../../image/wo_de_ce_shi.png', url: 'result' }, { id: '', img: '../../image/ce_yi_ce.png', url: 'set_info' }, ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { app.getWxloginCode(code => { this.setData({ code }) }) const userInfo = wx.getStorageSync('userInfo') if (userInfo) { this.setData({ userInfo}) } this.getPersonInfo(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (app.sharePageDefaultCtl) { return app.sharePageDefaultCtl() } }, /** * 底部导航跳转 */ redirectCtl: app.redirectCtl, /** * 路由跳转 */ navigateCtl: app.navigateCtl, /** * 点击排行榜 */ clickOther:function(e){ const { bindex,url } = e.currentTarget.dataset; var that = this; const { level, ageGroup, userInfo } = that.data; if (userInfo) { console.log(bindex) // if(bindex==0){ // that.navigateCtl({ url: url, method: {} }, true) // }else if(bindex==1){ that.navigateCtl({ url: url, method: {} }, true) // } } else { wx.showToast({ title: '请授权登录后再试', icon: 'none' }) } }, /** * 微信授权 */ bindGetUserInfo: function (e) { const { code } = this.data; if (e.detail.userInfo) { app.saveUserInfo(e.detail, code) } else { wx.showToast({ title: '微信授权失败', icon: 'none' }) } }, /** * 获取个人信息 */ getPersonInfo:function(){ const postData = { fn: this.getPersonInfo, param: { ...arguments } } var that = this; const { userInfo } = this.data; app.post('/api/game/v2/homepageInfo', {}, 0, postData).then(res => { const { photo, name, level, ageGroup}=res.data; if (userInfo){ that.setData({ photo, name, level, ageGroup }); }else{ that.setData({ level, ageGroup }); } }) }, /** * 点击测一测 */ clickTest:function(){ const { level, ageGroup} = this.data; this.redirectCtl({ url: 'set_info', method: {} }, true) // if (ageGroup ==-1){ // this.redirectCtl({ url: 'set_info', method: { level:0, ageGroup } }, true) // } else{ // this.redirectCtl({ url: 'tu_xing_tui_li', method: { level:0, ageGroup } }, true) // } }, /** * 重新开始 */ getReset: function () { const { level, ageGroup} = this.data; const postData = { fn: this.getPersonInfo, param: { ...arguments } } var that = this; app.post('/api/game/v2/reset', {}, 0, postData).then(res => { that.navigateCtl({ url: 'info', method: { level: 1, ageGroup } }, true) that.setData({ hiddenModel:false}) // wx.showToast({ // title: '重置成功', // icon: 'none' // }) }) }, /** * 接着测试 */ geonTest: function () { const { level, ageGroup } = this.data; this.setData({ hiddenModel: false }) if (level==1){ this.navigateCtl({ url: 'tu_xing_tui_li', method: { level: 2, ageGroup } }, true) } else if (level == 2){ this.navigateCtl({ url: 'tu_xing_tui_li', method: { level: 3, ageGroup } }, true) } }, /** * 提示框隐藏 */ allShowModel: function () { this.setData({ hiddenModel: false }) }, })