sms-login.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!-- 短信登录 - smsLogin -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box">
  6. <view class="ss-flex ss-m-b-20">
  7. <!-- <view class="head-title-active ss-m-r-40" @tap="showAuthModal('accountLogin')">
  8. 账号登录
  9. </view>
  10. <view class="head-title head-title-line head-title-animation">短信登录</view> -->
  11. <view class="head-subtitle">未注册的手机号,验证后自动注册账号</view>
  12. </view>
  13. </view>
  14. <!-- 表单项 -->
  15. <uni-forms ref="smsLoginRef" v-model="state.model" :rules="state.rules" validateTrigger="bind" labelWidth="140"
  16. labelAlign="center" class="loginUniForm">
  17. <uni-forms-item name="mobile" label="手机号" class="loginUniFormItem">
  18. <uni-easyinput placeholder="请输入手机号" v-model="state.model.mobile" :inputBorder="false" type="number">
  19. <template v-slot:right>
  20. <button class="ss-reset-button code-btn code-btn-start" :disabled="state.isMobileEnd"
  21. :class="{ 'code-btn-end': state.isMobileEnd }"
  22. @tap="getSmsCode('smsLogin', state.model.mobile)">
  23. {{ getSmsTimer('smsLogin') }}
  24. </button>
  25. </template>
  26. </uni-easyinput>
  27. </uni-forms-item>
  28. <uni-forms-item name="code" label="验证码" class="loginUniFormItem">
  29. <uni-easyinput placeholder="请输入验证码" v-model="state.model.code" :inputBorder="false" type="number"
  30. maxlength="4">
  31. <!-- <template v-slot:right>
  32. <button class="ss-reset-button login-btn-start" @tap="smsLoginSubmit"> 登录 </button>
  33. </template> -->
  34. </uni-easyinput>
  35. </uni-forms-item>
  36. </uni-forms>
  37. <view style="display: flex;justify-content: space-between;margin-top: 20rpx;">
  38. <!-- <button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
  39. 忘记密码
  40. </button> -->
  41. <button class="ss-reset-button login-btn-start" @tap="smsLoginSubmit"> 登录 </button>
  42. </view>
  43. </view>
  44. </template>
  45. <script setup>
  46. import {
  47. ref,
  48. reactive,
  49. unref,
  50. computed
  51. } from 'vue';
  52. import sheep from '@/sheep';
  53. import {
  54. code,
  55. mobile
  56. } from '@/sheep/validate/form';
  57. import {
  58. showAuthModal,
  59. closeAuthModal,
  60. getSmsCode,
  61. getSmsTimer
  62. } from '@/sheep/hooks/useModal';
  63. import AuthUtil from '@/sheep/api/member/auth';
  64. const smsLoginRef = ref(null);
  65. const emits = defineEmits(['onConfirm']);
  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. // 短信登录
  86. async function smsLoginSubmit() {
  87. // 看缓存中有没有linkId 如果有的话 加入model传给后台 即为绑定
  88. const linkId = uni.getStorageSync("linkId")
  89. if(!linkId){
  90. state.model.linkId = linkId
  91. }
  92. // 参数校验
  93. const validate = await unref(smsLoginRef)
  94. .validate()
  95. .catch((error) => {
  96. console.log('error: ', error);
  97. });
  98. if (!validate) {
  99. return;
  100. }
  101. if (!props.agreeStatus) {
  102. emits('onConfirm', true)
  103. //onConfirm(true)
  104. sheep.$helper.toast('请勾选同意');
  105. return;
  106. }
  107. // 提交数据
  108. const {
  109. code
  110. } = await AuthUtil.smsLogin(state.model);
  111. if (code === 0) {
  112. closeAuthModal();
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. @import '../index.scss';
  118. .code-btn-start {
  119. color: #55b774;
  120. border: 1px solid #55b774;
  121. }
  122. .agreement-box {
  123. margin: 20rpx 0;
  124. }
  125. .login-btn-start {
  126. background: rgb(14, 147, 46);
  127. width: 100%;
  128. height: 80rpx;
  129. font-size: 32rpx;
  130. }
  131. .loginUniForm {
  132. border: 1rpx solid #d6d6d6;
  133. padding: 10rpx 15rpx;
  134. border-radius: 10rpx;
  135. }
  136. .loginUniFormItem:first-child {
  137. border-bottom: 1rpx solid #d6d6d6;
  138. padding-bottom: 10rpx;
  139. }
  140. .loginUniFormItem:last-child {
  141. // border-bottom: 1rpx solid #d6d6d6;
  142. padding-top: 10rpx;
  143. }
  144. ::v-deep .loginUniFormItem .uni-forms-item__inner {
  145. padding-bottom: 0;
  146. }
  147. ::v-deep .loginUniFormItem .uni-error-message {
  148. bottom: -20rpx;
  149. }
  150. </style>