main-navbar-update-password.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <el-dialog
  3. title="修改密码"
  4. :visible.sync="visible"
  5. :append-to-body="true">
  6. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
  7. <el-form-item label="账号">
  8. <span>{{ userName }}</span>
  9. </el-form-item>
  10. <el-form-item label="原密码" prop="password">
  11. <el-input type="password" v-model="dataForm.password"></el-input>
  12. </el-form-item>
  13. <el-form-item label="新密码" prop="newPassword">
  14. <el-input type="password" v-model="dataForm.newPassword"></el-input>
  15. </el-form-item>
  16. <el-form-item label="确认密码" prop="confirmPassword">
  17. <el-input type="password" v-model="dataForm.confirmPassword"></el-input>
  18. </el-form-item>
  19. </el-form>
  20. <span slot="footer">
  21. <el-button @click="visible = false">取消</el-button>
  22. <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  23. </span>
  24. </el-dialog>
  25. </template>
  26. <script>
  27. import { clearLoginInfo } from '@/utils'
  28. export default {
  29. data () {
  30. const validateConfirmPassword = (rule, value, callback) => {
  31. if (this.dataForm.newPassword !== value) {
  32. callback(new Error('确认密码与新密码不一致'))
  33. } else {
  34. callback()
  35. }
  36. }
  37. return {
  38. visible: false,
  39. dataForm: {
  40. password: '',
  41. newPassword: '',
  42. confirmPassword: ''
  43. },
  44. dataRule: {
  45. password: [
  46. { required: true, message: '原密码不能为空', trigger: 'blur' }
  47. ],
  48. newPassword: [
  49. { required: true, message: '新密码不能为空', trigger: 'blur' }
  50. ],
  51. confirmPassword: [
  52. { required: true, message: '确认密码不能为空', trigger: 'blur' },
  53. { validator: validateConfirmPassword, trigger: 'blur' }
  54. ]
  55. }
  56. }
  57. },
  58. computed: {
  59. userName: {
  60. get () { return this.$store.state.user.name }
  61. },
  62. mainTabs: {
  63. get () { return this.$store.state.common.mainTabs },
  64. set (val) { this.$store.commit('common/updateMainTabs', val) }
  65. }
  66. },
  67. methods: {
  68. // 初始化
  69. init () {
  70. this.visible = true
  71. this.$nextTick(() => {
  72. this.$refs['dataForm'].resetFields()
  73. })
  74. },
  75. // 表单提交
  76. dataFormSubmit () {
  77. this.$refs['dataForm'].validate((valid) => {
  78. if (valid) {
  79. this.$http({
  80. url: this.$http.adornUrl('/user-service/user/password'),
  81. method: 'post',
  82. data: this.$http.adornData({
  83. 'password': this.dataForm.password,
  84. 'newPassword': this.dataForm.newPassword
  85. })
  86. }).then(({data}) => {
  87. if (data && data.code === '200') {
  88. this.$message({
  89. message: '操作成功',
  90. type: 'success',
  91. duration: 1500,
  92. onClose: () => {
  93. this.visible = false
  94. this.$nextTick(() => {
  95. this.mainTabs = []
  96. clearLoginInfo()
  97. this.$router.replace({ name: 'login' })
  98. })
  99. }
  100. })
  101. } else {
  102. this.$message.error(data.msg)
  103. }
  104. })
  105. }
  106. })
  107. }
  108. }
  109. }
  110. </script>