stepFirst.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. :state="state.mobile"
  10. @blur.native.capture="validateMobile"
  11. v-model="valid.mobile"></mt-field>
  12. </div>
  13. <div class="page-part">
  14. <mt-field placeholder="验证码"
  15. :state="state.captcha"
  16. auto-complete="off"
  17. @blur.native.capture="validateCode"
  18. v-model="valid.captcha">
  19. <img :src="imgSrc" height="45px" width="100px" @click="getCode">
  20. </mt-field>
  21. </div>
  22. <div class="page-part">
  23. <mt-button size="large" type="primary" @click="sureAccount('select')">下一步</mt-button>
  24. </div>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'step-one',
  31. data () {
  32. return {
  33. state: {
  34. mobile: 'error',
  35. captcha: 'error'
  36. },
  37. valid: {
  38. mobile: '',
  39. captcha: ''
  40. },
  41. imgSrc: ''
  42. }
  43. },
  44. mounted () {
  45. this.$nextTick(() => {
  46. this.getCode()
  47. })
  48. },
  49. methods: {
  50. // 警告弹窗
  51. downToast (type) {
  52. this.$toast({
  53. message: type,
  54. iconClass: 'el-icon-warning'
  55. })
  56. },
  57. // 验证手机号
  58. validateMobile () {
  59. let reg = /^1[0-9]{10}$/
  60. if (!this.valid.mobile) {
  61. this.downToast('请先填写手机号 ')
  62. } else {
  63. if (reg.test(this.valid.mobile)) {
  64. this.state.mobile = 'success'
  65. } else {
  66. this.state.mobile = 'warning'
  67. this.downToast('请填写正确的手机号码')
  68. }
  69. }
  70. },
  71. // 验证码验证
  72. validateCode () {
  73. if (!this.valid.captcha) {
  74. this.downToast('请填写验证码信息')
  75. } else {
  76. this.state.captcha = 'success'
  77. }
  78. },
  79. sureAccount (type) {
  80. if (this.state.mobile !== 'success' && this.state.captcha !== 'success') {
  81. this.downToast('请确认填写部分是否有误')
  82. } else {
  83. this.$indicator.open('验证过程中...')
  84. let param = new FormData()
  85. param.append('mobile', this.valid.mobile)
  86. param.append('captcha', this.valid.captcha)
  87. let config = {
  88. headers: {'Content-Type': 'multipart/form-data'}
  89. }
  90. this.$http.post(`/sso/resetPwd/checkCaptcha`, param, config)
  91. .then(response => {
  92. this.$indicator.close()
  93. if (response.data.success) {
  94. this.$emit('stepEvent', type)
  95. } else {
  96. this.getCode()
  97. this.downToast(response.data.errMsg)
  98. }
  99. }).catch(() => {
  100. this.$indicator.close()
  101. this.downToast('请检查网络是否正常或联系服务商')
  102. })
  103. }
  104. },
  105. getCode () {
  106. this.imgSrc = '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf()
  107. }
  108. }
  109. }
  110. </script>