mobilelogin.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="">
  3. <!-- 顶部导航 -->
  4. <fa-navbar title="登录"></fa-navbar>
  5. <view class="login">
  6. <view class="u-m-t-50">
  7. <u-form :model="form" :rules="rules" ref="uForm" :errorType="errorType">
  8. <u-form-item :label-position="labelPosition" label="手机号码:" prop="mobile" label-width="120">
  9. <u-input :border="border" placeholder="请输入手机号码" v-model="form.mobile" type="number"></u-input>
  10. </u-form-item>
  11. <u-form-item :label-position="labelPosition" label="验证码:" prop="captcha" label-width="120">
  12. <u-input :border="border" placeholder="请输入验证码" v-model="form.captcha" type="text"></u-input>
  13. <u-button hover-class="none" type="primary" slot="right" :custom-style="{ backgroundColor: theme.bgColor, color: theme.color }" size="mini" @click="getCode">
  14. {{ codeTips }}
  15. </u-button>
  16. </u-form-item>
  17. </u-form>
  18. </view>
  19. <view class="u-m-t-80">
  20. <u-button hover-class="none" type="primary" :custom-style="{ backgroundColor: theme.bgColor, color: theme.color }" shape="circle" @click="goLogin">登录</u-button>
  21. </view>
  22. <view class="u-flex u-row-right u-tips-color u-m-t-30 u-p-20"><view class="" @click="goPage">账号登录</view></view>
  23. <view class="u-text-center other" v-if="isThreeLogin">
  24. <u-grid :col="1" :border="false">
  25. <u-grid-item @click="goThreeLogin">
  26. <u-icon name="weixin-fill" color="#53c240" :size="50"></u-icon>
  27. <view class="grid-text">微信</view>
  28. </u-grid-item>
  29. </u-grid>
  30. </view>
  31. </view>
  32. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  33. </view>
  34. </template>
  35. <script>
  36. import {loginfunc} from '@/common/fa.mixin.js'
  37. export default {
  38. mixins:[loginfunc],
  39. onLoad() {
  40. // #ifdef MP-WEIXIN || APP-PLUS
  41. this.isThreeLogin = true;
  42. // #endif
  43. // #ifdef H5
  44. if (this.$util.isWeiXinBrowser()) {
  45. this.isThreeLogin = true;
  46. }
  47. // #endif
  48. },
  49. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  50. onReady() {
  51. this.$refs.uForm.setRules(this.rules);
  52. },
  53. data() {
  54. return {
  55. labelPosition: 'top',
  56. border: false,
  57. errorType: ['message'],
  58. form: {
  59. mobile: '',
  60. captcha: ''
  61. },
  62. rules: {
  63. mobile: [
  64. {
  65. required: true,
  66. message: '请输入手机号码',
  67. // 可以单个或者同时写两个触发验证方式
  68. trigger: ['change', 'blur']
  69. },
  70. {
  71. // 自定义验证函数,见上说明
  72. validator: (rule, value, callback) => {
  73. return this.$u.test.mobile(value);
  74. },
  75. message: '手机号码不正确',
  76. trigger: ['change', 'blur']
  77. }
  78. ],
  79. captcha: [
  80. {
  81. required: true,
  82. message: '请输入验证码',
  83. trigger: 'change'
  84. }
  85. ]
  86. },
  87. isThreeLogin: false,
  88. codeTips: ''
  89. };
  90. },
  91. methods: {
  92. codeChange(text) {
  93. this.codeTips = text;
  94. },
  95. // 获取验证码
  96. getCode: async function() {
  97. if (!this.$u.test.mobile(this.form.mobile)) {
  98. this.$u.toast('手机号码格式不正确!');
  99. return;
  100. }
  101. if (this.$refs.uCode.canGetCode) {
  102. let res = await this.$api.getSmsSend({
  103. mobile: this.form.mobile,
  104. event: 'mobilelogin'
  105. });
  106. this.$u.toast(res.msg);
  107. if(res.code){
  108. this.$refs.uCode.start();
  109. }
  110. } else {
  111. this.$u.toast('倒计时结束后再发送');
  112. }
  113. },
  114. goPage(index) {
  115. this.$Router.push('/pages/login/login');
  116. },
  117. goThreeLogin: async function() {
  118. // #ifdef MP-WEIXIN
  119. this.$Router.push('/pages/login/wxlogin');
  120. // #endif
  121. // #ifdef H5
  122. this.goAuth();
  123. // #endif
  124. // #ifdef APP-PLUS
  125. this.goAppLogin();
  126. // #endif
  127. },
  128. goLogin: function() {
  129. this.$refs.uForm.validate(async valid => {
  130. if (valid) {
  131. if (this.vuex_wx_uid) {
  132. this.form.wx_user_id = this.vuex_wx_uid;
  133. }
  134. let res = await this.$api.mobilelogin(this.form);
  135. if (!res.code) {
  136. this.$u.toast(res.msg);
  137. return;
  138. }
  139. this.$u.vuex('vuex_token', res.data.token);
  140. this.success(1);
  141. } else {
  142. this.$u.toast('验证失败');
  143. }
  144. });
  145. }
  146. }
  147. };
  148. </script>
  149. <style>
  150. page {
  151. background-color: #ffffff;
  152. }
  153. .login {
  154. padding: 80rpx 100rpx 0 100rpx;
  155. }
  156. .other {
  157. position: absolute;
  158. width: 100%;
  159. left: 0;
  160. bottom: 40rpx;
  161. }
  162. </style>