dm-wechat-mini/pages/login/login.js

116 lines
2.6 KiB
JavaScript

import userApi from '../../api/user';
const app = getApp();
Page({
data: {
isAgree: false,
loging:false,
animation:null,
userCode:'',
appConfig:{}
},
onLoad(options){
this.setData({
userCode:options.shared_user_code||app.globalData.shared_user_code||''
});
app.getAppConfig().then((data)=>{
console.log(data);
this.setData({
appConfig:data
})
})
},
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',
})
}
});
app.globalData.needRefreshOrderList = true;
const pages = getCurrentPages();
const prePage = pages[pages.length-2];
if(prePage){
prePage.onLoad(prePage.options);
}
}
})
})
},
navToPrivacy(){
wx.navigateTo({
url: `/pages/browser/index?url=${encodeURIComponent(this.data.appConfig.url_user_privacy)}`,
})
},
navToDeliveryContract(){
wx.navigateTo({
url: `/pages/browser/index?url=${encodeURIComponent(this.data.appConfig.url_delivery_contract)}`,
})
},
navToAgreement(){
wx.navigateTo({
url: `/pages/browser/index?url=${encodeURIComponent(this.data.appConfig.url_user_agreement)}`,
})
},
goBack(){
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()
})
}
})