bind-mobile.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. export default {
  23. data() {
  24. return {
  25. formData: {
  26. mobile: "",
  27. code: "",
  28. captcha: ""
  29. },
  30. focusMobile:true,
  31. logo: "/static/logo.png"
  32. }
  33. },
  34. computed: {
  35. tipText() {
  36. return `验证码已通过短信发送至 ${this.formData.mobile}。密码为6 - 20位`
  37. }
  38. },
  39. onLoad(event) {},
  40. onReady() {},
  41. methods: {
  42. /**
  43. * 完成并提交
  44. */
  45. submit() {
  46. if(! /^1\d{10}$/.test(this.formData.mobile)){
  47. this.focusMobile = true
  48. return uni.showToast({
  49. title: '手机号码格式不正确',
  50. icon: 'none'
  51. });
  52. }
  53. if(! /^\d{6}$/.test(this.formData.code)){
  54. this.$refs.smsForm.focusSmsCodeInput = true
  55. return uni.showToast({
  56. title: '验证码格式不正确',
  57. icon: 'none'
  58. });
  59. }
  60. console.log(this.formData);
  61. const uniIdCo = uniCloud.importObject("uni-id-co")
  62. uniIdCo.bindMobileBySms(this.formData).then(e => {
  63. console.log(e);
  64. uni.showToast({
  65. title: e.errMsg,
  66. icon: 'none'
  67. });
  68. // #ifdef APP-NVUE
  69. const eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
  70. // #endif
  71. // #ifndef APP-NVUE
  72. const eventChannel = this.getOpenerEventChannel();
  73. // #endif
  74. eventChannel.emit('getUserInfo')
  75. uni.navigateBack()
  76. }).catch(e => {
  77. console.log(e);
  78. if (e.errCode == 'uni-id-captcha-required') {
  79. this.$refs.popup.open()
  80. }
  81. }).finally(e => {
  82. this.formData.captcha = ""
  83. })
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss">
  89. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  90. .uni-content {
  91. padding: 0;
  92. align-items: center;
  93. justify-content: center;
  94. padding: 50rpx;
  95. padding-top: 10px;
  96. }
  97. @media screen and (min-width: 690px) {
  98. .uni-content{
  99. padding: 30px 40px 40px;
  100. }
  101. }
  102. /* #ifndef APP-NVUE || VUE3 */
  103. .uni-content ::v-deep .uni-easyinput__content {}
  104. /* #endif */
  105. .input-box {
  106. width: 100%;
  107. margin-top: 16px;
  108. background-color: #f9f9f9;
  109. border-radius: 6rpx;
  110. flex-direction: row;
  111. flex-wrap: nowrap;
  112. margin-bottom: 10px;
  113. }
  114. .send-btn-box {
  115. margin-top: 15px;
  116. }
  117. </style>