修改功能,现已测试注册登录忘记密码
This commit is contained in:
+141
-15
@@ -127,10 +127,10 @@
|
||||
let layerInstance = null;
|
||||
let currentCaptchaId = "";
|
||||
let currentVerifyType = "captcha";
|
||||
let currentSlideToken = "";
|
||||
let currentSlideUuid = "";
|
||||
let currentSlideX = 0;
|
||||
let pendingSmsAfterVerify = false;
|
||||
let smsCodeIssuedPhone = "";
|
||||
|
||||
function showError(field, message) {
|
||||
const containerId =
|
||||
@@ -158,13 +158,12 @@
|
||||
|
||||
function refreshCaptcha() {
|
||||
currentCaptchaId = "";
|
||||
currentSlideToken = "";
|
||||
currentSlideUuid = "";
|
||||
currentSlideX = 0;
|
||||
$("#captchaId").val("");
|
||||
$("#captchaInput").val("");
|
||||
$("#captchaGroup").removeClass("is-slide-mode");
|
||||
$("#sendSmsBtn").prop("disabled", currentVerifyType === "slide");
|
||||
$("#sendSmsBtn").prop("disabled", false);
|
||||
if (currentVerifyType === "slide") {
|
||||
renderSlideCaptchaEntry();
|
||||
return;
|
||||
@@ -200,9 +199,6 @@
|
||||
function completeSlideCaptcha(result) {
|
||||
const data = result || {};
|
||||
const nested = data.data || {};
|
||||
currentSlideToken =
|
||||
data.slideToken || data.token || data.verifyToken ||
|
||||
nested.slideToken || nested.token || nested.verifyToken || "";
|
||||
currentSlideUuid =
|
||||
data.slideUuid || data.uuid || nested.slideUuid || nested.uuid || "";
|
||||
currentSlideX =
|
||||
@@ -234,7 +230,6 @@
|
||||
onSuccess: completeSlideCaptcha,
|
||||
onCancel: function () {
|
||||
currentSlideUuid = "";
|
||||
currentSlideToken = "";
|
||||
currentSlideX = 0;
|
||||
},
|
||||
onError: function (error) {
|
||||
@@ -257,7 +252,7 @@
|
||||
$("#captchaInput").hide();
|
||||
$("#captchaRefreshLink").hide();
|
||||
$("#captchaGroup").addClass("is-slide-mode");
|
||||
$("#sendSmsBtn").prop("disabled", true);
|
||||
$("#sendSmsBtn").prop("disabled", false);
|
||||
$("#captchaContainer")
|
||||
.removeAttr("onclick")
|
||||
.html(
|
||||
@@ -294,6 +289,29 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
function hasIssuedSmsCodeForCurrentPhone() {
|
||||
const phone = $("#phone").val().trim();
|
||||
return !!phone && smsCodeIssuedPhone === phone;
|
||||
}
|
||||
|
||||
function handlePhoneInput() {
|
||||
const phone = $("#phone").val().trim();
|
||||
if (smsCodeIssuedPhone && smsCodeIssuedPhone !== phone) {
|
||||
smsCodeIssuedPhone = "";
|
||||
$("#smsCode").val("");
|
||||
}
|
||||
}
|
||||
|
||||
function validateSmsCodePhone(show) {
|
||||
if (!validateSmsCode(show)) return false;
|
||||
if (!hasIssuedSmsCodeForCurrentPhone()) {
|
||||
if (show) showError("smsCode", "请先获取当前手机号的短信验证码");
|
||||
return false;
|
||||
}
|
||||
clearError("smsCode");
|
||||
return true;
|
||||
}
|
||||
|
||||
function validatePassword(show) {
|
||||
if (!AuthPageUtil.isPassword($("#password").val())) {
|
||||
if (show) showError("password", "密码长度应为6-20位");
|
||||
@@ -320,7 +338,6 @@
|
||||
}
|
||||
return {
|
||||
verifyType: "slide",
|
||||
slideToken: currentSlideToken,
|
||||
slideUuid: currentSlideUuid,
|
||||
slideX: currentSlideX,
|
||||
};
|
||||
@@ -334,23 +351,131 @@
|
||||
return { verifyType: "captcha", code, uuid: currentCaptchaId };
|
||||
}
|
||||
|
||||
function getSmsWaitSeconds() {
|
||||
const smsCountdownApi = ApiClient.API["authSmsCountdown"];
|
||||
if (!smsCountdownApi) return Promise.resolve(0);
|
||||
return ApiClient.get(
|
||||
smsCountdownApi,
|
||||
{ phoneNumber: $("#phone").val().trim(), scene: "auth" },
|
||||
{ publicRequest: true },
|
||||
)
|
||||
.then(function (res) {
|
||||
if (!ApiClient.isSuccess(res)) return 0;
|
||||
const data = res.data || {};
|
||||
return Number(data.seconds || data.waitSeconds || data.remainingSeconds || data.countdown || 0) || 0;
|
||||
})
|
||||
.catch(function () {
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
function refreshDialogCaptcha() {
|
||||
currentCaptchaId = "";
|
||||
$("#captchaInput").val("");
|
||||
$("#captchaId").val("");
|
||||
$("#captchaDialogInput").val("");
|
||||
$("#captchaDialogImage").attr("src", "");
|
||||
return ApiClient.get(ApiClient.API.authCode, {}, { publicRequest: true })
|
||||
.then(function (res) {
|
||||
if (ApiClient.isSuccess(res) && res.data) {
|
||||
currentCaptchaId = res.data.uuid || res.data.id || "";
|
||||
$("#captchaId").val(currentCaptchaId);
|
||||
$("#captchaDialogImage").attr("src", res.data.img || res.data.image || "");
|
||||
return;
|
||||
}
|
||||
layerInstance.msg("获取验证码失败,请重试", { icon: 2 });
|
||||
})
|
||||
.catch(function () {
|
||||
layerInstance.msg("网络错误,无法获取验证码", { icon: 2 });
|
||||
});
|
||||
}
|
||||
|
||||
function openImageCaptchaDialog() {
|
||||
const dialogHtml =
|
||||
'<div class="captcha-dialog">' +
|
||||
'<div class="captcha-dialog-title">完成图片验证码</div>' +
|
||||
'<div class="captcha-dialog-desc">请输入右侧图片中的验证码,通过后将自动发送短信验证码。</div>' +
|
||||
'<div class="captcha-dialog-row">' +
|
||||
'<input type="text" class="captcha-dialog-input" id="captchaDialogInput" maxlength="6" placeholder="请输入验证码" />' +
|
||||
'<div class="captcha-dialog-img-box" id="captchaDialogRefresh">' +
|
||||
'<img class="captcha-dialog-img" id="captchaDialogImage" src="" alt="验证码" />' +
|
||||
'</div></div>' +
|
||||
'<div class="captcha-dialog-tip">看不清?<span id="captchaDialogRefreshText">换一张</span></div>' +
|
||||
'<div class="captcha-dialog-actions">' +
|
||||
'<button type="button" class="captcha-dialog-btn" id="captchaDialogCancel">取消</button>' +
|
||||
'<button type="button" class="captcha-dialog-btn primary" id="captchaDialogConfirm">确认发送</button>' +
|
||||
'</div></div>';
|
||||
|
||||
const dialogIndex = layerInstance.open({
|
||||
type: 1,
|
||||
title: false,
|
||||
area: ["420px", "auto"],
|
||||
shadeClose: true,
|
||||
closeBtn: 1,
|
||||
content: dialogHtml,
|
||||
success: function () {
|
||||
refreshDialogCaptcha();
|
||||
$("#captchaDialogRefresh, #captchaDialogRefreshText").on("click", refreshDialogCaptcha);
|
||||
$("#captchaDialogCancel").on("click", function () {
|
||||
layerInstance.close(dialogIndex);
|
||||
});
|
||||
$("#captchaDialogInput").on("keydown", function (event) {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
$("#captchaDialogConfirm").trigger("click");
|
||||
}
|
||||
});
|
||||
$("#captchaDialogConfirm").on("click", function () {
|
||||
const code = $("#captchaDialogInput").val().trim();
|
||||
if (!code) {
|
||||
layerInstance.msg("请输入验证码", { icon: 2 });
|
||||
return;
|
||||
}
|
||||
$("#captchaInput").val(code);
|
||||
layerInstance.close(dialogIndex);
|
||||
sendSmsCode();
|
||||
});
|
||||
setTimeout(function () {
|
||||
$("#captchaDialogInput").focus();
|
||||
}, 80);
|
||||
},
|
||||
end: function () {
|
||||
$("#sendSmsBtn").prop("disabled", false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function sendSmsCode() {
|
||||
if (!validatePhone(true)) return;
|
||||
if (currentVerifyType === "slide" && !currentSlideUuid) {
|
||||
layerInstance.msg("请先完成滑动验证后获取短信验证码", { icon: 2 });
|
||||
pendingSmsAfterVerify = true;
|
||||
openSlideCaptcha();
|
||||
return;
|
||||
}
|
||||
if (currentVerifyType === "captcha" && !$("#captchaInput").val().trim()) {
|
||||
$("#sendSmsBtn").prop("disabled", true);
|
||||
openImageCaptchaDialog();
|
||||
return;
|
||||
}
|
||||
const verifyParams = getVerifyParams(true);
|
||||
if (!verifyParams) return;
|
||||
$("#sendSmsBtn").prop("disabled", true);
|
||||
AuthPageUtil.sendForgotPasswordSmsCode(
|
||||
getSmsWaitSeconds().then(function (waitSeconds) {
|
||||
if (waitSeconds > 0) {
|
||||
layerInstance.msg("请 " + waitSeconds + " 秒后再获取短信验证码", { icon: 0 });
|
||||
AuthPageUtil.startSmsCountdown("#sendSmsBtn", waitSeconds);
|
||||
throw new Error("__SMS_WAIT__");
|
||||
}
|
||||
return AuthPageUtil.sendForgotPasswordSmsCode(
|
||||
Object.assign(
|
||||
{ phoneNumber: $("#phone").val().trim() },
|
||||
verifyParams,
|
||||
),
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(function (res) {
|
||||
if (ApiClient.isSuccess(res)) {
|
||||
smsCodeIssuedPhone = $("#phone").val().trim();
|
||||
layerInstance.msg("短信验证码已发送", { icon: 1 });
|
||||
AuthPageUtil.startSmsCountdown("#sendSmsBtn");
|
||||
return;
|
||||
@@ -361,7 +486,8 @@
|
||||
});
|
||||
refreshCaptcha();
|
||||
})
|
||||
.catch(function () {
|
||||
.catch(function (error) {
|
||||
if (error && error.message === "__SMS_WAIT__") return;
|
||||
$("#sendSmsBtn").prop("disabled", false);
|
||||
layerInstance.msg("网络异常,短信发送失败", { icon: 2 });
|
||||
refreshCaptcha();
|
||||
@@ -371,7 +497,7 @@
|
||||
function validateForm() {
|
||||
if (
|
||||
!validatePhone(true) ||
|
||||
!validateSmsCode(true) ||
|
||||
!validateSmsCodePhone(true) ||
|
||||
!validatePassword(true) ||
|
||||
!validateConfirmPassword(true)
|
||||
)
|
||||
@@ -433,7 +559,7 @@
|
||||
event.preventDefault();
|
||||
if (validateForm()) submitResetPassword();
|
||||
});
|
||||
$("#phone").on("blur", function () {
|
||||
$("#phone").on("input", handlePhoneInput).on("blur", function () {
|
||||
validatePhone(true);
|
||||
});
|
||||
$("#smsCode").on("blur", function () {
|
||||
|
||||
Reference in New Issue
Block a user