// index.js // 获取应用实例 const app = getApp() let userInfo = getApp().globalData.userInfo let token = getApp().globalData.token console.log(userInfo) Page({ data: { avatarModal: false, phoneModal: false, phoneModal1: false, showBg: false, step: 0,// 头像授权1, 手机授权2 nickNamebind: false, phonebind: false, userInfo: null, userid:'', token: '' }, onLoad() { if (userInfo) { this.setData({ token: token, userid: userInfo.id, userInfo: userInfo }) if(!!userInfo.userWxName&&!!userInfo.phone){ this.leave() return; } if(!userInfo.userWxName||!userInfo.phone){ this.setData({ showBg: true }) }else{ this.setData({ showBg: false }) } this.setData({ avatarModal: !!userInfo.userWxName?false:true, phoneModal1: !!userInfo.phone?false:true, step: 1 }) if(!this.data.avatarModal){ this.setData({ step: 2, phoneModal: this.data.phoneModal1 }) } } }, backhome(){ wx.navigateTo({ url: '/pages/index/index' }) }, shouquan(){ if(userInfo.phone){ wx.showToast({ icon: 'none', title: '您已完成授权', }) } if(this.data.step==1){ this.setData({ avatarModal: true, showBg: true }) } if(this.data.step==2){ this.setData({ phoneModal: true, showBg: true }) } }, closeModal(){ this.setData({ showBg: false }) }, leave(){ wx.navigateTo({ url: '/pages/out/index?index=1&userid='+ this.data.userid+'&gameid=1'+'&type=2', }) }, // 绑定用户头像信息 bindNickname(obj) { let that = this let params = { id: that.data.userid, userWxHeadImgUrl: obj.avatarUrl, userWxName: obj.nickName, userVxGender: obj.gender } wx.request({ url: 'https://cktest.2weisou.com/meta/ar/user/bindNickname', method: "POST", data: params, header: { Authorization: 'bearer '+ that.data.token }, success(res) { if (res.statusCode == 200) { that.setData({ avatarModal: false, step: 2 }) if(that.data.phoneModal1){ that.setData({ phoneModal: true }) } } } }) }, getUserInfo(){ let that = this wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { // console.log(res) that.bindNickname(res.userInfo) } }) }, // 授权手机号 getPhoneNumber(e) { console.log(e); let that = this if (e.detail.errMsg == "getPhoneNumber:ok") { const { iv, encryptedData } = e.detail; wx.request({ url: 'https://cktest.2weisou.com/meta/ar/user/bindMini', method: "POST", data: { encrypted: encryptedData, iv }, header: { Authorization: 'bearer '+ that.data.token }, success(res) { console.log(res) if (res.data.code == 0) { // console.log(res) that.setData({ phoneModal: false, showBg: false, step: 0 }) that.leave() } } }) } else { wx.showToast({ icon: "none", title: "请授权手机号" }) } } })