修复邮箱注册验证码报错的bug

This commit is contained in:
xiaojunnuo
2025-10-28 15:30:31 +08:00
parent 0c8b8647f3
commit d32f4fc38e
4 changed files with 66 additions and 56 deletions

View File

@@ -56,10 +56,10 @@ function onChange(data: any) {
}
async function getCaptchaForm() {
return await captchaRef.value.getCaptchaForm();
return await captchaRef.value?.getCaptchaForm();
}
async function reset() {
await captchaRef.value.reset();
await captchaRef.value?.reset();
}
defineExpose({
getCaptchaForm,

View File

@@ -53,6 +53,13 @@ function callback(res: { ret: number; ticket: string; randstr: string; errorCode
// res验证成功 = {ret: 0, ticket: "String", randstr: "String"}
// res请求验证码发生错误验证码自动返回trerror_前缀的容灾票据 = {ret: 0, ticket: "String", randstr: "String", errorCode: Number, errorMessage: "String"}
// 此处代码仅为验证结果的展示示例真实业务接入建议基于ticket和errorCode情况做不同的业务处理
if (res.errorCode && res.errorCode > 0) {
notification.error({
message: `验证码验证失败:${res.errorMessage || res.errorCode}`,
});
}
if (res.ret === 0) {
emitChange({
ticket: res.ticket,
@@ -116,7 +123,7 @@ function emitChange(value: any) {
emit("change", value);
}
function reset() {
captchaInstanceRef.value.instance.reset();
captchaInstanceRef.value?.instance?.reset();
}
watch(

View File

@@ -61,7 +61,7 @@
</a-input-password>
</a-form-item>
<a-form-item has-feedback name="imgCode" label="验证码" :rules="rules.imgCode">
<a-form-item has-feedback name="captchaForEmail" label="验证码" :rules="rules.captchaForEmail">
<CaptchaInput v-model:model-value="formState.captchaForEmail"></CaptchaInput>
</a-form-item>
@@ -118,6 +118,7 @@ export default defineComponent({
password: "",
confirmPassword: "",
captcha: null,
captchaForEmail: null,
});
const rules = {
@@ -180,10 +181,10 @@ export default defineComponent({
message: "请通过验证码",
},
],
imgCode: [
captchaForEmail: [
{
required: true,
message: "请输入验证码",
message: "请通过验证码",
},
],
};
@@ -204,7 +205,7 @@ export default defineComponent({
password: formState.password,
username: formState.username,
email: formState.email,
captcha: formState.captcha,
captcha: registerType.value === "email" ? formState.captchaForEmail : formState.captcha,
validateCode: formState.validateCode,
}) as any
);