diff --git a/frontend/src/stores/user.ts b/frontend/src/stores/user.ts index f7c0050..f2fc598 100644 --- a/frontend/src/stores/user.ts +++ b/frontend/src/stores/user.ts @@ -42,7 +42,7 @@ export const useUserStore = defineStore('user', () => { await pb.collection('users').authWithPassword(email, password) await initUser() } catch (error: any) { - throw new Error(error.message || '登录失败') + throw new Error('邮箱或密码错误') } finally { loading.value = false } @@ -55,6 +55,14 @@ export const useUserStore = defineStore('user', () => { await pb.collection('users').create(data) await login(data.email, data.password) } catch (error: any) { + const validation = error?.data?.data || error?.data + if (validation) { + const messages: string[] = [] + if (validation.email) messages.push('邮箱无效或已被使用') + if (validation.username) messages.push('用户名无效或已被使用') + if (validation.password) messages.push('密码不符合要求') + if (messages.length > 0) throw new Error(messages.join(';')) + } throw new Error(error.message || '注册失败') } finally { loading.value = false