2
0

修复忘记密码时提示错误问题

This commit is contained in:
lai
2025-02-20 16:08:46 +08:00
parent 1dd6d27d64
commit 9172a03e11
3 changed files with 83 additions and 100 deletions

View File

@@ -79,14 +79,19 @@ async function handleSubmit() {
try {
await validate();
await resetPasswordByEmail({
const { error } = resetPasswordByEmail({
email: model.email,
code: model.code,
password: model.password
});
window.$message?.success(t('page.login.resetPwd.resetSuccess'));
toggleLoginModule('pwd-login');
if (!error) {
window.$message?.success(t('page.login.resetPwd.resetSuccess'));
toggleLoginModule('pwd-login');
}
} catch (error) {
console.error('Reset password failed:', error);
window.$message?.error(t('page.login.resetPwd.resetFailed'));
@@ -97,34 +102,25 @@ async function handleSubmit() {
<template>
<AForm ref="formRef" :model="model" :rules="rules">
<AFormItem name="email">
<AInput v-model:value="model.email" size="large" :placeholder="t('page.login.common.emailPlaceholder')" autocomplete="off"/>
<AInput v-model:value="model.email" size="large" :placeholder="t('page.login.common.emailPlaceholder')"
autocomplete="off" />
</AFormItem>
<AFormItem name="code">
<div class="w-full flex-y-center gap-8px">
<AInput v-model:value="model.code" size="large" :placeholder="t('page.login.common.codePlaceholder')" autocomplete="off"/>
<AButton
size="small"
:disabled="isCounting"
:loading="loading"
@click="handleCaptcha"
>
<AInput v-model:value="model.code" size="large" :placeholder="t('page.login.common.codePlaceholder')"
autocomplete="off" />
<AButton size="small" :disabled="isCounting" :loading="loading" @click="handleCaptcha">
{{ label }}
</AButton>
</div>
</AFormItem>
<AFormItem name="password">
<AInputPassword
v-model:value="model.password"
size="large"
:placeholder="t('page.login.common.passwordPlaceholder')"
/>
<AInputPassword v-model:value="model.password" size="large"
:placeholder="t('page.login.common.passwordPlaceholder')" />
</AFormItem>
<AFormItem name="confirmPassword">
<AInputPassword
v-model:value="model.confirmPassword"
size="large"
:placeholder="t('page.login.common.confirmPasswordPlaceholder')"
/>
<AInputPassword v-model:value="model.confirmPassword" size="large"
:placeholder="t('page.login.common.confirmPasswordPlaceholder')" />
</AFormItem>
<ASpace direction="vertical" size="large" class="w-full">
<AButton type="primary" block size="large" shape="round" @click="handleSubmit">

View File

@@ -118,29 +118,40 @@ async function handleSubmit() {
try {
await formRef.value?.validate();
if (resetType.value === 'password') {
// 通过原密码重置
await resetPassword({
oldPassword: formModel.oldPassword,
newPassword: formModel.password
});
} else {
// 通过邮箱验证码重置
await resetPasswordByEmail({
email: formModel.email,
code: formModel.code,
password: formModel.password
});
}
message.success({
content: t('page.login.resetPwd.resetSuccess'),
duration: 2
});
// if (resetType.value === 'password') {
// // 通过原密码重置
// await resetPassword({
// oldPassword: formModel.oldPassword,
// newPassword: formModel.password
// });
// } else {
// // 通过邮箱验证码重置
// await resetPasswordByEmail({
// email: formModel.email,
// code: formModel.code,
// password: formModel.password
// });
// }
const { error } = await (resetType.value === 'password' ? resetPassword({
oldPassword: formModel.oldPassword,
newPassword: formModel.password
}) : resetPasswordByEmail({
email: formModel.email,
code: formModel.code,
password: formModel.password
}));
if (!error) {
message.success({
content: t('page.login.resetPwd.resetSuccess'),
duration: 2
});
// 延迟跳转
setTimeout(() => {
router.push('/userInfo/usercard');
}, 2000);
}
// 延迟跳转
setTimeout(() => {
router.push('/userInfo/usercard');
}, 2000);
} catch (error) {
console.error('Reset password failed:', error);
@@ -169,51 +180,32 @@ const handleBack = () => {
<a-radio value="email">{{ t('page.login.resetPwd.byEmail') }}</a-radio>
</a-radio-group>
<a-form
ref="formRef"
:model="formModel"
:rules="formRules"
:label-col="{
xs: { span: 24 },
sm: { span: 8 },
md: { span: 6 }
}"
:wrapper-col="{
xs: { span: 24 },
sm: { span: 16 },
md: { span: 18 }
}"
>
<a-form ref="formRef" :model="formModel" :rules="formRules" :label-col="{
xs: { span: 24 },
sm: { span: 8 },
md: { span: 6 }
}" :wrapper-col="{
xs: { span: 24 },
sm: { span: 16 },
md: { span: 18 }
}">
<template v-if="resetType === 'password'">
<a-form-item name="oldPassword" :label="t('page.login.resetPwd.oldPassword')">
<a-input-password
v-model:value="formModel.oldPassword"
:placeholder="t('page.login.resetPwd.oldPasswordPlaceholder')"
/>
<a-input-password v-model:value="formModel.oldPassword"
:placeholder="t('page.login.resetPwd.oldPasswordPlaceholder')" />
</a-form-item>
</template>
<template v-else>
<a-form-item name="email" :label="t('page.login.register.email')">
<a-input
v-model:value="formModel.email"
:placeholder="t('page.login.common.emailPlaceholder')"
/>
<a-input v-model:value="formModel.email" :placeholder="t('page.login.common.emailPlaceholder')" />
</a-form-item>
<a-form-item name="code" :label="t('page.login.register.code')">
<a-space>
<a-input
v-model:value="formModel.code"
:placeholder="t('page.login.common.codePlaceholder')"
style="width: 200px"
/>
<a-button
type="primary"
:loading="loading"
:disabled="isCounting"
@click="handleCaptcha"
>
<a-input v-model:value="formModel.code" :placeholder="t('page.login.common.codePlaceholder')"
style="width: 200px" />
<a-button type="primary" :loading="loading" :disabled="isCounting" @click="handleCaptcha">
{{ label }}
</a-button>
</a-space>
@@ -221,26 +213,20 @@ const handleBack = () => {
</template>
<a-form-item name="password" :label="t('page.login.resetPwd.newPassword')">
<a-input-password
v-model:value="formModel.password"
:placeholder="t('page.login.common.passwordPlaceholder')"
/>
<a-input-password v-model:value="formModel.password"
:placeholder="t('page.login.common.passwordPlaceholder')" />
</a-form-item>
<a-form-item name="confirmPassword" :label="t('page.login.register.confirmPassword')">
<a-input-password
v-model:value="formModel.confirmPassword"
:placeholder="t('page.login.common.confirmPasswordPlaceholder')"
/>
<a-input-password v-model:value="formModel.confirmPassword"
:placeholder="t('page.login.common.confirmPasswordPlaceholder')" />
</a-form-item>
<a-form-item
:wrapper-col="{
xs: { span: 24, offset: 0 },
sm: { span: 16, offset: 8 },
md: { span: 18, offset: 6 }
}"
>
<a-form-item :wrapper-col="{
xs: { span: 24, offset: 0 },
sm: { span: 16, offset: 8 },
md: { span: 18, offset: 6 }
}">
<a-button type="primary" block @click="handleSubmit">
{{ t('common.confirm') }}
</a-button>
@@ -268,7 +254,8 @@ const handleBack = () => {
}
:deep(.ant-form-item-label) {
white-space: normal; /* 允许标签文字换行 */
white-space: normal;
/* 允许标签文字换行 */
height: auto;
line-height: 1.5;
padding-bottom: 8px;