Browse Source

优化登录注册的验证逻辑

wangyi/feature-20251022162725-启动页登录注册
Ethereal 4 weeks ago
parent
commit
a3edcce138
  1. 170
      pages/start/Registration/Registration.vue
  2. 192
      pages/start/login/login.vue

170
pages/start/Registration/Registration.vue

@ -85,7 +85,7 @@
class="input-field"
type="text"
placeholder="请输入验证码"
v-model="password"
v-model="verifyCode"
/>
</view>
</view>
@ -131,7 +131,7 @@
class="input-field"
type="text"
placeholder="请输入验证码"
v-model="password"
v-model="verifyCode"
/>
</view>
</view>
@ -149,7 +149,9 @@
<button class="register-btn" @click="register">注册</button>
<!-- 或者 -->
<text class="or-text" @click="goToLogin">已有账号登录 </text>
<text class="or-text" @click="goToLogin">已有账号
<text class="link">登录</text>
</text>
<!-- 同意弹窗 -->
<uniPopup ref="agreementPopup" type="dialog">
@ -194,6 +196,8 @@ const { safeAreaInsets } = uni.getSystemInfoSync();
const codeBtnText = ref("获取验证码");
const isCodeBtnDisabled = ref(false); //
const checkboxUrl = ref("../../../static/icons/Check-one-false.png");
const verifyCode = ref("");
const account = ref("");
// 使list.js
const countries = ref(
@ -234,11 +238,13 @@ function goToIndex() {
function switchEmail() {
//
switchType.value = "Email";
verifyCode.value = "";
}
function switchPhone() {
//
switchType.value = "Phone";
verifyCode.value = "";
}
// function register() {
@ -271,31 +277,54 @@ function switchPhone() {
// }
// }
function register() {
if (switchType.value === "Phone") {
//
if (!phone.value) {
if (!basicVerification()) {
return;
}
}
//
function basicVerification() {
if (switchType.value === "User") {
if (!deepChartID.value) {
uni.showToast({
title: "请输入手机号码",
title: "请输入用户名",
icon: "none",
});
return;
return false;
}
if (!password.value) {
uni.showToast({
title: "请输入验证码",
title: "请输入码",
icon: "none",
});
return;
return false;
}
}
if (switchType.value === "Phone") {
//
if (!phone.value) {
uni.showToast({
title: "请输入手机号码",
icon: "none",
});
return false;
}
const phoneAll = `${country.value}${phone.value}`;
console.log("完整手机号" + phoneAll);
if (validatePhoneNumber(country.value, phone.value)) {
console.log("登录成功:", phoneAll);
if (!validatePhoneNumber(country.value, phone.value)) {
return false;
}
//
// console.log(":", phone.value);
if (!verifyCode.value) {
uni.showToast({
title: "请输入验证码",
icon: "none",
});
return false;
}
}
if (switchType.value === "Email") {
@ -305,31 +334,27 @@ function register() {
title: "请输入邮箱地址",
icon: "none",
});
return;
}
if (!password.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;
}
//
console.log("登录:", email.value);
if (!verifyCode.value) {
uni.showToast({
title: "请输入验证码",
icon: "none",
});
return false;
}
}
if (!agreed.value) {
@ -338,61 +363,18 @@ function register() {
return;
}
//
// uni.showToast({
// title: "",
// icon: "success",
// });
}
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;
}
return true;
}
// function sendCode() {
// //
// if (isCodeBtnDisabled.value) return;
// //
// isCodeBtnDisabled.value = true;
// codeBtnText.value = "";
// let time = 6;
// const timer = setInterval(() => {
// time--;
// codeBtnText.value = " " + time + "S";
// if (time <= 0) {
// clearInterval(timer);
// codeBtnText.value = "";
// //
// isCodeBtnDisabled.value = false;
// }
// }, 1000);
// return;
// }
function sendCode() {
//
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 {

192
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",
// });
const account = changeAccount();
return true;
}
const res = await LoginApi({
loginType: switchType.value,
account: account,
verifyCode: verifyCode.value,
password: password.value,
useCode: verifyCode.value ? true : false,
idToken: "",
//
function VerCodeVerfifcation() {
if (switchType.value === "Phone") {
if (!phone.value) {
uni.showToast({
title: "请输入手机号",
icon: "none",
});
return false;
}
const message = res.message;
if (res.code === 200) {
//
const bool = verificationPhone(country.value, phone.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: "登录成功",
icon: "success",
title: "手机号格式不正确",
icon: "none",
});
//
uni.switchTab({
url: "/pages/start/index/index",
return false;
}
}
if (switchType.value === "Email") {
if (!email.value) {
uni.showToast({
title: "请输入邮箱地址",
icon: "none",
});
} else {
//
return false;
}
const bool = verificationEmail(email.value);
console.log("验证是否成功", bool);
//
if (!bool) {
uni.showToast({
title: message,
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",
});
if (!VerCodeVerfifcation()) {
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;
@ -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 {

Loading…
Cancel
Save