声脉桥梁云监控平台

updateLoginPwd.vue 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <el-dialog title="修改登录密码" :visible.sync="dialogTableVisible" width="460px">
  3. <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" class="demo-ruleForm">
  4. <el-form-item prop="pass">
  5. <el-input type="password" v-model="ruleForm2.pass" placeholder="请设置您的新密码" auto-complete="off"></el-input>
  6. </el-form-item>
  7. <el-form-item prop="checkPass">
  8. <el-input type="password" v-model="ruleForm2.checkPass" placeholder="请再次输入密码确认" auto-complete="off"></el-input>
  9. </el-form-item>
  10. <el-form-item class="el-btn-col">
  11. <div class="el-btn-col-box">
  12. <el-button type="primary" @click.native.prevent="resetPwd('ruleForm2')">确定</el-button>
  13. </div>
  14. </el-form-item>
  15. </el-form>
  16. </el-dialog>
  17. </template>
  18. <script>
  19. import { changePw } from '@/api/login'
  20. import { MessageBox } from 'element-ui'
  21. export default {
  22. data() {
  23. var validatePass = (rule, value, callback) => {
  24. if (value === '') {
  25. callback(new Error('请设置您的新密码'))
  26. } else if (value.length < 6 || value.length > 24) {
  27. callback(new Error('密码由6-24个字符组成,区分大小写'))
  28. } else {
  29. if (this.ruleForm2.checkPass !== '') {
  30. this.$refs.ruleForm2.validateField('checkPass')
  31. }
  32. callback()
  33. }
  34. }
  35. var validatePass2 = (rule, value, callback) => {
  36. if (value === '') {
  37. callback(new Error('请再次输入密码确认'))
  38. } else if (value !== this.ruleForm2.pass) {
  39. callback(new Error('两次输入密码不一致,请重新输入!'))
  40. } else {
  41. callback()
  42. }
  43. }
  44. return {
  45. dialogTableVisible: false,
  46. ruleForm2: {
  47. pass: '',
  48. checkPass: ''
  49. },
  50. rules2: {
  51. pass: [
  52. { required: true, validator: validatePass, trigger: 'blur' }
  53. ],
  54. checkPass: [
  55. { required: true, validator: validatePass2, trigger: 'blur' }
  56. ]
  57. }
  58. }
  59. },
  60. methods: {
  61. resetPwd(formName) {
  62. this.$refs[formName].validate((valid) => {
  63. if (valid) {
  64. const newPw = this.ruleForm2.checkPass
  65. changePw({ newPw }).then((res) => {
  66. if (res.success) {
  67. MessageBox.alert('密码修改成功!', '提示', {
  68. confirmButtonText: '确定',
  69. type: 'success',
  70. center: true,
  71. callback: action => {
  72. if (action === 'confirm') {
  73. this.dialogTableVisible = false
  74. this.$refs[formName].resetFields()
  75. }
  76. }
  77. })
  78. }
  79. })
  80. } else {
  81. return false
  82. }
  83. })
  84. }
  85. }
  86. }
  87. </script>