From 75fc4aaa60501ce2e2fb3601f30a1ef2d3531919 Mon Sep 17 00:00:00 2001 From: Ethereal <3432649580@qq.com> Date: Sat, 25 Oct 2025 13:43:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E6=B7=BB=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/start/login/login.vue | 151 +++++++++++++++++++++++++++++++++----- pages/start/login/verification.js | 61 +++++++++++++++ 2 files changed, 195 insertions(+), 17 deletions(-) create mode 100644 pages/start/login/verification.js diff --git a/pages/start/login/login.vue b/pages/start/login/login.vue index f5243d6..df7e937 100644 --- a/pages/start/login/login.vue +++ b/pages/start/login/login.vue @@ -63,7 +63,7 @@ class="input-field" type="text" placeholder="请输入DeepChart ID" - v-model="email" + v-model="deepChartID" /> @@ -240,13 +240,16 @@ 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" +const deepChartID = ref(""); const type = ref("member"); const email = ref(""); const password = ref(""); +const country = ref("+86"); const phone = ref(""); const agreed = ref(false); -const switchType = ref("Email"); // 默认是邮箱注册 +const switchType = ref("User"); // 默认是邮箱注册 const { safeAreaInsets } = uni.getSystemInfoSync(); const codeBtnText = ref("获取验证码"); const isCodeBtnDisabled = ref(false); // 添加验证码按钮禁用状态 @@ -265,8 +268,7 @@ 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] ); // 显示国家选择器 @@ -277,6 +279,7 @@ function showCountryPicker() { ), success: function (res) { selectedCountry.value = countries.value[res.tapIndex]; + country.value = selectedCountry.value.code }, }); } @@ -291,34 +294,42 @@ function goToIndex() { function switchUser() { // 切换到手机注册 switchType.value = "User"; + password.value = ""; } function switchEmail() { // 切换到邮箱注册 switchType.value = "Email"; + password.value = ""; + } function switchPhone() { // 切换到手机注册 switchType.value = "Phone"; + password.value = ""; + } function register() { if (switchType.value === "User") { - } - if (switchType.value === "Email") { - // 登录逻辑 - if (!email.value) { + if (!deepChartID.value) { uni.showToast({ - title: "请输入邮箱地址", + title: "请输入用户名", icon: "none", }); return; } - // 发送登录请求 - console.log("登录:", email.value); + if (!password.value) { + uni.showToast({ + title: "请输入密码", + icon: "none", + }); + return; + } } + if (switchType.value === "Phone") { // 登录逻辑 @@ -330,8 +341,49 @@ function register() { return; } + if (!password.value) { + uni.showToast({ + title: "请输入验证码", + icon: "none", + }); + return; + } + const phoneAll = `${country.value}${phone.value}` + console.log("完整手机号"+phoneAll); + if(validatePhoneNumber(country.value,phone.value)){ + console.log("登录成功:", phoneAll); + } + + + + + + // 发送登录请求 - console.log("登录:", phone.value); + // console.log("登录:", phone.value); + } + + + if (switchType.value === "Email") { + // 登录逻辑 + if (!email.value) { + uni.showToast({ + title: "请输入邮箱地址", + icon: "none", + }); + return; + } + + if (!password.value) { + uni.showToast({ + title: "请输入验证码", + icon: "none", + }); + return; + } + + // 发送登录请求 + console.log("登录:", email.value); } if (!agreed.value) { @@ -341,10 +393,10 @@ function register() { } // 如果已经同意,则继续登录流程 - uni.showToast({ - title: "登录成功", - icon: "success", - }); + // uni.showToast({ + // title: "登录成功", + // icon: "success", + // }); } // 添加弹窗引用 @@ -423,6 +475,28 @@ function onPhoneInput(e) { } function sendCode() { + if(switchType.value === "Phone"){ + if(!phone.value){ + uni.showToast({ + title: "请输入手机号", + icon: "none", + }); + return; + } + } + + if(switchType.value === "Email"){ + if(!email.value){ + uni.showToast({ + title: "请输入邮箱地址", + icon: "none", + }); + return; + } + } + + + // 如果按钮已禁用,则不执行后续逻辑 if (isCodeBtnDisabled.value) return; @@ -471,6 +545,50 @@ function changeCheckbox() { ? "../../../static/icons/Check-one-true.png" : "../../../static/icons/Check-one-false.png"; } + +// 验证手机号是否正确 +function validatePhoneNumber(countryCode, phoneNumber) { + // 检查是否为空 + if (!phoneNumber || phoneNumber.trim() === '') { + uni.showToast({ + title: "手机号不能为空", + icon: "none", + }); + return false; + } + + + const bool = verification(countryCode,phoneNumber) + console.log("验证是否成功", bool); + + // 检查格式是否正确 + if (!bool) { + uni.showToast({ + title: "手机号格式不正确", + icon: "none", + }); + return false; + } + + // 去掉+号后检查长度(手机号通常在7到15位之间) + const cleanNumber = phoneNumber.replace(/^\+/, ''); + if (cleanNumber.length < 7 || cleanNumber.length > 15) { + uni.showToast({ + title: "手机号长度不正确", + icon: "none", + }); + return false; + } + + return true; +} + +// 部分国家优化手机号验证 + + + + + \ No newline at end of file diff --git a/pages/start/login/verification.js b/pages/start/login/verification.js new file mode 100644 index 0000000..8040c08 --- /dev/null +++ b/pages/start/login/verification.js @@ -0,0 +1,61 @@ + +function verification(countryCode,phoneNumber) { + switch (countryCode) { + case '+86': + return verificationChina(phoneNumber); + case '+1': + return verificationAmerica(phoneNumber); + case '+65': + return verificationSingapore(phoneNumber); + case '+60': + return verificationMalaysia(phoneNumber); + case '+66': + return verificationThailand(phoneNumber); + case '+852': + return verificationHongKong(phoneNumber); + case '+84': + return verificationVietnam(phoneNumber); + default: + return true; + } +} + + +function verificationChina(phoneNumber){ + const phoneRegex = /^1[3-9]\d{9}$/; + return phoneRegex.test(phoneNumber); +} + + +function verificationAmerica(phoneNumber){ + const phoneRegex = /^[2-9]\d{2}[- ]?\d{4}$/; + return phoneRegex.test(phoneNumber); +} +function verificationSingapore(phoneNumber){ + const phoneRegex = /^[89]\d{7}$/; + return phoneRegex.test(phoneNumber); +} +function verificationMalaysia(phoneNumber){ + const phoneRegex = /^01\d{8}$/; + return phoneRegex.test(phoneNumber); +} + +function verificationHongKong(phoneNumber){ + const phoneRegex = /^0[896]\d{8}$/; + return phoneRegex.test(phoneNumber); +} + + +function verificationThailand(phoneNumber){ + const phoneRegex = /^[5-9]\d{7}$/; + return phoneRegex.test(phoneNumber); +} + + + +function verificationVietnam(phoneNumber){ + const phoneRegex = /^(0)?[3-9]\d{8}$/; + return phoneRegex.test(phoneNumber); +} + +export {verification} \ No newline at end of file