From a3edcce1384c704bb4e917a9b4f373d56104e2ad Mon Sep 17 00:00:00 2001 From: Ethereal <3432649580@qq.com> Date: Sun, 26 Oct 2025 14:36:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E7=9A=84=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/start/Registration/Registration.vue | 174 +++++++++++++------------ pages/start/login/login.vue | 206 +++++++++++++++--------------- 2 files changed, 196 insertions(+), 184 deletions(-) diff --git a/pages/start/Registration/Registration.vue b/pages/start/Registration/Registration.vue index 678e7a8..9ef0ba7 100644 --- a/pages/start/Registration/Registration.vue +++ b/pages/start/Registration/Registration.vue @@ -85,7 +85,7 @@ class="input-field" type="text" placeholder="请输入验证码" - v-model="password" + v-model="verifyCode" /> @@ -131,7 +131,7 @@ class="input-field" type="text" placeholder="请输入验证码" - v-model="password" + v-model="verifyCode" /> @@ -149,9 +149,11 @@ - 已有账号?登录 + 已有账号? + 登录 + - + { -// time--; -// codeBtnText.value = "重新发送 " + time + "S"; -// if (time <= 0) { -// clearInterval(timer); -// codeBtnText.value = "重新发送"; -// // 倒计时结束后启用按钮 -// isCodeBtnDisabled.value = false; -// } -// }, 1000); - -// return; -// } - -function sendCode() { - if (switchType.value === "Phone") { +// 验证码验证 +function VerCodeVerfifcation() { + if (switchType.value === "Phone") { if (!phone.value) { uni.showToast({ title: "请输入手机号", icon: "none", }); - return; + return false; } const bool = verificationPhone(country.value, phone.value); @@ -404,7 +386,7 @@ function sendCode() { title: "手机号格式不正确", icon: "none", }); - return; + return false; } } @@ -414,7 +396,7 @@ function sendCode() { title: "请输入邮箱地址", icon: "none", }); - return; + return false; } const bool = verificationEmail(email.value); console.log("验证是否成功", bool); @@ -425,10 +407,38 @@ function sendCode() { title: "邮箱格式不正确", icon: "none", }); - return; + return false; } } + return true; +} + +function goToLogin() { + // 跳转到登录页 + uni.navigateTo({ + url: "/pages/start/login/login", + }); +} + +function onPhoneInput(e) { + // 确保只允许输入数字 + const value = e.detail.value; + // 使用 isNaN 检查是否为有效数字 + if (isNaN(value)) { + phone.value = ""; + } else { + phone.value = value; + } +} + + +function sendCode() { + + if (!VerCodeVerfifcation()) { + return ; + } + // 如果按钮已禁用,则不执行后续逻辑 if (isCodeBtnDisabled.value) return; @@ -522,7 +532,6 @@ function handleAgree() { // 继续登录流程 } - // 处理同意按钮点击 function handleCancel() { // 关闭弹窗 @@ -873,7 +882,6 @@ function handleCancel() { bottom: 0; } - /* 弹窗样式 */ .popup-content { background-color: #ffffff; @@ -883,8 +891,6 @@ function handleCancel() { width: 550rpx; } - - .popup-message { font-size: 28rpx; color: #000000; @@ -896,7 +902,7 @@ function handleCancel() { align-items: center; /* 垂直居中 */ font-weight: 300; } -.popup-message-link{ +.popup-message-link { font-weight: 700; } .button-group { diff --git a/pages/start/login/login.vue b/pages/start/login/login.vue index f7e26fe..07e74ce 100644 --- a/pages/start/login/login.vue +++ b/pages/start/login/login.vue @@ -327,14 +327,52 @@ function switchPhone() { verifyCode.value = ""; } +// 登录 async function register() { + if (!basicVerification()) { + return; + } + + const account = changeAccount(); + + const res = await LoginApi({ + loginType: switchType.value, + account: account, + verifyCode: verifyCode.value, + password: password.value, + useCode: verifyCode.value ? true : false, + idToken: "", + }); + + const message = res.message; + if (res.code === 200) { + // 登录成功 + uni.showToast({ + title: "登录成功", + icon: "success", + }); + // 跳转到首页 + uni.switchTab({ + url: "/pages/start/index/index", + }); + } else { + // 登录失败 + uni.showToast({ + title: message, + icon: "none", + }); + } +} + +// 基础验证 +function basicVerification() { if (switchType.value === "User") { if (!deepChartID.value) { uni.showToast({ title: "请输入用户名", icon: "none", }); - return; + return false; } if (!password.value) { @@ -342,7 +380,7 @@ async function register() { title: "请输入密码", icon: "none", }); - return; + return false; } } @@ -353,7 +391,13 @@ async function register() { title: "请输入手机号码", icon: "none", }); - return; + return false; + } + + const phoneAll = `${country.value}${phone.value}`; + console.log("完整手机号" + phoneAll); + if (!validatePhoneNumber(country.value, phone.value)) { + return false; } if (!verifyCode.value) { @@ -361,16 +405,8 @@ async function register() { title: "请输入验证码", icon: "none", }); - return; - } - const phoneAll = `${country.value}${phone.value}`; - console.log("完整手机号" + phoneAll); - if (!validatePhoneNumber(country.value, phone.value)) { - return; + return false; } - - // 发送登录请求 - // console.log("登录:", phone.value); } if (switchType.value === "Email") { @@ -380,30 +416,27 @@ async function register() { title: "请输入邮箱地址", icon: "none", }); - return; - } - - if (!verifyCode.value) { - uni.showToast({ - title: "请输入验证码", - icon: "none", - }); - return; + return false; } const bool = verificationEmail(email.value); console.log("验证是否成功", bool); - // 检查格式是否正确 if (!bool) { uni.showToast({ title: "邮箱格式不正确", icon: "none", }); - return; + return false; + } + + if (!verifyCode.value) { + uni.showToast({ + title: "请输入验证码", + icon: "none", + }); + return false; } - // 发送登录请求 - // console.log("登录:", email.value); } if (!agreed.value) { @@ -412,41 +445,55 @@ async function register() { return; } - // 如果已经同意,则继续登录流程 - // uni.showToast({ - // title: "登录成功", - // icon: "success", - // }); + return true; +} - const account = changeAccount(); +// 注册码码验证 +function VerCodeVerfifcation() { + if (switchType.value === "Phone") { + if (!phone.value) { + uni.showToast({ + title: "请输入手机号", + icon: "none", + }); + return false; + } - const res = await LoginApi({ - loginType: switchType.value, - account: account, - verifyCode: verifyCode.value, - password: password.value, - useCode: verifyCode.value ? true : false, - idToken: "", - }); + const bool = verificationPhone(country.value, phone.value); + console.log("验证是否成功", bool); - const message = res.message; - if (res.code === 200) { - // 登录成功 - uni.showToast({ - title: "登录成功", - icon: "success", - }); - // 跳转到首页 - uni.switchTab({ - url: "/pages/start/index/index", - }); - } else { - // 登录失败 - uni.showToast({ - title: message, - icon: "none", - }); + // 检查格式是否正确 + if (!bool) { + uni.showToast({ + title: "手机号格式不正确", + icon: "none", + }); + return false; + } } + + if (switchType.value === "Email") { + if (!email.value) { + uni.showToast({ + title: "请输入邮箱地址", + icon: "none", + }); + return false; + } + const bool = verificationEmail(email.value); + console.log("验证是否成功", bool); + + // 检查格式是否正确 + if (!bool) { + uni.showToast({ + title: "邮箱格式不正确", + icon: "none", + }); + return false; + } + } + + return true; } function changeAccount() { @@ -545,49 +592,10 @@ function onPhoneInput(e) { } async function sendCode() { - if (switchType.value === "Phone") { - if (!phone.value) { - uni.showToast({ - title: "请输入手机号", - icon: "none", - }); - return; - } - - const bool = verificationPhone(country.value, phone.value); - console.log("验证是否成功", bool); - - // 检查格式是否正确 - if (!bool) { - uni.showToast({ - title: "手机号格式不正确", - icon: "none", - }); - return; - } - } - - if (switchType.value === "Email") { - if (!email.value) { - uni.showToast({ - title: "请输入邮箱地址", - icon: "none", - }); - return; - } - const bool = verificationEmail(email.value); - console.log("验证是否成功", bool); - // 检查格式是否正确 - if (!bool) { - uni.showToast({ - title: "邮箱格式不正确", - icon: "none", - }); - return; - } + if (!VerCodeVerfifcation()) { + return; } - // 如果按钮已禁用,则不执行后续逻辑 if (isCodeBtnDisabled.value) return; @@ -1045,8 +1053,6 @@ function validatePhoneNumber(countryCode, phoneNumber) { width: 550rpx; } - - .popup-message { font-size: 28rpx; color: #000000; @@ -1058,7 +1064,7 @@ function validatePhoneNumber(countryCode, phoneNumber) { align-items: center; /* 垂直居中 */ font-weight: 300; } -.popup-message-link{ +.popup-message-link { font-weight: 700; } .button-group {