65 lines
1.2 KiB
JavaScript
65 lines
1.2 KiB
JavaScript
import userApi from '../../api/user';
|
|
const app = getApp();
|
|
|
|
Page({
|
|
data: {
|
|
isAgree: false,
|
|
loging:false
|
|
},
|
|
|
|
handleAgreeChange(e) {
|
|
this.setData({
|
|
isAgree: e.detail.value.length > 0
|
|
})
|
|
},
|
|
|
|
onLogin() {
|
|
if (!this.data.isAgree) {
|
|
wx.showToast({
|
|
title: '请先同意用户协议和隐私政策',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
|
|
},
|
|
getPhoneNumber(event){
|
|
console.log(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',
|
|
})
|
|
}
|
|
})
|
|
})
|
|
}
|
|
})
|