beefast-mini-deliveryman/pages/login/index.js
2025-02-20 19:34:09 +08:00

99 lines
1.7 KiB
JavaScript

import userApi from '../../api/user';
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
phone:'',
password:'',
isAgree:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.validator = {
phone:{type:'phone',message:'请输入正确的手机号',shake:true,autoFocus:true},
password:{required:true,message:'请输入密码',shake:true,autoFocus:true}
}
},
login(){
if(this.data.isAgree){
const valid = app.validateForm(this.validator,this);
console.log(valid,this.validator);
if(valid.length==0){
userApi.login(this.data.phone,this.data.password).then((data)=>{
app.globalData.userInfo = data.user;
app.globalData.accessToken = data.access_token;
wx.setStorage({
key:'accessToken',
data:data.access_token,
success:()=>{
wx.reLaunch({
url: '/pages/index/index',
})
}
})
})
}
}else{
}
},
handleAgreeChange(event){
this.setData({
isAgree:!!event.detail
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})