dm-wechat-mini/pages/login/login.js
2025-02-22 03:14:42 +08:00

73 lines
1.5 KiB
JavaScript

import userApi from '../../api/user';
const app = getApp();
Page({
data: {
isAgree: false,
loging:false,
animation:null
},
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).then((data)=>{
this.setData({
loging:false
});
app.globalData.accessToken = data.access_token;
wx.setStorage({
key:"accessToken",
data:data.access_token,
success(){
console.log(app.globalData);
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()
})
}
})