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.

123 lines
3.8 KiB

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