smsVerification.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="smsVerification-container">
  3. <view class="sms-title">输入短信验证码</view>
  4. <text class="sms-describe">验证码已发送至157****7854,请在下方输入框内输入6位数字验证码</text>
  5. <view class="sms-item" @tap="showKeyboard=!showKeyboard">
  6. <u-message-input mode="bottomLine" :maxlength="6" v-model="value" :disabled-keyboard="true"></u-message-input>
  7. </view>
  8. <view class="sendcode-con">
  9. <text :class="['getcode-btn', isDisable ? 'grey-btn' : '']" @click="isDisable ? null : getCodeValidate()">{{nowVal}}</text>
  10. </view>
  11. <view class="btn-con">
  12. <u-button class="handle-btn" type="info" size="medium" @click="cancel">取消</u-button>
  13. <u-button class="handle-btn" type="primary" size="medium" @click="submit">确定</u-button>
  14. </view>
  15. <!-- 数字键盘 -->
  16. <u-keyboard ref="uKeyboard" :dot-enabled="false" :mask="false" :tooltip="false" v-model="showKeyboard" @change="valChange" @backspace="backspace"></u-keyboard>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. nowVal: '获取验证码', // 按钮显示内容
  24. count: '', // 当前秒数
  25. timer: null, // 倒计时
  26. isDisable: false, // 是否禁止获取验证码
  27. value: '', //输入的内容
  28. showKeyboard: false // 是否打开键盘
  29. }
  30. },
  31. onShow() {
  32. this.getCodeValidate()
  33. },
  34. onLoad() {
  35. //因为此时实例没有挂载完成,需要延迟操作
  36. setTimeout(() => {
  37. this.showKeyboard = true
  38. }, 50)
  39. },
  40. methods:{
  41. // 按键被点击(点击退格键不会触发此事件)
  42. valChange(val) {
  43. // 将每次按键的值拼接到value变量中,注意+=写法
  44. if(this.value.length < 6){
  45. this.value += val
  46. }
  47. },
  48. // 退格键被点击
  49. backspace() {
  50. // 删除value的最后一个字符
  51. if(this.value.length) this.value = this.value.substr(0, this.value.length - 1)
  52. },
  53. // 获取验证码
  54. getCodeValidate(){
  55. const _this = this
  56. // 短信验证码
  57. // memberVerifyCode({ phone: '15454787787' }).then(res => {
  58. // console.log(JSON.stringify(res))
  59. // if(res.status == 200){ // 验证码输入正确
  60. // 开启倒计时
  61. this.getCodeFun()
  62. uni.showToast({icon: 'none',title: '验证码发送成功'})
  63. // }else { // 验证码输入错误
  64. // uni.showToast({icon: 'none',title: res.message})
  65. // }
  66. // })
  67. },
  68. // 开始倒计时
  69. getCodeFun(){
  70. const TIME_COUNT = 60
  71. if (!this.timer) {
  72. this.count = TIME_COUNT
  73. this.timer = setInterval(() => {
  74. if (this.count > 0 && this.count <= TIME_COUNT) {
  75. this.count--
  76. this.nowVal = this.count + '秒后重新发送'
  77. this.isDisable = true
  78. } else {
  79. this.nowVal = '重新获取验证码'
  80. clearInterval(this.timer)
  81. this.timer = null
  82. this.isDisable = false
  83. }
  84. }, 1000)
  85. }
  86. },
  87. // 确定
  88. submit(){
  89. if(!this.value || this.value.length < 6){
  90. uni.showToast({ title: '请输入6位数字验证码', icon: 'none' })
  91. }else{
  92. // 校验输入短信验证码是否正确
  93. uni.redirectTo({
  94. url: '/pages/userCenter/userInfo/paymentPwd'
  95. })
  96. }
  97. },
  98. // 取消
  99. cancel(){
  100. uni.navigateBack({
  101. delta: 1
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="less">
  108. .smsVerification-container{
  109. width: 100%;
  110. padding: 0 30rpx;
  111. box-sizing: border-box;
  112. background-color: #fff;
  113. .sms-title {
  114. margin: 50rpx 0 30rpx;
  115. font-size: 36rpx;
  116. font-weight: bold;
  117. }
  118. .sms-describe{
  119. display: block;
  120. color: #606266;
  121. margin: 20rpx 0 50rpx;
  122. }
  123. .sendcode-con{
  124. text-align: center;
  125. padding-top: 70rpx;
  126. .getcode-btn {
  127. display: block;
  128. font-size: 28rpx;
  129. color: #298bf2;
  130. }
  131. .grey-btn{
  132. color: #999;
  133. }
  134. }
  135. .btn-con{
  136. display: flex;
  137. justify-content: space-between;
  138. padding-top: 130rpx;
  139. .handle-btn{
  140. display: inline-block;
  141. width: 45%;
  142. margin: 0 auto;
  143. text-align: center;
  144. }
  145. }
  146. }
  147. </style>