code.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="wrap">
  3. <view class="key-input">
  4. <view class="title">输入验证码</view>
  5. <view class="tips">验证码已发送至 {{ loginName }}</view>
  6. <u-message-input :focus="true" :maxlength="maxlength" :value="value" mode="bottomLine" @change="change"
  7. @finish="finish"></u-message-input>
  8. <text :class="{ error: error }">验证码错误,请重新输入</text>
  9. <view class="captcha">
  10. <text :class="{ noCaptcha: show }" @tap="noCaptcha">收不到验证码点这里</text>
  11. <text :class="{ regain: !show }">{{ second }}秒后重新获取验证码</text>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. maxlength: 4,
  21. value: '',
  22. second: 60,
  23. show: false,
  24. error: false,
  25. loginName: ''
  26. };
  27. },
  28. onLoad: function (option) {
  29. this.loginName = option.loginName //上个页面传递的参数。
  30. // 发送验证码
  31. this.getCaptcha()
  32. // 倒计时
  33. let interval = setInterval(() => {
  34. this.second--;
  35. if (this.second <= 0) {
  36. this.show = true;
  37. if (this.value.lenth != 4) {
  38. this.error = true;
  39. }
  40. clearInterval(interval);
  41. }
  42. }, 1000);
  43. },
  44. methods: {
  45. getCaptcha() {
  46. console.log('用户===>' + this.loginName);
  47. let url = "/api/captchaSms";
  48. this.$u.get(url, {
  49. loginName: this.loginName
  50. }).then(data => {
  51. console.log('验证码发送' + data.send);
  52. });
  53. },
  54. // 收不到验证码选择时的选择
  55. noCaptcha() {
  56. let that = this
  57. uni.showActionSheet({
  58. itemList: ['重新获取验证码'],
  59. success: function (res) {
  60. that.getCaptcha()
  61. that.$mytip.toast('验证码发送成功')
  62. },
  63. fail: function (res) {
  64. }
  65. });
  66. },
  67. // change事件侦听
  68. change(value) {
  69. // console.log('change', value);
  70. },
  71. // 输入完验证码最后一位执行
  72. finish(value) {
  73. // 登录成功初始化token与用户信息
  74. let url = "/api/thirdRegister";
  75. this.$u.post(url, {
  76. username: this.loginName,
  77. code: value
  78. }).then(data => {
  79. // 登录成功初始化token与用户信息
  80. this.$u.vuex('vuex_token', data.token);
  81. this.$u.vuex('vuex_user', data.loginUser);
  82. uni.switchTab({
  83. url: '/pages/index/index'
  84. })
  85. });
  86. }
  87. }
  88. };
  89. </script>
  90. <style lang="scss" scoped>
  91. .wrap {
  92. padding: 80 rpx;
  93. }
  94. .box {
  95. margin: 30 rpx 0;
  96. font-size: 30 rpx;
  97. color: 555;
  98. }
  99. .key-input {
  100. padding: 30 rpx 0;
  101. text {
  102. display: none;
  103. }
  104. .error {
  105. display: block;
  106. color: red;
  107. font-size: 30 rpx;
  108. margin: 20 rpx 0;
  109. }
  110. }
  111. .title {
  112. font-size: 50 rpx;
  113. color: #333;
  114. }
  115. .key-input .tips {
  116. font-size: 30 rpx;
  117. color: #333;
  118. margin-top: 20 rpx;
  119. margin-bottom: 60 rpx;
  120. }
  121. .captcha {
  122. color: $u-type-warning;
  123. font-size: 30 rpx;
  124. margin-top: 40 rpx;
  125. .noCaptcha {
  126. display: block;
  127. }
  128. .regain {
  129. display: block;
  130. }
  131. }
  132. </style>