sms-login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <!-- 短信登录 - smsLogin -->
  2. <template>
  3. <view>
  4. <!-- 表单项 -->
  5. <u-form ref="smsLoginRef" validateTrigger="bind" labelWidth="140" labelAlign="left"
  6. labelPosition="top">
  7. <u-form-item prop="mobile" label="手机号">
  8. <view class="input-line">
  9. <u-input placeholder="请输入手机号" v-model="model.mobile" border="none" type="number" maxlength="11">
  10. </u-input>
  11. </view>
  12. </u-form-item>
  13. <u-form-item prop="code" label="验证码">
  14. <view class="code-line flex_box flex_row_between w">
  15. <view class="input-line w-370">
  16. <u-input placeholder="请输入验证码" v-model="model.code" border="none" type="number" maxlength="6">
  17. </u-input>
  18. </view>
  19. <u-code keepRunning :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code>
  20. <u-button class="codeBtn" @tap="getCode">{{tips}}</u-button>
  21. <!-- <button
  22. class="ss-reset-button code-btn code-btn-start"
  23. :disabled="getSmsTimer('smsLogin') != '获取验证码'"
  24. :class="{ 'code-btn-end': getSmsTimer('smsLogin') != '获取验证码' }"
  25. @tap="getSmsCode('smsLogin', model.mobile)"
  26. >
  27. {{ getSmsTimer('smsLogin') }}
  28. </button> -->
  29. </view>
  30. </u-form-item>
  31. </u-form>
  32. <!-- <button class="ss-reset-button type-btn" @tap="showAuthModal('smsRegister')"> 立即注册 </button>-->
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. tips: '',
  40. seconds: 60,
  41. model: {
  42. mobile: '',
  43. code: ''
  44. },
  45. rules: {
  46. mobile: [{
  47. required: true,
  48. errorMessage: '请输入手机号',
  49. },
  50. {
  51. validateFunction: function(rule, value, data, callback) {
  52. if (!test.mobile(value)) {
  53. callback('手机号码格式不正确');
  54. }
  55. return true;
  56. },
  57. },
  58. ],
  59. }
  60. }
  61. },
  62. methods: {
  63. codeChange(text) {
  64. this.tips = text;
  65. },
  66. getCode() {
  67. if (this.$refs.uCode.canGetCode) {
  68. uni.showLoading({
  69. title: '正在获取验证码'
  70. })
  71. setTimeout(() => {
  72. uni.hideLoading();
  73. // 这里此提示会被this.start()方法中的提示覆盖
  74. uni.$u.toast('验证码已发送');
  75. // 通知验证码组件内部开始倒计时
  76. this.$refs.uCode.start();
  77. }, 2000);
  78. } else {
  79. // uni.$u.toast('倒计时结束后再发送');
  80. }
  81. },
  82. end() {
  83. // uni.$u.toast('倒计时结束');
  84. },
  85. start() {
  86. // uni.$u.toast('倒计时开始');
  87. },
  88. smsLoginSubmit() {
  89. if(!uni.$u.test.mobile(this.model.mobile)){
  90. return uni.$u.toast("请输入正确手机号");
  91. }
  92. if(!this.model.code) {
  93. return uni.$u.toast("请输入验证码");
  94. }
  95. uni.$u.toast("登录成功!");
  96. setTimeout(()=>{
  97. uni.navigateTo({
  98. url:'/pages/index/index'
  99. })
  100. },1000)
  101. }
  102. }
  103. }
  104. // import {reactive, ref, unref} from 'vue';
  105. // import sheep from '@/sheep';
  106. // import {code, mobile} from '@/sheep/validate/form';
  107. // import {closeAuthModal, getSmsCode, getSmsTimer, showAuthModal} from '@/sheep/hooks/useModal';
  108. // import {Base64} from 'js-base64'
  109. // import {onLoad} from "@dcloudio/uni-app";
  110. // const smsLoginRef = ref(null);
  111. // const props = defineProps({
  112. // agreeStatus: {
  113. // type: Boolean,
  114. // default: false,
  115. // },
  116. // });
  117. // // 数据
  118. // const state = reactive({
  119. // isMobileEnd: false, // 手机号输入完毕
  120. // codeText: '获取验证码',
  121. // model: {
  122. // mobile: '', // 手机号
  123. // code: '', // 验证码
  124. // uuid: null, // uuid
  125. // authInfo: {}
  126. // },
  127. // rules: {
  128. // code,
  129. // mobile,
  130. // },
  131. // });
  132. // // 2.短信登录
  133. // async function smsLoginSubmit() {
  134. // const validate = await unref(smsLoginRef)
  135. // .validate()
  136. // .catch((error) => {
  137. // console.log('error: ', error);
  138. // });
  139. // if (!validate) return;
  140. // state.model.uuid = sheep.$store('user').getUUID('smsLogin')
  141. // if (sheep.$store('app').authInfo){
  142. // state.model.authInfo = sheep.$store('app').authInfo
  143. // // sheep.$store('app').authInfo = null
  144. // }
  145. // // #ifdef MP
  146. // state.model.mpOpenId = uni.getStorageSync('openId');
  147. // // #endif
  148. // console.log(state.model,'state.mode')
  149. // const data = Base64.encode(JSON.stringify(state.model))
  150. // sheep.$api.user.smsLogin(data).then((response) => {
  151. // sheep.$helper.toast('登录成功')
  152. // closeAuthModal();
  153. // })
  154. // }
  155. // defineExpose({
  156. // smsLoginSubmit
  157. // })
  158. </script>
  159. <style lang="scss" scoped>
  160. // @import '../index.scss';
  161. .code-line {
  162. width: 100%;
  163. }
  164. .input-line {
  165. display: flex;
  166. align-items: center;
  167. width: 100%;
  168. background-color: #F5F7FB;
  169. border-radius: 16rpx;
  170. padding-left: 30rpx;
  171. height: 88rpx;
  172. box-sizing: border-box;
  173. }
  174. .codeBtn {
  175. width: 240rpx;
  176. height: 88rpx;
  177. background-color: #0256FF;
  178. border-radius: 16rpx;
  179. color: #fff;
  180. }
  181. .w-370 {
  182. width: 370rpx;
  183. }
  184. </style>