feat: 用户密码重置
This commit is contained in:
parent
ada055a484
commit
3694d27232
101
apps/web-antd/src/views/system/user/user-reset-pwd-modal.vue
Normal file
101
apps/web-antd/src/views/system/user/user-reset-pwd-modal.vue
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { Recordable } from '@vben/types';
|
||||||
|
|
||||||
|
import { useVbenModal, z } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter';
|
||||||
|
import { userResetPassword } from '#/api/system/user';
|
||||||
|
import { Description, useDescription } from '#/components/description';
|
||||||
|
|
||||||
|
const emit = defineEmits<{ reload: [] }>();
|
||||||
|
|
||||||
|
const [BasicModal, modalApi] = useVbenModal({
|
||||||
|
onCancel: handleCancel,
|
||||||
|
onConfirm: handleSubmit,
|
||||||
|
onOpenChange: handleOpenChange,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerDescription, { setDescProps }] = useDescription({
|
||||||
|
column: 1,
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
field: 'userId',
|
||||||
|
label: '用户ID',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'userName',
|
||||||
|
label: '用户名',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'nickName',
|
||||||
|
label: '昵称',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const [BasicForm, formApi] = useVbenForm({
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
show: () => false,
|
||||||
|
triggerFields: [''],
|
||||||
|
},
|
||||||
|
fieldName: 'userId',
|
||||||
|
label: '用户ID',
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'StrengthMeter',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入新的密码, 密码长度为5 - 20',
|
||||||
|
},
|
||||||
|
fieldName: 'password',
|
||||||
|
label: '新的密码',
|
||||||
|
rules: z
|
||||||
|
.string()
|
||||||
|
.min(5, { message: '密码长度为5 - 20' })
|
||||||
|
.max(20, { message: '密码长度为5 - 20' }),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleOpenChange(open: boolean) {
|
||||||
|
if (!open) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { record } = modalApi.getData() as { record: Recordable<any> };
|
||||||
|
setDescProps({ data: record }, true);
|
||||||
|
await formApi.setValues({ userId: record.userId });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
modalApi.modalLoading(true);
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = formApi.getValues();
|
||||||
|
await userResetPassword(data as any);
|
||||||
|
emit('reload');
|
||||||
|
handleCancel();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
modalApi.modalLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleCancel() {
|
||||||
|
modalApi.close();
|
||||||
|
await formApi.resetForm();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BasicModal :close-on-click-modal="false" title="重置密码">
|
||||||
|
<Description @register="registerDescription" />
|
||||||
|
<BasicForm />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user