fix:注册提示

This commit is contained in:
2025-11-12 10:04:40 +08:00
parent 65a48b6927
commit 34cb51e037

View File

@@ -34,6 +34,15 @@ const submit = async () => {
return;
}
// 基础密码强度校验,避免命中后端 400
const hasUpper = /[A-Z]/.test(form.password);
const hasNumber = /[0-9]/.test(form.password);
const hasSpecial = /[^A-Za-z0-9]/.test(form.password);
if (form.password.length < 8 || !hasUpper || !hasNumber || !hasSpecial) {
errorMessage.value = '密码需至少8位且包含大写字母、数字和特殊字符';
return;
}
isLoading.value = true;
errorMessage.value = '';
try {
@@ -51,6 +60,18 @@ const submit = async () => {
console.warn('register failed', err);
const status = err?.response?.status as number | undefined;
const backendMsg = err?.response?.data?.message as string | undefined;
const fieldErrors = err?.response?.data?.errors as Record<string, string[]> | undefined;
// 展示后端字段级错误Zod
if (fieldErrors) {
const pick = (...keys: string[]) => keys.flatMap((k) => fieldErrors[k] ?? []);
const messages =
pick('displayName', 'email', 'password', 'confirmPassword')[0] ||
Object.values(fieldErrors).flat()[0];
if (messages) {
errorMessage.value = messages;
return;
}
}
if (!status) {
errorMessage.value = '无法连接服务器,请检查网络或 API 地址配置。';
} else if (status === 409) {