Blame view

antis-ncc-admin/src/views/permission/user/ResetPassword.vue 3.58 KB
03207d5d   wwk   1
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  <template>
    <el-dialog :title="$t(`user.resetPassword`)" :close-on-click-modal="false"
      :close-on-press-escape="false" :visible.sync="visible" lock-scroll
      class="NCC-dialog NCC-dialog_center" width="600px">
      <el-form ref="dataForm" v-loading="formLoading" :model="dataForm" :rules="dataRule"
        label-width="100px">
        <el-form-item label="账户" prop="account">
          <el-input v-model="dataForm.account" placeholder="账户" readonly />
        </el-form-item>
        <el-form-item label="新密码" prop="userPassword">
          <el-input v-model="dataForm.userPassword" type="password" autocomplete="off"
            placeholder="输入新密码" />
        </el-form-item>
        <el-form-item label="确认新密码" prop="validatePassword">
          <el-input v-model="dataForm.validatePassword" type="password" autocomplete="off"
            placeholder="确认新密码" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{$t('common.cancelButton')}}</el-button>
        <el-button type="primary" :loading="btnLoading" @click="dataFormSubmit()">
          {{$t('common.confirmButton')}}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import {
    resetUserPassword
  } from '@/api/permission/user'
  import md5 from 'js-md5'
  
  export default {
    data() {
      const validateUserPassword = (rule, value, callback) => {
        if (!value) {
          callback(new Error('请输入新密码'));
        } else if (value.toString().length < 6 || value.toString().length > 18) {
          callback(new Error('密码长度为6 - 18个字符'))
        } else {
          if (this.dataForm.userPassword !== '') {
            this.$refs.dataForm.validateField('validatePassword');
          }
          callback()
        }
      }
      const validatePassword = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入新密码'));
        } else if (value !== this.dataForm.userPassword) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      }
      return {
        visible: false,
        formLoading: false,
        btnLoading: false,
        dataForm: {
          id: '',
          account: '',
          userPassword: '',
          validatePassword: ''
        },
        dataRule: {
          userPassword: [
            { required: true, validator: validateUserPassword, trigger: 'blur' }
          ],
          validatePassword: [
            { required: true, validator: validatePassword, trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init(id, account) {
        this.visible = true
        this.formLoading = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          this.dataForm.id = id
          this.dataForm.account = account
          this.formLoading = false
        })
      },
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.btnLoading = true
            const formData = {
              id: this.dataForm.id,
              userPassword: md5(this.dataForm.userPassword),
              validatePassword: md5(this.dataForm.validatePassword)
            }
            resetUserPassword(formData).then(res => {
              this.$message({
                message: res.msg,
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.btnLoading = false
                  this.$emit('refreshDataList')
                }
              })
            }).catch(() => {
              this.btnLoading = false
            })
          }
        })
      }
    }
  }
  </script>