Files
ClassContent/项目合集/校园失物招领/min-tpl/pages/account/account.js
2024-09-27 02:06:13 +08:00

175 lines
3.4 KiB
JavaScript

const {
user,
util
} = getApp().globalData
Page({
/**
* 页面的初始数据
*/
data: {
isShowLogin: true,
phone: '', // 手机号
pwd: '', // 密码
confirmPwd: '', // 确认密码
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(user);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
async UserLogin() {
let { phone, pwd } = this.data
if (!util.checkPhone(phone)) {
wx.showToast({
title: '号码错误',
icon: 'none',
duration: 2000
})
return false;
}
if (pwd.length == 0) {
wx.showToast({
title: '密码必填',
icon: 'none',
duration: 2000
})
return false;
}
let res = await user.login({
phone: phone,
pwd: pwd
});
wx.setStorageSync('user', res);
util.showToast({
title: '登录成功',
icon: 'success',
duration: 2000,
close: () => wx.switchTab({ url: '/pages/index/index' })
})
},
async UserRegister() {
let { phone, pwd, confirmPwd } = this.data
if (!util.checkPhone(phone)) {
wx.showToast({
title: '号码错误',
icon: 'none',
duration: 2000
})
return false;
}
if (pwd.length == 0) {
wx.showToast({
title: '密码必填',
icon: 'none',
duration: 2000
})
return false;
}
if (confirmPwd.length == 0 || confirmPwd != pwd) {
wx.showToast({
title: '确认密码必填,且必须和密码一致',
icon: 'none',
duration: 2000
})
return false;
}
let res = await user.add({
phone: phone,
pwd: pwd
});
util.showToast({
title: '注册成功,即将跳转登录!',
icon: 'none',
duration: 2000,
close: () => this.setData({ isShowLogin: true })
})
},
// 手机号
bindPhoneInput(e) {
this.setData({
phone: e.detail.value
})
},
// 确认密码
bindConfirmPwdInput(e) {
this.setData({
confirmPwd: e.detail.value
})
},
// 密码
bindPwdInput(e) {
this.setData({
pwd: e.detail.value
})
},
changeStatus() {
this.setData({
isShowLogin: !this.data.isShowLogin
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})