main-navbar-update-password.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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" @keyup.enter.native="dataFormSubmit()" 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" class="dialog-footer">
  21. <el-button @click="visible = false">取消</el-button>
  22. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  23. </span>
  24. </el-dialog>
  25. </template>
  26. <script>
  27. import { clearLoginInfo } from '@/utils'
  28. import { Message } from "element-ui"
  29. export default {
  30. data () {
  31. var validateConfirmPassword = (rule, value, callback) => {
  32. if (this.dataForm.newPassword !== value) {
  33. callback(new Error('确认密码与新密码不一致'))
  34. } else {
  35. callback()
  36. }
  37. }
  38. return {
  39. visible: false,
  40. dataForm: {
  41. password: '',
  42. newPassword: '',
  43. confirmPassword: ''
  44. },
  45. dataRule: {
  46. password: [
  47. { required: true, message: '原密码不能为空', trigger: 'blur' }
  48. ],
  49. newPassword: [
  50. { required: true, message: '新密码不能为空', trigger: 'blur' }
  51. ],
  52. confirmPassword: [
  53. { required: true, message: '确认密码不能为空', trigger: 'blur' },
  54. { validator: validateConfirmPassword, trigger: 'blur' }
  55. ]
  56. }
  57. }
  58. },
  59. computed: {
  60. userName: {
  61. get () { return this.$store.state.user.name }
  62. },
  63. mainTabs: {
  64. get () { return this.$store.state.common.mainTabs },
  65. set (val) { this.$store.commit('common/updateMainTabs', val) }
  66. }
  67. },
  68. methods: {
  69. // 初始化
  70. init () {
  71. this.visible = true
  72. this.$nextTick(() => {
  73. this.$refs['dataForm'].resetFields()
  74. })
  75. },
  76. // 表单提交
  77. dataFormSubmit () {
  78. this.$refs['dataForm'].validate((valid) => {
  79. if (valid) {
  80. this.$http({
  81. url: this.$http.adornUrl('/sys/user/password'),
  82. method: 'post',
  83. data: this.$http.adornData({
  84. 'password': this.dataForm.password,
  85. 'newPassword': this.dataForm.newPassword
  86. })
  87. }).then(({data}) => {
  88. if (data && data.code === 0) {
  89. Message({
  90. message: '操作成功',
  91. type: 'success',
  92. duration: 1500,
  93. onClose: () => {
  94. this.visible = false
  95. this.$nextTick(() => {
  96. this.mainTabs = []
  97. clearLoginInfo()
  98. this.$router.replace({ name: 'login' })
  99. })
  100. }
  101. })
  102. } else {
  103. Message.error(data.msg)
  104. }
  105. })
  106. }
  107. })
  108. }
  109. }
  110. }
  111. </script>