Optimize captcha dialog

This commit is contained in:
mlogclub
2025-03-11 20:15:10 +08:00
parent c75fc41c38
commit 4dd65577b7
3 changed files with 36 additions and 44 deletions

View File

@@ -33,7 +33,7 @@
<a @click="toSignup">没有账号点击这里去注册&gt;&gt;</a>
</div>
<CaptchaDialog ref="captchaDialog" @confirm="captchaConfirm" />
<CaptchaDialog ref="captchaDialog" />
</div>
</template>
@@ -59,28 +59,24 @@ const clickLogin = async () => {
useMsgError("请输入密码");
return;
}
captchaDialog.value.show();
};
const captchaConfirm = async (captcha, callback) => {
form.captchaId = captcha.captchaId;
form.captchaCode = captcha.captchaCode;
captchaDialog.value.show().then(async (captcha) => {
form.captchaId = captcha.captchaId;
form.captchaCode = captcha.captchaCode;
try {
const userStore = useUserStore();
const { user, redirect } = await userStore.signin(form);
try {
const userStore = useUserStore();
const { user, redirect } = await userStore.signin(form);
callback(true);
if (redirect) {
useLinkTo(redirect);
} else {
useLinkTo(`/user/${user.id}`);
if (redirect) {
useLinkTo(redirect);
} else {
useLinkTo(`/user/${user.id}`);
}
} catch (e) {
useCatchError(e);
}
} catch (e) {
callback(false);
useCatchError(e);
}
});
};
const toSignup = async () => {

View File

@@ -91,7 +91,7 @@
</div>
</div>
<CaptchaDialog ref="captchaDialog" @confirm="publishSubmit" />
<CaptchaDialog ref="captchaDialog" />
</section>
</template>
@@ -166,13 +166,15 @@ const publish = () => {
}
if (topicCaptchaEnabled) {
captchaDialog.value.show();
captchaDialog.value.show().then((captcha) => {
publishSubmit(captcha);
});
} else {
publishSubmit();
}
};
const publishSubmit = async (captcha, callback) => {
const publishSubmit = async (captcha) => {
if (publishing.value) {
return;
}
@@ -197,8 +199,6 @@ const publishSubmit = async (captcha, callback) => {
} catch (e) {
useMsgError(e.message || e);
publishing.value = false;
} finally {
callback();
}
};
</script>

View File

@@ -80,7 +80,7 @@
</div>
</div>
<CaptchaDialog ref="captchaDialog" @confirm="captchaConfirm" />
<CaptchaDialog ref="captchaDialog" />
</section>
</template>
@@ -120,28 +120,24 @@ const clickSignup = async () => {
useMsgError("两次输入密码不一致");
return;
}
captchaDialog.value.show();
};
captchaDialog.value.show().then(async (captcha) => {
form.captchaId = captcha.captchaId;
form.captchaCode = captcha.captchaCode;
async function captchaConfirm(captcha, callback) {
form.captchaId = captcha.captchaId;
form.captchaCode = captcha.captchaCode;
try {
const userStore = useUserStore();
const { user, redirect } = await userStore.signup(form);
try {
const userStore = useUserStore();
const { user, redirect } = await userStore.signup(form);
callback(true);
if (redirect) {
useLinkTo(redirect);
} else {
useLinkTo(`/user/${user.id}`);
if (redirect) {
useLinkTo(redirect);
} else {
useLinkTo(`/user/${user.id}`);
}
} catch (err) {
useCatchError(err);
}
} catch (err) {
callback(false);
useCatchError(err);
}
}
});
};
function toSignin() {
if (form.redirect) {