ValidationEmailStepNew.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>验证邮箱</p>
  5. </div>
  6. <div class="f-form">
  7. <div class="page-part">
  8. <mt-field placeholder="新邮箱地址"
  9. v-model="valid.email"
  10. :state="state.email"
  11. @blur.native.capture="validateEmail"
  12. ></mt-field>
  13. </div>
  14. <div class="page-part">
  15. <mt-button :disabled="hasSend" size="large"
  16. type="primary"
  17. @click="sureAccount()"
  18. v-text="secretEmail">发送验证请求</mt-button>
  19. </div>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'step-one',
  26. props: ['tokenId'],
  27. data () {
  28. return {
  29. state: {
  30. email: 'error'
  31. },
  32. valid: {
  33. email: ''
  34. },
  35. secretEmail: '发送验证请求',
  36. hasSend: false
  37. }
  38. },
  39. methods: {
  40. // 弹窗处理
  41. downToast (type) {
  42. this.$toast({
  43. message: type,
  44. iconClass: 'el-icon-warning'
  45. })
  46. },
  47. // 验证邮箱号
  48. validateEmail () {
  49. let reg = /^([\w-])+(\.\w+)*@([\w-])+((\.\w{2,3}){1,3})$/
  50. if (!this.valid.email) {
  51. this.downToast('请先填写邮箱号')
  52. this.state.email = 'error'
  53. } else {
  54. if (!reg.test(this.valid.email)) {
  55. this.downToast('请填写正确的邮箱号')
  56. this.state.email = 'warning'
  57. } else {
  58. this.$http.get(`/update/user/email/hasRegister`, {params: {email: this.valid.email}})
  59. .then(response => {
  60. if (response.data.content.hasRegister) {
  61. this.$toast({
  62. message: '该邮箱号已被注册',
  63. iconClass: 'el-icon-error'
  64. })
  65. } else {
  66. this.state.email = 'success'
  67. }
  68. }).catch(() => {
  69. this.$indicator.close()
  70. this.downToast('请检查网络是否正常或联系服务商')
  71. })
  72. }
  73. }
  74. },
  75. sureAccount () {
  76. if (this.state.email !== 'success') {
  77. this.downToast('请确认填写是否有误')
  78. } else {
  79. this.$indicator.open('发送过程中...')
  80. this.$http.get(`/update/user/setEmail`, {params: {email: this.valid.email, token: this.tokenId ? this.tokenId : this.$route.query.token}})
  81. .then(response => {
  82. this.$indicator.close()
  83. if (response.data.success) {
  84. this.hasSend = true
  85. this.secretEmail = '已发送验证邮件,请查收'
  86. } else {
  87. this.hasSend = false
  88. this.downToast(response.data.errMsg)
  89. }
  90. }).catch(() => {
  91. this.$indicator.close()
  92. this.downToast('请检查网络是否正常或联系服务商')
  93. })
  94. }
  95. }
  96. }
  97. }
  98. </script>