完成了登录模块

This commit is contained in:
2025-05-19 09:08:33 +08:00
parent 7c934ded5f
commit 3fe9c3c209
20 changed files with 364 additions and 208 deletions

View File

@ -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: {