ny
22 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<script lang="ts" setup>
import { ref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicForm, useForm } from '@jnpf/ui/form';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { encryptByMd5 } from '@jnpf/utils';
 
import { resetUserPassword } from '#/api/permission/user';
 
defineEmits(['register']);
const [registerForm, { setFieldsValue, getFieldsValue, resetFields, validate }] = useForm({
  labelWidth: 90,
  schemas: [
    {
      field: 'account',
      label: '账户',
      component: 'Input',
      componentProps: {
        readonly: true,
      },
    },
    {
      field: 'userPassword',
      label: '新密码',
      component: 'Input',
      componentProps: {
        type: 'password',
      },
      rules: [
        {
          required: true,
          trigger: 'blur',
          validator: (_rule, val) => {
            if (!val) return Promise.reject(new Error('请输入新密码'));
            if (getFieldsValue().validatePassword !== '') validate(['validatePassword']);
            return Promise.resolve();
          },
        },
      ],
    },
    {
      field: 'validatePassword',
      label: '确认新密码',
      component: 'Input',
      componentProps: {
        type: 'password',
      },
      rules: [
        {
          required: true,
          trigger: 'blur',
          validator: async (_rule, val) => {
            if (!val) throw new Error('请再次输入新密码');
            if (val !== getFieldsValue().userPassword) throw new Error('两次输入密码不一致');
          },
        },
      ],
    },
  ],
});
const [registerModal, { changeOkLoading, closeModal }] = useModalInner(init);
const id = ref('');
const { createMessage } = useMessage();
 
function init(data) {
  resetFields();
  id.value = data.id;
  setFieldsValue(data);
}
 
async function handleSubmit() {
  const values = await validate();
  if (!values) return;
  changeOkLoading(true);
  const query = {
    id: id.value,
    userPassword: encryptByMd5(values.userPassword),
    validatePassword: encryptByMd5(values.validatePassword),
  };
  resetUserPassword(query)
    .then((res) => {
      createMessage.success(res.msg);
      changeOkLoading(false);
      closeModal();
    })
    .catch(() => {
      changeOkLoading(false);
    });
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="重置密码" @ok="handleSubmit">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>