bind-mobile.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!-- 绑定手机号码页 -->
  2. <template>
  3. <view class="uni-content">
  4. <match-media :min-width="690">
  5. <view class="login-logo">
  6. <image :src="logo"></image>
  7. </view>
  8. <!-- 顶部文字 -->
  9. <text class="title title-box">绑定手机号</text>
  10. </match-media>
  11. <!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
  12. <uni-easyinput clearable :focus="focusMobile" @blur="focusMobile = false" type="number" class="input-box" :inputBorder="false" v-model="formData.mobile"
  13. maxlength="11" placeholder="请输入手机号"></uni-easyinput>
  14. <uni-id-pages-sms-form ref="smsForm" type="bind-mobile-by-sms" v-model="formData.code" :phone="formData.mobile">
  15. </uni-id-pages-sms-form>
  16. <button class="uni-btn send-btn-box" type="primary" @click="submit">提交</button>
  17. <uni-popup-captcha @confirm="submit" v-model="formData.captcha" scene="bind-mobile-by-sms" ref="popup">
  18. </uni-popup-captcha>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. store,
  24. mutations
  25. } from '@/uni_modules/uni-id-pages/common/store.js'
  26. export default {
  27. data() {
  28. return {
  29. formData: {
  30. mobile: "",
  31. code: "",
  32. captcha: ""
  33. },
  34. focusMobile:true,
  35. logo: "/static/logo.png"
  36. }
  37. },
  38. computed: {
  39. tipText() {
  40. return `验证码已通过短信发送至 ${this.formData.mobile}。密码为6 - 20位`
  41. }
  42. },
  43. onLoad(event) {},
  44. onReady() {},
  45. methods: {
  46. /**
  47. * 完成并提交
  48. */
  49. submit() {
  50. if(! /^1\d{10}$/.test(this.formData.mobile)){
  51. this.focusMobile = true
  52. return uni.showToast({
  53. title: '手机号码格式不正确',
  54. icon: 'none',
  55. duration: 3000
  56. });
  57. }
  58. if(! /^\d{6}$/.test(this.formData.code)){
  59. this.$refs.smsForm.focusSmsCodeInput = true
  60. return uni.showToast({
  61. title: '验证码格式不正确',
  62. icon: 'none',
  63. duration: 3000
  64. });
  65. }
  66. const uniIdCo = uniCloud.importObject("uni-id-co")
  67. uniIdCo.bindMobileBySms(this.formData).then(e => {
  68. uni.showToast({
  69. title: e.errMsg,
  70. icon: 'none',
  71. duration: 3000
  72. });
  73. // #ifdef APP-NVUE
  74. const eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
  75. // #endif
  76. // #ifndef APP-NVUE
  77. const eventChannel = this.getOpenerEventChannel();
  78. // #endif
  79. mutations.setUserInfo(this.formData)
  80. uni.navigateBack()
  81. }).catch(e => {
  82. console.log(e);
  83. if (e.errCode == 'uni-id-captcha-required') {
  84. this.$refs.popup.open()
  85. }
  86. }).finally(e => {
  87. this.formData.captcha = ""
  88. })
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss">
  94. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  95. .uni-content {
  96. padding: 0;
  97. align-items: center;
  98. justify-content: center;
  99. padding: 50rpx;
  100. padding-top: 10px;
  101. }
  102. @media screen and (min-width: 690px) {
  103. .uni-content{
  104. padding: 30px 40px 40px;
  105. }
  106. }
  107. /* #ifndef APP-NVUE || VUE3 */
  108. .uni-content ::v-deep .uni-easyinput__content {}
  109. /* #endif */
  110. .input-box {
  111. width: 100%;
  112. margin-top: 16px;
  113. background-color: #f9f9f9;
  114. border-radius: 6rpx;
  115. flex-direction: row;
  116. flex-wrap: nowrap;
  117. margin-bottom: 10px;
  118. }
  119. .send-btn-box {
  120. margin-top: 15px;
  121. }
  122. </style>