stepMobile.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>密码重置</p>
  5. <a href="javascript:void(0)" class="back" @click="jump('select')"><i class="el-icon-back"></i></a>
  6. </div>
  7. <div class="f-form">
  8. <div class="page-part">
  9. <span>使用手机号<strong>{{info | hide}}</strong>接收验证码</span>
  10. </div>
  11. <div class="page-part">
  12. <mt-field auto-complete="off"
  13. placeholder="短信验证码"
  14. v-model="token"
  15. :state="state.token"
  16. @blur.native.capture="validateCode">
  17. <span class="token" @click="getCheckCode" v-text="tokenText">获取验证码</span>
  18. </mt-field>
  19. </div>
  20. <div class="page-part">
  21. <mt-button size="large" type="primary" @click="sureAccount">确 定</mt-button>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'step-mobile',
  29. props: ['info'],
  30. data () {
  31. return {
  32. state: {
  33. token: 'error'
  34. },
  35. token: '',
  36. tokenCode: '',
  37. tokenText: '获取验证码',
  38. tokenTime: '60'
  39. }
  40. },
  41. filters: {
  42. hide: function (value) {
  43. let reg = /^(\d{3})\d{6}(\d{2})$/
  44. return value.replace(reg, '$1******$2')
  45. }
  46. },
  47. methods: {
  48. jump (type) {
  49. this.$emit('stepEvent', type)
  50. },
  51. // 警告弹窗
  52. downToast (type) {
  53. this.$toast({
  54. message: type,
  55. iconClass: 'el-icon-warning'
  56. })
  57. },
  58. // 验证码验证
  59. validateCode () {
  60. if (!this.token) {
  61. this.downToast('请填写验证码信息')
  62. this.state.token = 'error'
  63. } else {
  64. this.state.token = 'success'
  65. }
  66. },
  67. // 获取验证码
  68. getCheckCode () {
  69. if (this.tokenTime > 0 && this.tokenTime < 60) {
  70. this.downToast('请稍后再点击,我在倒计时')
  71. } else {
  72. this.$indicator.open('获取中...')
  73. let _this = this
  74. this.$http.get('/sso/resetPwd/check/mobile', {params: {mobile: this.info, timestamp: new Date().getTime() + ''}})
  75. .then(response => {
  76. this.$indicator.close()
  77. if (response.data.content) {
  78. this.tokenCode = response.data.content.token
  79. this.$toast({
  80. message: '验证码已经发送到您的手机,请注意查收',
  81. iconClass: 'el-icon-success'
  82. })
  83. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  84. let setTime = setInterval(() => {
  85. _this.tokenTime--
  86. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  87. if (this.tokenTime <= 0) {
  88. clearInterval(setTime)
  89. _this.tokenText = '获取验证码'
  90. _this.tokenTime = 60
  91. }
  92. }, 1000)
  93. }
  94. }).catch((err) => {
  95. this.$indicator.close()
  96. this.downToast(err.errMsg)
  97. })
  98. }
  99. },
  100. // 验证信息
  101. sureAccount () {
  102. if (this.state.token !== 'success') {
  103. this.downToast('请确认填写部分是否有误')
  104. } else {
  105. this.$indicator.open('验证过程中...')
  106. let param = new FormData()
  107. param.append('code', this.token)
  108. param.append('token', this.tokenCode)
  109. let config = {
  110. headers: {'Content-Type': 'multipart/form-data'}
  111. }
  112. this.$http.post('/sso/resetPwd/check/mobile', param, config)
  113. .then(response => {
  114. this.$indicator.close()
  115. if (response.data.success) {
  116. this.$emit('stepEvent', 'security')
  117. this.$emit('tokenEvent', response.data.content.token)
  118. } else {
  119. this.downToast(response.data.errMsg)
  120. }
  121. }).catch((err) => {
  122. this.$indicator.close()
  123. this.downToast(err.errMsg)
  124. })
  125. }
  126. }
  127. }
  128. }
  129. </script>