sms-register.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!-- 短信注册 - smsRegister -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-m-b-60">
  6. <view class="head-title ss-m-b-20">{{$t('sheep.auth.register')}}</view>
  7. <view class="head-subtitle">{{$t('sheep.auth.tipsRegister')}}</view>
  8. </view>
  9. <!-- 表单项 -->
  10. <uni-forms
  11. ref="smsRegisterRef"
  12. v-model="state.model"
  13. :rules="state.rules"
  14. validateTrigger="bind"
  15. labelWidth="140"
  16. labelAlign="center"
  17. >
  18. <uni-forms-item name="mobile" :label="$t('sheep.auth.mobile')">
  19. <uni-easyinput
  20. :placeholder="$t('sheep.auth.enterMobile')"
  21. v-model="state.model.mobile"
  22. type="number"
  23. :inputBorder="false"
  24. >
  25. <template v-slot:right>
  26. <button
  27. class="ss-reset-button code-btn code-btn-start"
  28. :disabled="state.isMobileEnd"
  29. :class="{ 'code-btn-end': state.isMobileEnd }"
  30. @tap="getSmsCode('smsRegister', state.model.mobile)"
  31. >
  32. {{ getSmsTimer('smsRegister') }}
  33. </button>
  34. </template>
  35. </uni-easyinput>
  36. </uni-forms-item>
  37. <uni-forms-item name="code" :label="$t('sheep.auth.code')">
  38. <uni-easyinput
  39. :placeholder="$t('sheep.auth.enterCode')"
  40. v-model="state.model.code"
  41. :inputBorder="false"
  42. type="number"
  43. maxlength="4"
  44. ></uni-easyinput>
  45. </uni-forms-item>
  46. <uni-forms-item name="password" :label="$t('sheep.auth.password')">
  47. <uni-easyinput
  48. type="password"
  49. :placeholder="$t('sheep.auth.enterPassword')"
  50. v-model="state.model.password"
  51. :inputBorder="false"
  52. >
  53. <template v-slot:right>
  54. <button class="ss-reset-button login-btn-start" @tap="smsRegisterSubmit"> {{$t('sheep.auth.register')}} </button>
  55. </template>
  56. </uni-easyinput>
  57. </uni-forms-item>
  58. </uni-forms>
  59. <button class="ss-reset-button type-btn" @tap="showAuthModal('accountLogin')">
  60. {{$t('sheep.auth.backLogin')}}
  61. </button>
  62. </view>
  63. </template>
  64. <script setup>
  65. import { computed, ref, reactive, unref } from 'vue';
  66. import sheep from '@/sheep';
  67. import { code, mobile, password } from '@/sheep/validate/form';
  68. import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
  69. const props = defineProps({
  70. agreeStatus: {
  71. type: Boolean,
  72. default: false,
  73. },
  74. });
  75. const smsRegisterRef = ref(null);
  76. const isLogin = computed(() => sheep.$store('user').isLogin);
  77. const emits = defineEmits(['onConfirm']);
  78. // 数据
  79. const state = reactive({
  80. isMobileEnd: false, // 手机号输入完毕
  81. model: {
  82. mobile: '', // 手机号
  83. code: '', // 验证码
  84. password: '', // 密码
  85. },
  86. rules: {
  87. code,
  88. mobile,
  89. password,
  90. },
  91. });
  92. // 3.短信注册
  93. async function smsRegisterSubmit() {
  94. const validate = await unref(smsRegisterRef)
  95. .validate()
  96. .catch((error) => {
  97. console.log('error: ', error);
  98. });
  99. if (!validate) return;
  100. if (!props.agreeStatus) {
  101. emits('onConfirm',true);
  102. sheep.$helper.toast($t('sheep.auth.agree'));
  103. return;
  104. }
  105. const { code } = await sheep.$api.user.smsRegister({
  106. ...state.model,
  107. shareInfo: uni.getStorageSync('shareLog') || {},
  108. });
  109. if (code === 1) {
  110. closeAuthModal();
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. @import '../index.scss';
  116. </style>