Ben Lin
2024-06-27 226ad601bb8326814c3e94efd6f476014f6a9e66
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
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
    <PageWrapper title="修改当前用户密码" content="修改成功后会自动退出当前登录!">
      <div class="py-8 bg-white flex flex-col justify-center items-center">
        <BasicForm @register="register" />
        <!-- <div class="flex justify-center">
          <a-button @click="resetFields"> 重置 </a-button>
          <a-button class="!ml-4" type="primary" @click="handleSubmit"> 确认 </a-button>
        </div> -->
      </div>
    </PageWrapper>
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, computed, reactive } from 'vue';
  // import { useRoute } from 'vue-router';
  import { PageWrapper } from '/@/components/Page';
  import { BasicForm, useForm } from '/@/components/Form';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { useUserStore } from '/@/store/modules/user';
 
  import { formSchema } from './pwd.data';
  import { getUser, SaveUser } from '/@/api/tigerapi/account';
  import { AccountListItem } from '/@/api/tigerapi/model/systemModel';
  export default defineComponent({
    name: 'ChangePassword',
    components: { BasicForm, BasicModal, PageWrapper },
    emits: ['success', 'register'],
    setup(_, { emit }) {
      const userStore = useUserStore();
      const [register, { validate, resetFields, setFieldsValue }] = useForm({
        size: 'large',
        labelWidth: 100,
        showActionButtonGroup: false,
        schemas: formSchema,
      });
 
      const userInfo: AccountListItem[] = reactive([]);
 
      const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
        resetFields();
        setModalProps({ confirmLoading: false });
        //获取密码api
        getUser(data.passwordOld).then((action) => {
          if (action.IsSuccessed) {
            userInfo.values[0] = action.Data[0];
            setFieldsValue({
              passwordOld: action.Data[0].USER_PWD,
            });
          }
        });
      });
 
      const getTitle = computed(() => '修改密码');
 
      async function handleSubmit() {
        try {
          const values = await validate();
          const { passwordOld, passwordNew } = values;
          userInfo.values[0].USER_PWD = passwordNew;
          // TODO custom api
          console.log(passwordOld, passwordNew);
          SaveUser(userInfo.values[0], true).then((action) => {
            if (action.IsSuccessed) {
              closeModal();
              emit('success');
              userStore.confirmLoginOut(); //登出系统注销用户
            }
          });
        } catch (error) {}
      }
 
      return { register, registerModal, resetFields, getTitle, handleSubmit, closeModal };
    },
  });
</script>