sms-login.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!-- 短信登录 - smsLogin -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-m-b-60">
  6. <view class="ss-flex ss-m-b-20">
  7. <view class="head-title-active ss-m-r-40" @tap="showAuthModal('accountLogin')"
  8. >账号登录</view
  9. >
  10. <view class="head-title head-title-line head-title-animation">短信登录</view>
  11. </view>
  12. <view class="head-subtitle">未注册手机号请先点击下方立即注册</view>
  13. </view>
  14. <!-- 表单项 -->
  15. <uni-forms
  16. ref="smsLoginRef"
  17. v-model="state.model"
  18. :rules="state.rules"
  19. validateTrigger="bind"
  20. labelWidth="140"
  21. labelAlign="center"
  22. >
  23. <uni-forms-item name="mobile" label="手机号">
  24. <uni-easyinput
  25. placeholder="请输入手机号"
  26. v-model="state.model.mobile"
  27. :inputBorder="false"
  28. type="number"
  29. >
  30. <template v-slot:right>
  31. <button
  32. class="ss-reset-button code-btn code-btn-start"
  33. :disabled="state.isMobileEnd"
  34. :class="{ 'code-btn-end': state.isMobileEnd }"
  35. @tap="getSmsCode('smsLogin', state.model.mobile)"
  36. >
  37. {{ getSmsTimer('smsLogin') }}
  38. </button>
  39. </template>
  40. </uni-easyinput>
  41. </uni-forms-item>
  42. <uni-forms-item name="code" label="验证码">
  43. <uni-easyinput
  44. placeholder="请输入验证码"
  45. v-model="state.model.code"
  46. :inputBorder="false"
  47. type="number"
  48. maxlength="4"
  49. >
  50. <template v-slot:right>
  51. <button class="ss-reset-button login-btn-start" @tap="smsLoginSubmit"> 登录 </button>
  52. </template>
  53. </uni-easyinput>
  54. </uni-forms-item>
  55. </uni-forms>
  56. <button class="ss-reset-button type-btn" @tap="showAuthModal('smsRegister')"> 立即注册 </button>
  57. </view>
  58. </template>
  59. <script setup>
  60. import { computed, watch, ref, reactive, unref } from 'vue';
  61. import sheep from '@/sheep';
  62. import { code, mobile } from '@/sheep/validate/form';
  63. import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
  64. import throttle from '@/sheep/helper/throttle';
  65. const smsLoginRef = ref(null);
  66. const props = defineProps({
  67. agreeStatus: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. });
  72. // 数据
  73. const state = reactive({
  74. isMobileEnd: false, // 手机号输入完毕
  75. codeText: '获取验证码',
  76. model: {
  77. mobile: '', // 手机号
  78. code: '', // 验证码
  79. },
  80. rules: {
  81. code,
  82. mobile,
  83. },
  84. });
  85. // 2.短信登录
  86. async function smsLoginSubmit() {
  87. const validate = await unref(smsLoginRef)
  88. .validate()
  89. .catch((error) => {
  90. console.log('error: ', error);
  91. });
  92. if (!validate) return;
  93. if (!props.agreeStatus) {
  94. sheep.$helper.toast('请勾选同意');
  95. return;
  96. }
  97. const { error } = await sheep.$api.user.smsLogin(state.model);
  98. if (error === 0) {
  99. closeAuthModal();
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. @import '../index.scss';
  105. </style>