stepFirst.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. this.state.mobile = 'error'
  63. } else {
  64. if (reg.test(this.valid.mobile)) {
  65. this.state.mobile = 'success'
  66. } else {
  67. this.state.mobile = 'warning'
  68. this.downToast('请填写正确的手机号码')
  69. }
  70. }
  71. },
  72. // 验证码验证
  73. validateCode () {
  74. if (!this.valid.captcha) {
  75. this.downToast('请填写验证码信息')
  76. this.state.captcha = 'error'
  77. } else {
  78. this.state.captcha = 'success'
  79. }
  80. },
  81. sureAccount (type) {
  82. if (this.state.mobile !== 'success' || this.state.captcha !== 'success') {
  83. this.downToast('请确认填写部分是否有误')
  84. } else {
  85. this.$indicator.open('验证过程中...')
  86. let param = new FormData()
  87. param.append('mobile', this.valid.mobile)
  88. param.append('captcha', this.valid.captcha)
  89. let config = {
  90. headers: {'Content-Type': 'multipart/form-data'}
  91. }
  92. this.$http.post(`/sso/resetPwd/checkCaptcha`, param, config)
  93. .then(response => {
  94. this.$indicator.close()
  95. if (response.data.success) {
  96. this.$emit('stepEvent', type)
  97. } else {
  98. this.getCode()
  99. this.downToast(response.data.errMsg)
  100. }
  101. }).catch((err) => {
  102. this.$indicator.close()
  103. this.downToast(err.errMsg)
  104. })
  105. }
  106. },
  107. getCode () {
  108. this.imgSrc = '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf()
  109. }
  110. }
  111. }
  112. </script>