login-smscode.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!-- 短信验证码登录页 -->
  2. <template>
  3. <view class="uni-content">
  4. <view class="login-logo">
  5. <image :src="logo"></image>
  6. </view>
  7. <!-- 顶部文字 -->
  8. <text class="title">请输入验证码</text>
  9. <text class="tip">先输入图形验证码,再获取短信验证码</text>
  10. <uni-forms>
  11. <uni-id-pages-sms-form focusCaptchaInput v-model="code" type="login-by-sms" ref="smsCode" :phone="phone">
  12. </uni-id-pages-sms-form>
  13. <button class="uni-btn send-btn" type="primary" @click="submit">登录</button>
  14. </uni-forms>
  15. <uni-popup-captcha @confirm="submit" v-model="captcha" scene="login-by-sms" ref="popup"></uni-popup-captcha>
  16. </view>
  17. </template>
  18. <script>
  19. import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
  20. export default {
  21. mixins: [mixin],
  22. data() {
  23. return {
  24. "code": "",
  25. "phone": "",
  26. "captcha": "",
  27. "logo": "/static/logo.png"
  28. }
  29. },
  30. computed: {
  31. tipText() {
  32. return '验证码已通过短信发送至' + this.phone;
  33. },
  34. },
  35. onLoad({
  36. phoneNumber
  37. }) {
  38. this.phone = phoneNumber;
  39. },
  40. onShow() {
  41. // #ifdef H5
  42. document.onkeydown = event => {
  43. let e = event || window.event;
  44. if (e && e.keyCode == 13) { //回车键的键值为13
  45. this.submit()
  46. }
  47. };
  48. // #endif
  49. },
  50. methods: {
  51. submit() { //完成并提交
  52. const uniIdCo = uniCloud.importObject("uni-id-co", {
  53. errorOptions: {
  54. type: 'toast'
  55. }
  56. })
  57. if (this.code.length != 6) {
  58. this.$refs.smsCode.focusSmsCodeInput = true
  59. return uni.showToast({
  60. title: '验证码不能为空',
  61. icon: 'none',
  62. duration: 3000
  63. });
  64. }
  65. uniIdCo.loginBySms({
  66. "mobile": this.phone,
  67. "code": this.code,
  68. "captcha": this.captcha
  69. }).then(e => {
  70. this.loginSuccess(e)
  71. }).catch(e => {
  72. if (e.errCode == 'uni-id-captcha-required') {
  73. this.$refs.popup.open()
  74. } else {
  75. console.log(e.errMsg);
  76. }
  77. }).finally(e => {
  78. this.captcha = ''
  79. })
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped lang="scss">
  85. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  86. .tip {
  87. margin-top: -15px;
  88. margin-bottom: 15px;
  89. }
  90. .popup-captcha {
  91. /* #ifndef APP-NVUE */
  92. display: flex;
  93. /* #endif */
  94. padding: 20rpx;
  95. background-color: #FFF;
  96. border-radius: 2px;
  97. flex-direction: column;
  98. position: relative;
  99. }
  100. .popup-captcha .title {
  101. font-weight: normal;
  102. padding: 0;
  103. padding-bottom: 15px;
  104. color: #666;
  105. }
  106. .popup-captcha .close {
  107. position: absolute;
  108. bottom: -40px;
  109. margin-left: -13px;
  110. left: 50%;
  111. }
  112. .popup-captcha .uni-btn {
  113. margin: 0;
  114. }
  115. </style>