sms-register.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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">注册</view>
  7. <view class="head-subtitle">请使用本人手机号完成注册</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="手机号">
  19. <uni-easyinput
  20. placeholder="请输入手机号"
  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="验证码">
  38. <uni-easyinput
  39. placeholder="请输入验证码"
  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="密码">
  47. <uni-easyinput
  48. type="password"
  49. placeholder="请输入密码"
  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"> 注册 </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. 返回登录
  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. // 数据
  78. const state = reactive({
  79. isMobileEnd: false, // 手机号输入完毕
  80. model: {
  81. mobile: '', // 手机号
  82. code: '', // 验证码
  83. password: '', // 密码
  84. },
  85. rules: {
  86. code,
  87. mobile,
  88. password,
  89. },
  90. });
  91. // 3.短信注册
  92. async function smsRegisterSubmit() {
  93. const validate = await unref(smsRegisterRef)
  94. .validate()
  95. .catch((error) => {
  96. console.log('error: ', error);
  97. });
  98. if (!validate) return;
  99. if (!props.agreeStatus) {
  100. sheep.$helper.toast('请勾选同意');
  101. return;
  102. }
  103. const { error } = await sheep.$api.user.smsRegister({
  104. ...state.model,
  105. shareInfo: uni.getStorageSync('shareLog') || {},
  106. });
  107. if (error === 0) {
  108. closeAuthModal();
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. @import '../index.scss';
  114. </style>