reset-password.vue 5.19 KB
Newer Older
葛齐林's avatar
葛齐林 committed
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
<template lang="pug">
el-dialog( :visible.sync="visible" :append-to-body="true" :before-close="handleClose" )
    .title-bold(slot='title') 密码重置
    el-form( :model="dataForm" :rules="dataRule" ref="dataForm" :label-position="labelPosition" label-width="150px" )
        el-row(justify="center" style="width:70%;margin:0 auto;")
            el-col(:span="24")
                el-form-item(label="所属站点:" prop="name")
                    el-input.mywidth(readonly v-model="dataForm.name" placeholder="所属站点")
            el-col(:span="24")
                el-form-item(label="用户账号:" prop="username")
                    el-input.mywidth(readonly v-model="dataForm.username" placeholder="用户账号")
            el-col(:span="24")
                el-form-item(label="请输入密码:" prop="password")
                    el-input.mywidth( v-model="dataForm.password" type="password" placeholder="请输入密码" clearable @input='e => dataForm.password = inputMe(e)')
            el-col(:span="24")
                el-form-item(label="请再次输入密码:" prop="comfirmPassword")
                    el-input.mywidth( v-model="dataForm.comfirmPassword" type="password" placeholder="请再次输入密码" clearable @input='e => dataForm.comfirmPassword = inputMe(e)')
    div(slot='footer' align='center')
        el-button(size="medium" type="primary" @click="cancel") 取消
        el-button(size="medium" type="primary" @click="submit" v-prevent-re-click) 保存
</template>
<script>
export default {
  data() {
    var validatePassword = (rule, value, callback) => {
      if (!value) {
        callback(new Error('密码不能为空'))
      } else {
        callback()
      }
    }
    var validateComfirmPassword = (rule, value, callback) => {
      if (!value) {
        callback(new Error('确认密码不能为空'))
      } else if (this.dataForm.password !== value) {
        callback(new Error('两次输入的密码不一致'))
      } else {
        callback()
      }
    }
    return {
      clickFlag: false,
      id: 1,
      dataListLoading: false,
      visible: false,
      labelPosition: 'right',
      dataForm: {
        username: '',
        name: '',
        code: '',
        password: '',
        comfirmPassword: ''
      },
      item: {},
      dataRule: {
        password: [
          { validator: validatePassword, required: true, trigger: 'blur' },
          {
            min: 1,
            max: 30,
            message: '长度在 1 到 50 个字符',
            trigger: 'blur'
          }
        ],
        comfirmPassword: [
          {
            validator: validateComfirmPassword,
            required: true,
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    init(row) {
      this.visible = true
      this.clickFlag = false
      this.dataForm.userId = row.user_id
      this.dataForm.username = row.username
      this.initData()
    },
    inputMe(e) {
      return e.replace(/[<>!?:":?@!,.;']/g, '')
    },
    initData() {
      this.$http({
        url: this.$http.adornUrl(`/sysSystem/getId/${this.id}`),
        method: 'get',
        params: this.$http.adornParams()
      })
        .then((data) => {
          // console.log(data, '---')
          if (data && data.code === 0) {
            let item = data.bean
            this.dataForm.name = item.name
            this.dataForm.code = item.code
            // this.dataForm.username = item.code + ' - ' + this.dataForm.username
          }
        })
        .catch((data) => {
          this.$message({
            type: 'error',
            message: data.mag,
            duration: 1500
          })
        })
    },
    submit() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.clickFlag = true
          this.$http({
            url: this.$http.adornUrl(`/sys/user/updatePassword`),
            method: 'post',
            params: {
              userIds: this.dataForm.userId,
              password: this.dataForm.password
            }
          })
            .then((data) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500
                })
              }
              this.handleClose()
              this.$emit('refreshdatalist')
              this.clickFlag = false
            })
            .catch((data) => {
              this.$message.error(data.msg)
              this.clickFlag = false
            })
        }
      })
    },
    handleClose() {
        this.visible = false
        this.$refs.dataForm.resetFields()
    },
    //取消
    cancel() {
      this.$confirm('确认取消?', '密码重置', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.handleClose()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出'
          })
        })
    }
  }
}
</script>
<style>
</style>