phoneLogin.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="t-login">
  3. <view class="t-b">欢迎登录车旅程!</view>
  4. <view class="t-b2">欢迎使用车旅程,为你提供便捷服务</view>
  5. <!-- 表单数据 -->
  6. <view class="form-box">
  7. <u-form >
  8. <u-form-item >
  9. <u-input v-model="mobile" border="none" placeholder="请输入手机号" />
  10. </u-form-item>
  11. <view class="line"></view>
  12. <u-form-item>
  13. <u-input v-model="captcha" border="none" placeholder="请输入验证码">
  14. <template slot="suffix">
  15. <u-code
  16. ref="uCode"
  17. @change="codeChange"
  18. seconds="20"
  19. unique-key="loginCode"
  20. changeText="X秒重新获取"
  21. ></u-code>
  22. <u-button
  23. @tap="getCode"
  24. :text="tips"
  25. type="success"
  26. size="mini"
  27. ></u-button>
  28. </template>
  29. </u-input>
  30. </u-form-item>
  31. </u-form>
  32. </view>
  33. <view class="submit-box">
  34. <u-button @click="login" :loading="loading" loadingText="登录中..." shape="circle" type="primary">确定</u-button>
  35. </view>
  36. <view class="agree">
  37. <u-checkbox-group v-model="agree">
  38. <u-checkbox shape="circle" name="1" label="我已阅读并同意" />
  39. </u-checkbox-group>
  40. <view @click="clickAgreement('用户协议')" class="agreement">《用户协议》</view>
  41. <view @click="clickAgreement('隐私政策')" class="agreement">《隐私政策》</view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import { getSmsCodeByPhone } from '@/api/login'
  47. const MOBILE_REG = /^[1][3-9][0-9]{9}$/
  48. const SMS_REG = /^\d{6}$/
  49. export default {
  50. data() {
  51. return {
  52. code:'', // 短信标识
  53. mobile:'', // 手机号码
  54. captcha:'', // 验证码
  55. agree: [],
  56. tips: '',
  57. seconds: 120,
  58. loading:false,
  59. }
  60. },
  61. computed:{
  62. checked(){
  63. return this.agree && this.agree.length > 0
  64. }
  65. },
  66. methods: {
  67. async getCode() {
  68. if(!MOBILE_REG.test(this.mobile)){
  69. return uni.$u.toast('请输入合法手机号')
  70. }
  71. if (this.$refs.uCode.canGetCode) {
  72. const res = await getSmsCodeByPhone({mobile:this.mobile})
  73. if(res.code === 'OK'){
  74. uni.$u.toast('短信验证码已发送,请注意查收')
  75. this.$refs.uCode.start()
  76. this.code = res.data.id
  77. }else{
  78. uni.$u.toast(res.message)
  79. }
  80. }
  81. },
  82. login() {
  83. if(!this.checked){
  84. return uni.$u.toast('请阅读并勾选底部协议')
  85. }
  86. if(!MOBILE_REG.test(this.mobile)){
  87. return uni.$u.toast('请输入合法手机号')
  88. }
  89. // if(!SMS_REG.test(this.captcha)){
  90. // return uni.$u.toast('请输入6位数字验证码')
  91. // }
  92. const data = {
  93. mobile:this.mobile,
  94. captcha:this.captcha,
  95. code:this.code,
  96. }
  97. // this.loading = true
  98. this.$store.dispatch('LoginBySmsCode', data)
  99. .then(() => {
  100. debugger
  101. // this.$store.dispatch('SwitchIdentity','CUSTOMER')
  102. this.$Router.pushTab('/pages/client/tabBar/home/index');
  103. // this.loading = false;
  104. this.$store.dispatch('GetUserInfo')
  105. uni.$u.toast('登录成功');
  106. })
  107. .catch(() => {
  108. // this.loading = false;
  109. uni.$u.toast('登录失败');
  110. });
  111. },
  112. codeChange(text) {
  113. this.tips = text;
  114. },
  115. },
  116. }
  117. </script>
  118. <style scoped lang="scss">
  119. .t-login {
  120. margin: 0 auto;
  121. font-size: 28rpx;
  122. color: #000;
  123. padding: 0 20rpx;
  124. background-color: #f2f5f9;
  125. .t-b {
  126. text-align: left;
  127. font-size: 46rpx;
  128. color: #000;
  129. padding: 150rpx 0 30rpx 0;
  130. font-weight: bold;
  131. }
  132. .t-b2 {
  133. text-align: left;
  134. font-size: 32rpx;
  135. color: #aaaaaa;
  136. padding: 0rpx 0 120rpx 0;
  137. }
  138. .form-box{
  139. background-color:#fff;
  140. padding:10rpx 20rpx;
  141. box-sizing: border-box;
  142. border-radius:20rpx;
  143. .line{
  144. height:1rpx;
  145. background-color:lightgray;
  146. }
  147. }
  148. .submit-box{
  149. margin: 40rpx 0;
  150. }
  151. }
  152. .agree {
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. font-size: 27rpx;
  157. margin-top: 20rpx;
  158. .agreement {
  159. color: #3c9cff;
  160. cursor: pointer;
  161. }
  162. }
  163. </style>