Rap 原分销系统代码Web
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

138 lines
4.4KB

  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="475px" @close="cancel">
  4. <el-form ref="form" :model="form" :rules="rules" size="small" label-width="88px">
  5. <el-form-item label="新邮箱" prop="email">
  6. <el-input v-model="form.email" auto-complete="on" style="width: 200px;" />
  7. <el-button :loading="codeLoading" :disabled="isDisabled" size="small" @click="sendCode">{{ buttonName }}</el-button>
  8. </el-form-item>
  9. <el-form-item label="验证码" prop="code">
  10. <el-input v-model="form.code" style="width: 320px;" />
  11. </el-form-item>
  12. <el-form-item label="当前密码" prop="pass">
  13. <el-input v-model="form.pass" type="password" style="width: 320px;" />
  14. </el-form-item>
  15. </el-form>
  16. <div slot="footer" class="dialog-footer">
  17. <el-button type="text" @click="cancel">取消</el-button>
  18. <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
  19. </div>
  20. </el-dialog>
  21. </div>
  22. </template>
  23. <script>
  24. import store from '@/store'
  25. import { validEmail } from '@/utils/validate'
  26. import { updateEmail } from '@/api/system/user'
  27. import { resetEmail } from '@/api/system/code'
  28. export default {
  29. props: {
  30. email: {
  31. type: String,
  32. required: true
  33. }
  34. },
  35. data() {
  36. const validMail = (rule, value, callback) => {
  37. if (value === '' || value === null) {
  38. callback(new Error('新邮箱不能为空'))
  39. } else if (value === this.email) {
  40. callback(new Error('新邮箱不能与旧邮箱相同'))
  41. } else if (validEmail(value)) {
  42. callback()
  43. } else {
  44. callback(new Error('邮箱格式错误'))
  45. }
  46. }
  47. return {
  48. loading: false, dialog: false, title: '修改邮箱', form: { pass: '', email: '', code: '' },
  49. user: { email: '', password: '' }, codeLoading: false,
  50. buttonName: '获取验证码', isDisabled: false, time: 60,
  51. rules: {
  52. pass: [
  53. { required: true, message: '当前密码不能为空', trigger: 'blur' }
  54. ],
  55. email: [
  56. { required: true, validator: validMail, trigger: 'blur' }
  57. ],
  58. code: [
  59. { required: true, message: '验证码不能为空', trigger: 'blur' }
  60. ]
  61. }
  62. }
  63. },
  64. methods: {
  65. cancel() {
  66. this.resetForm()
  67. },
  68. sendCode() {
  69. if (this.form.email && this.form.email !== this.email) {
  70. this.codeLoading = true
  71. this.buttonName = '验证码发送中'
  72. const _this = this
  73. resetEmail(this.form.email).then(res => {
  74. this.$message({
  75. showClose: true,
  76. message: '发送成功,验证码有效期5分钟',
  77. type: 'success'
  78. })
  79. this.codeLoading = false
  80. this.isDisabled = true
  81. this.buttonName = this.time-- + '秒后重新发送'
  82. this.timer = window.setInterval(function() {
  83. _this.buttonName = _this.time + '秒后重新发送'
  84. --_this.time
  85. if (_this.time < 0) {
  86. _this.buttonName = '重新发送'
  87. _this.time = 60
  88. _this.isDisabled = false
  89. window.clearInterval(_this.timer)
  90. }
  91. }, 1000)
  92. }).catch(err => {
  93. this.resetForm()
  94. this.codeLoading = false
  95. console.log(err.response.data.message)
  96. })
  97. }
  98. },
  99. doSubmit() {
  100. this.$refs['form'].validate((valid) => {
  101. if (valid) {
  102. this.loading = true
  103. updateEmail(this.form).then(res => {
  104. this.loading = false
  105. this.resetForm()
  106. this.$notify({
  107. title: '邮箱修改成功',
  108. type: 'success',
  109. duration: 1500
  110. })
  111. store.dispatch('GetInfo').then(() => {})
  112. }).catch(err => {
  113. this.loading = false
  114. console.log(err.response.data.message)
  115. })
  116. } else {
  117. return false
  118. }
  119. })
  120. },
  121. resetForm() {
  122. this.dialog = false
  123. this.$refs['form'].resetFields()
  124. window.clearInterval(this.timer)
  125. this.time = 60
  126. this.buttonName = '获取验证码'
  127. this.isDisabled = false
  128. this.form = { pass: '', email: '', code: '' }
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped>
  134. </style>