code.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="wrap">
  3. <view class="key-input">
  4. <view class="title">输入验证码</view>
  5. <view class="tips">验证码已发送至 +{{tel}}</view>
  6. <u-message-input :focus="true" :value="value" @change="change" @finish="finish" mode="bottomLine" :maxlength="maxlength"></u-message-input>
  7. <text :class="{ error: error }">验证码错误,请重新输入</text>
  8. <view class="captcha">
  9. <text :class="{ noCaptcha: show }" @tap="noCaptcha">收不到验证码点这里</text>
  10. <text :class="{ regain: !show }">{{ second }}秒后重新获取验证码</text>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. maxlength: 4,
  20. value: '',
  21. second: 60,
  22. show: false,
  23. error: false,
  24. tel: ''
  25. };
  26. },
  27. computed: {},
  28. onLoad(page) {
  29. console.log(page)
  30. this.tel = page.tel
  31. // this.getCaptcha()
  32. let interval = setInterval(() => {
  33. this.second--;
  34. if (this.second <= 0) {
  35. this.show = true;
  36. if (this.value.lenth != 4) {
  37. this.error = true;
  38. }
  39. clearInterval(interval);
  40. }
  41. }, 1000);
  42. },
  43. methods: {
  44. // 收不到验证码选择时的选择
  45. noCaptcha() {
  46. uni.showActionSheet({
  47. itemList: ['重新获取验证码', '接听语音验证码'],
  48. success: function(res) {
  49. },
  50. fail: function(res) {
  51. }
  52. });
  53. },
  54. // change事件侦听
  55. change(value) {
  56. // console.log('change', value);
  57. },
  58. // 输入完验证码最后一位执行
  59. finish(value) {
  60. // console.log('finish', value);
  61. }
  62. }
  63. };
  64. </script>
  65. <style lang="scss" scoped>
  66. .wrap {
  67. padding: 80rpx;
  68. }
  69. .box {
  70. margin: 30rpx 0;
  71. font-size: 30rpx;
  72. color: 555;
  73. }
  74. .key-input {
  75. padding: 30rpx 0;
  76. text {
  77. display: none;
  78. }
  79. .error {
  80. display: block;
  81. color: red;
  82. font-size: 30rpx;
  83. margin: 20rpx 0;
  84. }
  85. }
  86. .title {
  87. font-size: 50rpx;
  88. color: #333;
  89. }
  90. .key-input .tips {
  91. font-size: 30rpx;
  92. color: #333;
  93. margin-top: 20rpx;
  94. margin-bottom: 60rpx;
  95. }
  96. .captcha {
  97. color: $u-type-warning;
  98. font-size: 30rpx;
  99. margin-top: 40rpx;
  100. .noCaptcha {
  101. display: block;
  102. }
  103. .regain {
  104. display: block;
  105. }
  106. }
  107. </style>