完成了登录模块
This commit is contained in:
@ -63,12 +63,16 @@ Page({
|
||||
|
||||
// 3. 发送验证码请求
|
||||
wx.request({
|
||||
url: baseUrl + '/userInfo/code',
|
||||
url: baseUrl + '/userInfo/code/pwd',
|
||||
method: 'POST',
|
||||
data: { templateString: phone },
|
||||
success: () => {
|
||||
wx.showToast({ title: '验证码已发送', icon: 'none' });
|
||||
this._startCountdown(60);
|
||||
success: (res) => {
|
||||
if (res.data.code === 1) {
|
||||
wx.showToast({ title: '验证码已发送', icon: 'none' });
|
||||
this._startCountdown(60);
|
||||
} else {
|
||||
wx.showToast({ title: res.data.message, icon: 'none' });
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({ title: '发送失败,请重试', icon: 'none' });
|
||||
@ -114,17 +118,24 @@ Page({
|
||||
const { loginType, phone, credential, isAgree } = this.data;
|
||||
|
||||
// 非空校验(手机号、密码/验证码、协议)
|
||||
if (!validate(this.data, {
|
||||
phone: '请输入手机号',
|
||||
credential: loginType === 'password' ? '请输入密码' : '请输入验证码',
|
||||
isAgree: '请先同意用户协议'
|
||||
})) {
|
||||
if (!phone.trim()) {
|
||||
wx.showToast({ title: '请输入手机号', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
// 手机号格式校验
|
||||
if (!/^1\d{10}$/.test(phone)) {
|
||||
return wx.showToast({ title: '手机号格式不正确', icon: 'none' });
|
||||
}
|
||||
if (!validate(this.data, {
|
||||
credential: loginType === 'password' ? '请输入密码' : '请输入验证码',
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
// 2. 再单独校验协议勾选
|
||||
if (!this.data.isAgree) {
|
||||
wx.showToast({ title: '请先同意用户协议', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 组装请求
|
||||
const url = loginType === 'password'
|
||||
@ -145,10 +156,17 @@ Page({
|
||||
// ← 新增:将 token 存到本地缓存
|
||||
wx.setStorageSync('token', token);
|
||||
|
||||
wx.showToast({ title: '登录成功', icon: 'success' });
|
||||
wx.navigateTo({
|
||||
url: '/pages/projectModule/projectList/projectList'
|
||||
wx.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success',
|
||||
duration: 1000
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
wx.reLaunch({
|
||||
url: '/pages/projectModule/projectList/projectList',
|
||||
})
|
||||
}, 1000); // 1000ms = 1秒
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: res.data.message || '登录失败',
|
||||
|
Reference in New Issue
Block a user