diff --git a/pages/start/login/login.vue b/pages/start/login/login.vue index df7e937..96b0fef 100644 --- a/pages/start/login/login.vue +++ b/pages/start/login/login.vue @@ -240,7 +240,7 @@ import countryList from "./list.js"; import footerBar from "../../../components/footerBar-cn"; import uniPopupDialogVue from "../../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.vue"; import uniPopup from "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.vue"; -import {verification} from "../login/verification" +import { verificationPhone, verificationEmail } from "../login/verification"; const deepChartID = ref(""); const type = ref("member"); @@ -268,7 +268,8 @@ const countries = ref( // 默认选中的国家(中国) const selectedCountry = ref( - countries.value.find((country) => country.short === "CN") || countries.value[0] + countries.value.find((country) => country.short === "CN") || + countries.value[0] ); // 显示国家选择器 @@ -279,7 +280,7 @@ function showCountryPicker() { ), success: function (res) { selectedCountry.value = countries.value[res.tapIndex]; - country.value = selectedCountry.value.code + country.value = selectedCountry.value.code; }, }); } @@ -301,14 +302,12 @@ function switchEmail() { // 切换到邮箱注册 switchType.value = "Email"; password.value = ""; - } function switchPhone() { // 切换到手机注册 switchType.value = "Phone"; password.value = ""; - } function register() { @@ -329,7 +328,6 @@ function register() { return; } } - if (switchType.value === "Phone") { // 登录逻辑 @@ -341,30 +339,24 @@ function register() { return; } - if (!password.value) { + if (!password.value) { uni.showToast({ title: "请输入验证码", icon: "none", }); return; } - const phoneAll = `${country.value}${phone.value}` - console.log("完整手机号"+phoneAll); - if(validatePhoneNumber(country.value,phone.value)){ + const phoneAll = `${country.value}${phone.value}`; + console.log("完整手机号" + phoneAll); + if (validatePhoneNumber(country.value, phone.value)) { console.log("登录成功:", phoneAll); } - - - - - // 发送登录请求 // console.log("登录:", phone.value); } - - if (switchType.value === "Email") { + if (switchType.value === "Email") { // 登录逻辑 if (!email.value) { uni.showToast({ @@ -382,6 +374,18 @@ function register() { return; } + const bool = verificationEmail(email.value); + console.log("验证是否成功", bool); + + // 检查格式是否正确 + if (!bool) { + uni.showToast({ + title: "邮箱格式不正确", + icon: "none", + }); + return; + } + // 发送登录请求 console.log("登录:", email.value); } @@ -475,27 +479,48 @@ function onPhoneInput(e) { } function sendCode() { - if(switchType.value === "Phone"){ - if(!phone.value){ + if (switchType.value === "Phone") { + if (!phone.value) { uni.showToast({ title: "请输入手机号", icon: "none", }); return; } - } - if(switchType.value === "Email"){ - if(!email.value){ + const bool = verificationPhone(country.value, phone.value); + console.log("验证是否成功", bool); + + // 检查格式是否正确 + if (!bool) { uni.showToast({ - title: "请输入邮箱地址", + 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 (isCodeBtnDisabled.value) return; @@ -549,46 +574,38 @@ function changeCheckbox() { // 验证手机号是否正确 function validatePhoneNumber(countryCode, phoneNumber) { // 检查是否为空 - if (!phoneNumber || phoneNumber.trim() === '') { - uni.showToast({ - title: "手机号不能为空", - icon: "none", - }); + if (!phoneNumber || phoneNumber.trim() === "") { + uni.showToast({ + title: "手机号不能为空", + icon: "none", + }); return false; } - - const bool = verification(countryCode,phoneNumber) + const bool = verificationPhone(countryCode, phoneNumber); console.log("验证是否成功", bool); - + // 检查格式是否正确 if (!bool) { - uni.showToast({ - title: "手机号格式不正确", - icon: "none", - }); + uni.showToast({ + title: "手机号格式不正确", + icon: "none", + }); return false; } - + // 去掉+号后检查长度(手机号通常在7到15位之间) - const cleanNumber = phoneNumber.replace(/^\+/, ''); + const cleanNumber = phoneNumber.replace(/^\+/, ""); if (cleanNumber.length < 7 || cleanNumber.length > 15) { uni.showToast({ - title: "手机号长度不正确", - icon: "none", - }); + title: "手机号长度不正确", + icon: "none", + }); return false; } - + return true; } - -// 部分国家优化手机号验证 - - - - -