完成了登录模块
This commit is contained in:
@ -41,12 +41,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' });
|
||||
@ -96,14 +100,14 @@ Page({
|
||||
newPwd: '请输入新密码',
|
||||
confirmPwd: '请再次输入新密码'
|
||||
})) return;
|
||||
// 2. 密码一致
|
||||
if (newPwd !== confirmPwd) {
|
||||
return wx.showToast({ title: '两次密码不一致', icon: 'none' });
|
||||
}
|
||||
// 3. 格式校验手机号
|
||||
if (!/^1\d{10}$/.test(phone)) {
|
||||
return wx.showToast({ title: '手机号格式不正确', icon: 'none' });
|
||||
}
|
||||
// 2. 密码一致
|
||||
if (newPwd !== confirmPwd) {
|
||||
return wx.showToast({ title: '两次密码不一致', icon: 'none' });
|
||||
}
|
||||
// 4. 发起重置请求
|
||||
wx.request({
|
||||
url: baseUrl + '/userInfo/mini/forgetPwd',
|
||||
|
@ -1,7 +1,7 @@
|
||||
<view class="flex-col page">
|
||||
<image
|
||||
class="self-center image"
|
||||
src="https://ide.code.fun/api/image?token=6827630f4ae84d00122fd0c8&name=f8bf0cb3ec8201f89a31727a655c0709.png"
|
||||
src="https://img.picui.cn/free/2025/05/19/682a0dbe4085c.png"
|
||||
/>
|
||||
<text class="self-center text">欢迎登陆—青橙校园</text>
|
||||
|
||||
|
@ -50,7 +50,7 @@
|
||||
}
|
||||
.section_2 {
|
||||
margin-right: 4.42rpx;
|
||||
padding: 20.16rpx 16.88rpx 19.22rpx;
|
||||
padding: 25.16rpx 16.88rpx 24.22rpx;
|
||||
background-color: #ffffff;
|
||||
border-radius: 9.38rpx;
|
||||
box-shadow: 0rpx 3.75rpx 7.5rpx #00000040;
|
||||
|
@ -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 || '登录失败',
|
||||
|
@ -1,7 +1,7 @@
|
||||
<view class="flex-col page">
|
||||
<image
|
||||
class="self-center image"
|
||||
src="https://ide.code.fun/api/image?token=6827630f4ae84d00122fd0c8&name=f8bf0cb3ec8201f89a31727a655c0709.png"
|
||||
src="https://img.picui.cn/free/2025/05/19/682a0dbe4085c.png"
|
||||
/>
|
||||
<text class="self-center text">欢迎登陆—青橙校园</text>
|
||||
<view class="flex-col self-stretch group">
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { url } from "../../../request";
|
||||
import { baseUrl } from "../../../request";
|
||||
import { requestAsync } from "../../../utils/request";
|
||||
import { validate } from "../../../utils/validate";
|
||||
|
||||
@ -9,11 +9,11 @@ Page({
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
nickname: 'cxz',
|
||||
phone: '13888610253',
|
||||
captcha: '111111',
|
||||
inviteCode: '123456',
|
||||
password: '123456',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
captcha: '',
|
||||
inviteCode: '',
|
||||
password: '',
|
||||
agree: false,
|
||||
sending: false,
|
||||
count: 60,
|
||||
@ -21,12 +21,16 @@ Page({
|
||||
|
||||
sendSmsCode() {
|
||||
const { phone } = this.data;
|
||||
if (!phone.trim()) {
|
||||
wx.showToast({ title: '请输入手机号', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!/^1\d{10}$/.test(phone)) {
|
||||
wx.showToast({ title: '请输入有效的手机号', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
wx.request({
|
||||
url: url + '/userInfo/code',
|
||||
url: baseUrl + '/userInfo/code/register',
|
||||
method: 'POST',
|
||||
header: { 'content-type': 'application/json' },
|
||||
data: {
|
||||
@ -78,16 +82,8 @@ Page({
|
||||
|
||||
// 注册按钮点击
|
||||
async onRegister() {
|
||||
if (!this.data.agree) {
|
||||
wx.showToast({
|
||||
title: '请先勾选同意协议',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 调用通用校验,失败时已提示并 return
|
||||
if (!validate(this.data, {
|
||||
agree: '请先勾选同意协议',
|
||||
nickname: '请输入昵称',
|
||||
phone: '请输入手机号',
|
||||
captcha: '请输入验证码',
|
||||
@ -96,9 +92,14 @@ Page({
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
// 2. 再单独校验协议勾选
|
||||
if (!this.data.agree) {
|
||||
wx.showToast({ title: '请先同意用户协议', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
const { nickname, phone, captcha, inviteCode, password } = this.data;
|
||||
const res = await requestAsync({
|
||||
url: url + '/userInfo/register',
|
||||
url: baseUrl + '/userInfo/register',
|
||||
method: 'POST',
|
||||
header: { 'content-type': 'application/json' },
|
||||
data: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<view class="flex-col page">
|
||||
<image
|
||||
class="self-center image"
|
||||
src="https://ide.code.fun/api/image?token=68274ca04ae84d00122fcf90&name=f8bf0cb3ec8201f89a31727a655c0709.png"
|
||||
src="https://img.picui.cn/free/2025/05/19/682a0dbe4085c.png"
|
||||
/>
|
||||
<text class="self-center text">欢迎登陆—青橙校园</text>
|
||||
<view class="flex-col self-stretch group">
|
||||
|
Reference in New Issue
Block a user