Blame view

ant-design-vue-jeecg/src/views/system/modules/PasswordModal.vue 4 KB
肖超群 authored
1
2
<template>
  <a-modal
曾湘平 authored
3
    :title="$t('system.resetPassword')"
肖超群 authored
4
5
6
7
8
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
谭毅彬 authored
9
    :cancelText="$t('button.close')"
肖超群 authored
10
11
12
13
14
    style="top:20px;"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
曾湘平 authored
15
        <a-form-item :label="$t('system.userAccount')" :labelCol="labelCol" :wrapperCol="wrapperCol">
曾湘平 authored
16
          <a-input :placeholder="$t('system.enterUserAccount')" v-decorator="[ 'username', {}]" :readOnly="true"/>
肖超群 authored
17
18
        </a-form-item>
曾湘平 authored
19
20
        <a-form-item :label="$t('system.loginPassword')" :labelCol="labelCol" :wrapperCol="wrapperCol" hasFeedback>
          <a-input type="password" :placeholder="$t('system.enterLoginPassword')" v-decorator="[ 'password', validatorRules.password]"/>
肖超群 authored
21
22
        </a-form-item>
曾湘平 authored
23
24
        <a-form-item :label="$t('system.confirmPassword')" :labelCol="labelCol" :wrapperCol="wrapperCol" hasFeedback>
          <a-input type="password" @blur="handleConfirmBlur" :placeholder="$t('system.pleaseProvideLoginPasswordAgain')"
肖超群 authored
25
                   v-decorator="[ 'confirmpassword', validatorRules.confirmpassword]"/>
肖超群 authored
26
27
28
29
30
31
32
33
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
肖超群 authored
34
import {changePassword} from '@/api/api'
35
import { translateResultMessage } from '@/api/api'
肖超群 authored
36
肖超群 authored
37
38
39
40
41
42
43
44
45
46
47
48
export default {
  name: "PasswordModal",
  data() {
    return {
      visible: false,
      confirmLoading: false,
      confirmDirty: false,
      validatorRules: {
        password: {
          rules: [{
            validator: this.validateToNextPassword,
          }],
肖超群 authored
49
        },
肖超群 authored
50
51
        confirmpassword: {
          rules: [{
曾湘平 authored
52
            required: true, message: this.$t('system.pleaseProvideLoginPasswordAgain'),
肖超群 authored
53
54
55
          }, {
            validator: this.compareToFirstPassword,
          }],
肖超群 authored
56
57
        },
      },
肖超群 authored
58
59
60
61
62
63

      model: {},

      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
肖超群 authored
64
      },
肖超群 authored
65
66
67
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
肖超群 authored
68
      },
肖超群 authored
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
97
98
      form: this.$form.createForm(this)
    }
  },
  created() {
    console.log("created");
  },

  methods: {
    show(username) {
      this.form.resetFields();
      this.visible = true;
      this.model.username = username;
      this.$nextTick(() => {
        this.form.setFieldsValue({username: username});
      });
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.disableSubmit = false;
      this.selectedRole = [];
    },
    handleSubmit() {
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          this.confirmLoading = true;
          let formData = Object.assign(this.model, values);
          changePassword(formData).then((res) => {
            if (res.success) {
99
              this.$message.success(translateResultMessage(res, res.message))
肖超群 authored
100
101
              this.$emit('ok');
            } else {
102
              this.$message.warning(translateResultMessage(res, res.message))
肖超群 authored
103
104
105
106
107
            }
          }).finally(() => {
            this.confirmLoading = false;
            this.close();
          });
肖超群 authored
108
        }
肖超群 authored
109
110
111
112
113
114
115
116
117
118
      })
    },
    handleCancel() {
      this.close()
    },
    validateToNextPassword(rule, value, callback) {
      const form = this.form;
      const confirmpassword = form.getFieldValue('confirmpassword');
      console.log("confirmpassword==>", confirmpassword);
      if (value && confirmpassword && value !== confirmpassword) {
曾湘平 authored
119
        callback(this.$t('system.thePasswordsEnteredDoNotMatch'));
肖超群 authored
120
121
122
      }
      if (value && this.confirmDirty) {
        form.validateFields(['confirm'], {force: true})
肖超群 authored
123
      }
肖超群 authored
124
125
126
127
128
      callback();
    },
    compareToFirstPassword(rule, value, callback) {
      const form = this.form;
      if (value && value !== form.getFieldValue('password')) {
曾湘平 authored
129
        callback(this.$t('system.thePasswordsEnteredDoNotMatch'));
肖超群 authored
130
131
132
133
134
135
136
      } else {
        callback()
      }
    },
    handleConfirmBlur(e) {
      const value = e.target.value
      this.confirmDirty = this.confirmDirty || !!value
肖超群 authored
137
138
    }
  }
肖超群 authored
139
}
肖超群 authored
140
</script>