Blame view

ant-design-vue-jeecg/src/components/tools/UserPassword.vue 4.03 KB
肖超群 authored
1
2
3
4
5
6
7
8
<template>
  <a-modal
    :title="title"
    :width="modalWidth"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
谭毅彬 authored
9
    :cancelText="$t('button.close')"
肖超群 authored
10
11
12
13
14
15
16
17
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="旧密码">
肖超群 authored
18
          <a-input type="password" placeholder="请输入旧密码" v-decorator="[ 'oldpassword', validatorRules.oldpassword]"/>
肖超群 authored
19
20
21
22
23
24
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="新密码">
肖超群 authored
25
          <a-input type="password" placeholder="请输入新密码" v-decorator="[ 'password', validatorRules.password]"/>
肖超群 authored
26
27
28
29
30
31
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="确认新密码">
肖超群 authored
32
33
          <a-input type="password" @blur="handleConfirmBlur" placeholder="请确认新密码"
                   v-decorator="[ 'confirmpassword', validatorRules.confirmpassword]"/>
肖超群 authored
34
35
36
37
38
39
40
41
42
        </a-form-item>

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

<script>
肖超群 authored
43
import {putAction} from '@/api/manage'
44
import { translateResultMessage } from '@/api/api'
肖超群 authored
45
肖超群 authored
46
47
48
49
50
51
52
53
54
55
56
57
58
export default {
  name: "UserPassword",
  data() {
    return {
      title: "修改密码",
      modalWidth: 800,
      visible: false,
      confirmLoading: false,
      validatorRules: {
        oldpassword: {
          rules: [{
            required: true, message: '请输入旧密码!',
          }],
肖超群 authored
59
        },
肖超群 authored
60
61
62
63
64
65
        password: {
          rules: [{
            required: true, message: '请输入新密码!',
          }, {
            validator: this.validateToNextPassword,
          }],
肖超群 authored
66
        },
肖超群 authored
67
68
69
70
71
72
        confirmpassword: {
          rules: [{
            required: true, message: '请确认新密码!',
          }, {
            validator: this.compareToFirstPassword,
          }],
肖超群 authored
73
74
        }
      },
肖超群 authored
75
76
77
78
      confirmDirty: false,
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
肖超群 authored
79
      },
肖超群 authored
80
81
82
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
肖超群 authored
83
      },
肖超群 authored
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

      form: this.$form.createForm(this),
      url: "sys/user/updatePassword",
      username: "",
    }
  },
  methods: {
    show(uname) {
      if (!uname) {
        this.$message.warning("当前系统无登录用户!");
        return
      } else {
        this.username = uname
        this.form.resetFields();
        this.visible = true;
      }
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.disableSubmit = false;
      this.selectedRole = [];
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let params = Object.assign({username: this.username}, values)
          console.log("修改密码提交数据", params)
          putAction(this.url, params).then((res) => {
            if (res.success) {
              console.log(res)
121
              that.$message.success(translateResultMessage(res, res.message))
肖超群 authored
122
123
              that.close();
            } else {
124
              that.$message.warning(translateResultMessage(res, res.message))
肖超群 authored
125
126
127
128
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
肖超群 authored
129
        }
肖超群 authored
130
131
132
133
134
135
      })
    },
    validateToNextPassword(rule, value, callback) {
      const form = this.form;
      if (value && this.confirmDirty) {
        form.validateFields(['confirm'], {force: true})
肖超群 authored
136
      }
肖超群 authored
137
138
139
140
141
142
143
144
145
146
147
148
149
      callback();
    },
    compareToFirstPassword(rule, value, callback) {
      const form = this.form;
      if (value && value !== form.getFieldValue('password')) {
        callback('两次输入的密码不一样!');
      } else {
        callback()
      }
    },
    handleConfirmBlur(e) {
      const value = e.target.value
      this.confirmDirty = this.confirmDirty || !!value
肖超群 authored
150
    }
肖超群 authored
151
肖超群 authored
152
  }
肖超群 authored
153
}
肖超群 authored
154
155
156
157
158
159
</script>

<style scoped>

</style>