【前端】智能库房综合管理系统前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.2 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div style="display: inline-block">
  3. <el-dialog :visible.sync="dialog" :close-on-click-modal="false" :before-close="cancel" :title="title" append-to-body @close="cancel">
  4. <span class="dialog-right-top" />
  5. <span class="dialog-left-bottom" />
  6. <div class="setting-dialog">
  7. <el-form ref="form" :model="form" :rules="rules" size="small" label-width="88px">
  8. <el-form-item label="旧密码" prop="oldPass">
  9. <el-input v-model="form.oldPass" type="password" auto-complete="on" style="width: 370px;" />
  10. </el-form-item>
  11. <el-form-item label="新密码" prop="newPass">
  12. <el-input v-model="form.newPass" type="password" auto-complete="on" style="width: 370px;" />
  13. </el-form-item>
  14. <el-form-item label="确认密码" prop="confirmPass">
  15. <el-input v-model="form.confirmPass" type="password" auto-complete="on" style="width: 370px;" />
  16. </el-form-item>
  17. </el-form>
  18. <div slot="footer" class="dialog-footer">
  19. <el-button type="text" @click="cancel">取消</el-button>
  20. <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
  21. </div>
  22. </div>
  23. </el-dialog>
  24. </div>
  25. </template>
  26. <script>
  27. import store from '@/store'
  28. import { updatePass } from '@/api/system/user'
  29. export default {
  30. data() {
  31. const confirmPass = (rule, value, callback) => {
  32. if (value) {
  33. if (this.form.newPass !== value) {
  34. callback(new Error('两次输入的密码不一致'))
  35. } else {
  36. callback()
  37. }
  38. } else {
  39. callback(new Error('请再次输入密码'))
  40. }
  41. }
  42. return {
  43. loading: false, dialog: false, title: '修改密码', form: { oldPass: '', newPass: '', confirmPass: '' },
  44. rules: {
  45. oldPass: [
  46. { required: true, message: '请输入旧密码', trigger: 'blur' }
  47. ],
  48. newPass: [
  49. { required: true, message: '请输入新密码', trigger: 'blur' },
  50. { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
  51. ],
  52. confirmPass: [
  53. { required: true, validator: confirmPass, trigger: 'blur' }
  54. ]
  55. }
  56. }
  57. },
  58. methods: {
  59. cancel() {
  60. this.resetForm()
  61. },
  62. doSubmit() {
  63. this.$refs['form'].validate((valid) => {
  64. if (valid) {
  65. this.loading = true
  66. updatePass(this.form).then(res => {
  67. this.resetForm()
  68. this.$message({
  69. message: '密码修改成功,请重新登录',
  70. type: 'success',
  71. duration: 1500
  72. })
  73. setTimeout(() => {
  74. store.dispatch('LogOut').then(() => {
  75. location.reload() // 为了重新实例化vue-router对象 避免bug
  76. })
  77. }, 1500)
  78. }).catch(err => {
  79. this.loading = false
  80. console.log(err.response.data.message)
  81. })
  82. } else {
  83. return false
  84. }
  85. })
  86. },
  87. resetForm() {
  88. this.dialog = false
  89. this.$refs['form'].resetFields()
  90. this.form = { oldPass: '', newPass: '', confirmPass: '' }
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. </style>