fix: 修复强制重置密码流程与表单状态

- 修正强制改密跳转及免旧密码的服务端校验

- 统一双端表单错误布局与更新按钮加载状态

- 补充认证服务和强制改密路由测试
This commit is contained in:
2026-07-30 15:03:53 +08:00
parent 03f45212ef
commit 1b40829135
20 changed files with 535 additions and 117 deletions

View File

@@ -1,44 +1,34 @@
<script setup lang="ts">
import type {EasyFlowFormSchema} from '#/adapter/form';
import type { EasyFlowFormSchema } from '#/adapter/form';
import {computed, ref} from 'vue';
import {useRoute, useRouter} from 'vue-router';
import { computed, ref } from 'vue';
import { useRouter } from 'vue-router';
import {ProfilePasswordSetting, z} from '@easyflow/common-ui';
import {preferences} from '@easyflow/preferences';
import {useUserStore} from '@easyflow/stores';
import { ProfilePasswordSetting, z } from '@easyflow/common-ui';
import { preferences } from '@easyflow/preferences';
import { useUserStore } from '@easyflow/stores';
import {ElMessage} from 'element-plus';
import { ElMessage } from 'element-plus';
import {getCredentialKeyApi} from '#/api';
import {api} from '#/api/request';
import {$t} from '#/locales';
import {useAuthStore} from '#/store';
import {encryptCredentialPayload} from '#/utils/credential-encryption';
import {isStrongPassword} from '#/utils/password-policy';
import { getCredentialKeyApi } from '#/api';
import { api } from '#/api/request';
import { $t } from '#/locales';
import { useAuthStore } from '#/store';
import { encryptCredentialPayload } from '#/utils/credential-encryption';
import { isStrongPassword } from '#/utils/password-policy';
import { isPasswordResetRequired } from '#/utils/password-reset';
const profilePasswordSettingRef = ref();
const authStore = useAuthStore();
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
const isForcedPasswordChange = computed(() => {
return (
!!userStore.userInfo?.passwordResetRequired || route.query.force === '1'
);
return isPasswordResetRequired(userStore.userInfo);
});
const formSchema = computed((): EasyFlowFormSchema[] => {
return [
{
fieldName: 'password',
label: $t('sysAccount.oldPwd'),
component: 'EasyFlowInputPassword',
componentProps: {
placeholder: $t('sysAccount.oldPwd') + $t('common.isRequired'),
},
},
const schema: EasyFlowFormSchema[] = [
{
fieldName: 'newPassword',
label: $t('sysAccount.newPwd'),
@@ -58,7 +48,7 @@ const formSchema = computed((): EasyFlowFormSchema[] => {
})
.min(1, { message: $t('sysAccount.newPwd') + $t('common.isRequired') })
.refine((value) => isStrongPassword(value), {
message: $t('sysAccount.passwordStrongTip'),
message: $t('sysAccount.passwordStrengthInvalid'),
}),
},
{
@@ -83,10 +73,29 @@ const formSchema = computed((): EasyFlowFormSchema[] => {
},
},
];
if (!isForcedPasswordChange.value) {
schema.unshift({
fieldName: 'password',
label: $t('sysAccount.oldPwd'),
component: 'EasyFlowInputPassword',
componentProps: {
placeholder: $t('sysAccount.oldPwd') + $t('common.isRequired'),
},
rules: z
.string({
required_error: $t('sysAccount.oldPwd') + $t('common.isRequired'),
})
.min(1, { message: $t('sysAccount.oldPwd') + $t('common.isRequired') }),
});
}
return schema;
});
const updateLoading = ref(false);
async function handleSubmit(values: any) {
const wasForcedPasswordChange = isForcedPasswordChange.value;
updateLoading.value = true;
try {
const encryptedPayload = await encryptCredentialPayload(
@@ -100,7 +109,7 @@ async function handleSubmit(values: any) {
if (res.errorCode === 0) {
ElMessage.success($t('message.success'));
const userInfo = await authStore.fetchUserInfo();
if (isForcedPasswordChange.value) {
if (wasForcedPasswordChange) {
await router.replace(
userInfo?.homePath || preferences.app.defaultHomePath || '/',
);