Rap 原分销系统代码Web
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

96 行
3.0KB

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