code.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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('验证码发送成功');
  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. console.log('登录名===>' + this.loginName);
  74. console.log('输入的验证码是===>' + value);
  75. // 登录成功初始化token与用户信息
  76. let url = "/api/thirdRegister";
  77. this.$u.post(url, {
  78. username: this.loginName,
  79. code: value
  80. }).then(data => {
  81. // 登录成功初始化token与用户信息
  82. this.$u.vuex('vuex_token', data.token);
  83. this.$u.vuex('vuex_user', data.loginUser);
  84. uni.switchTab({
  85. url: '/pages/index/index'
  86. })
  87. });
  88. }
  89. }
  90. };
  91. </script>
  92. <style lang="scss" scoped>
  93. .wrap {
  94. padding: 80 rpx;
  95. }
  96. .box {
  97. margin: 30 rpx 0;
  98. font-size: 30 rpx;
  99. color: 555;
  100. }
  101. .key-input {
  102. padding: 30 rpx 0;
  103. text {
  104. display: none;
  105. }
  106. .error {
  107. display: block;
  108. color: red;
  109. font-size: 30 rpx;
  110. margin: 20 rpx 0;
  111. }
  112. }
  113. .title {
  114. font-size: 50 rpx;
  115. color: #333;
  116. }
  117. .key-input .tips {
  118. font-size: 30 rpx;
  119. color: #333;
  120. margin-top: 20 rpx;
  121. margin-bottom: 60 rpx;
  122. }
  123. .captcha {
  124. color: $u-type-warning;
  125. font-size: 30 rpx;
  126. margin-top: 40 rpx;
  127. .noCaptcha {
  128. display: block;
  129. }
  130. .regain {
  131. display: block;
  132. }
  133. }
  134. </style>