sms-login.vue 3.0 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. </view>
  57. </template>
  58. <script setup>
  59. import { computed, watch, ref, reactive, unref } from 'vue';
  60. import sheep from '@/sheep';
  61. import { code, mobile } from '@/sheep/validate/form';
  62. import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
  63. const smsLoginRef = ref(null);
  64. const emits = defineEmits(['onConfirm']);
  65. const props = defineProps({
  66. agreeStatus: {
  67. type: Boolean,
  68. default: false,
  69. },
  70. });
  71. // 数据
  72. const state = reactive({
  73. isMobileEnd: false, // 手机号输入完毕
  74. codeText: '获取验证码',
  75. model: {
  76. mobile: '', // 手机号
  77. code: '', // 验证码
  78. },
  79. rules: {
  80. code,
  81. mobile,
  82. },
  83. });
  84. // 2.短信登录
  85. async function smsLoginSubmit() {
  86. const validate = await unref(smsLoginRef)
  87. .validate()
  88. .catch((error) => {
  89. console.log('error: ', error);
  90. });
  91. if (!validate) return;
  92. if (!props.agreeStatus) {
  93. emits('onConfirm', true)
  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>