import userApi from '../../api/user'; const app = getApp(); Page({ data: { isAgree: false, loging:false, animation:null, userCode:'' }, onLoad(options){ this.setData({ userCode:options.shared_user_code||'' }); }, radioChange(event){ this.setData({ isAgree:event.detail.value!='' }) }, preLogin(){ this.shake(); }, getPhoneNumber(event){ if(!event.detail.code){ //未接受 return; } this.setData({ loging:true }); wx.login({ success: (res) => { // 实现登录逻辑 this.sendLogin(res.code,event.detail.code); }, fail:()=>{ this.setData({ loging:false }); } }) }, sendLogin(wxcode,phonecode){ userApi.loginWithCode(wxcode,phonecode,this.data.userCode).then((data)=>{ this.setData({ loging:false }); app.globalData.accessToken = data.access_token; wx.setStorage({ key:"accessToken", data:data.access_token, success(){ wx.navigateBack({ fail(){ wx.reLaunch({ url: '/pages/help/index/index', }) } }); } }) }) }, shake(){ if(!this.animation){ this.animation = wx.createAnimation({ duration: 20, }) } this.animation.translateX(10).step(); this.animation.translateX(-10).step(); this.animation.translateX(10).step(); this.animation.translateX(-10).step(); this.animation.translateX(5).step(); this.animation.translateX(0).step(); // needSetData[`${key}Animation`] = item.animation.export(); this.setData({ animation:this.animation.export() }) } })