login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="container">
  3. <view class="t-b">欢迎登录车旅程!</view>
  4. <view class="t-b2">欢迎使用车旅程,为你提供便捷服务</view>
  5. <!-- 中间登录注册按钮 -->
  6. <view class="login-btn-wrap">
  7. <u-button v-if="!checked" shape="circle" type="primary" :customStyle="buttonStyleTop" @click="checkAgree">
  8. 微信用户一键登录
  9. </u-button>
  10. <u-button v-else shape="circle" type="primary" :loading="loading" loadingText="登录中..."
  11. :customStyle="buttonStyleTop" open-type="getPhoneNumber" @getphonenumber="login">
  12. 微信用户一键登录
  13. </u-button>
  14. <u-button shape="circle" :customStyle="buttonStyleButton" @tap="$Router.push('/pages/login/phoneLogin')">
  15. 手机号登录/注册
  16. </u-button>
  17. </view>
  18. <br />
  19. <!-- 底部协议 -->
  20. <view class="agree">
  21. <u-checkbox-group v-model="agree">
  22. <u-checkbox shape="circle" name="1" label="我已阅读并同意" />
  23. </u-checkbox-group>
  24. <view @click="$Router.push('/pages/webview/index?target=http://8.137.122.65:88/用户协议.html')"
  25. class="agreement">
  26. 《用户协议》</view>
  27. <view @click="$Router.push('/pages/webview/index?target=http://8.137.122.65:88/隐私政策.html')"
  28. class="agreement">
  29. 《隐私政策》</view>
  30. </view>
  31. <!-- 第三方 -->
  32. <view class="t-f"><text>————— 第三方账号登录 —————</text></view>
  33. <view class="t-e cl">
  34. <view class="t-g" @click="$Router.push('/pages/login/phoneLogin')">
  35. <image src="@/static//icon/phone.png" />
  36. </view>
  37. <view class="t-g">
  38. <image src="@/static//icon/qq.png" />
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. getWxLoginCode
  46. } from '@/api/login.js';
  47. export default {
  48. data() {
  49. return {
  50. agree: [],
  51. code: '',
  52. mobile: '', // 手机号密文并非真实手机号
  53. isUserAgreement: false,
  54. loading: false,
  55. title: '',
  56. buttonStyleTop: {
  57. 'font-size': '28rpx',
  58. background: '#5677fc',
  59. color: '#fff',
  60. height: '90rpx',
  61. 'line-height': '90rpx',
  62. 'border-radius': '50rpx',
  63. 'box-shadow': '0 5px 7px 0 rgba(86, 119, 252, 0.2)',
  64. marginTop: '30rpx',
  65. },
  66. buttonStyleButton: {
  67. 'font-size': '28rpx',
  68. background: '#fff',
  69. color: '#333',
  70. height: '90rpx',
  71. 'line-height': '90rpx',
  72. 'border-radius': '50rpx',
  73. 'box-shadow': '0 5px 7px 0 rgba(235, 237, 245, 0.2)',
  74. marginTop: '30rpx',
  75. },
  76. };
  77. },
  78. computed: {
  79. checked() {
  80. return this.agree && this.agree.length > 0;
  81. },
  82. },
  83. methods: {
  84. onLoad: function(options) {
  85. console.log('options========>', options.q);
  86. if (options.q) {
  87. const urlString = decodeURIComponent(options.q)
  88. const pathSegments = urlString.split('/');
  89. const promoterId = pathSegments[pathSegments.length - 1];
  90. this.$store.commit('SET_INVITATIONCODE', promoterId)
  91. }
  92. },
  93. checkAgree() {
  94. if (!this.checked) {
  95. return uni.$u.toast('请阅读并勾选底部协议');
  96. }
  97. },
  98. //点击微信用户一键登录
  99. async login(e) {
  100. if (e.detail.errMsg != 'getPhoneNumber:ok') {
  101. return uni.$u.toast('您已取消登录');
  102. }
  103. this.mobile = e.detail.code;
  104. this.code = await getWxLoginCode();
  105. if (!this.code || !this.mobile) {
  106. this.loading = false;
  107. uni.$u.toast('微信授权失败,请稍后重试');
  108. return;
  109. }
  110. this.loading = true;
  111. const data = {
  112. code: this.code,
  113. mobile: this.mobile,
  114. };
  115. this.$store.dispatch('LoginByWxCode', data).then(() => {
  116. // this.$store.dispatch('SwitchIdentity', 'CUSTOMER');
  117. this.$Router.pushTab('/pages/tabbar/home');
  118. this.loading = false;
  119. this.$store.dispatch('GetUserInfo');
  120. uni.$u.toast('登录成功');
  121. })
  122. .catch(err => {
  123. this.loading = false;
  124. uni.$u.toast(`${err.message}`);
  125. });
  126. },
  127. confirmUserAgreement() {
  128. // 确认按钮点击事件处理
  129. if (!this.checked.length) {
  130. this.showUserAgreementDialog = true;
  131. } else {
  132. this.showPrivacyPolicyDialog = true;
  133. }
  134. // 在确认按钮点击后执行页面跳转的代码
  135. this.$Router.back();
  136. },
  137. //点击用户协议
  138. clickAgreement(title) {
  139. this.show = true; //打开弹框
  140. this.title = title; //赋值标题
  141. },
  142. //点击用户协议弹框内的确定
  143. handleConfirm() {
  144. this.show = false; //关闭弹框
  145. },
  146. },
  147. };
  148. </script>
  149. <style scoped lang="scss">
  150. .container {
  151. height: 100vh;
  152. padding: 0 70rpx;
  153. background-color: #f2f5f9;
  154. background-color: #fff;
  155. padding-top: 150rpx;
  156. box-sizing: border-box;
  157. .t-b {
  158. text-align: left;
  159. font-size: 46rpx;
  160. color: #000;
  161. padding: 150rpx 0 30rpx 0;
  162. font-weight: bold;
  163. }
  164. .t-b2 {
  165. text-align: left;
  166. font-size: 32rpx;
  167. color: #aaaaaa;
  168. padding: 0rpx 0 80rpx 0;
  169. }
  170. .login-btn-wrap {
  171. margin-top: 50rpx;
  172. width: 100%;
  173. }
  174. }
  175. .agree {
  176. display: flex;
  177. justify-content: center;
  178. align-items: center;
  179. font-size: 27rpx;
  180. margin-top: 20rpx;
  181. .agreement {
  182. color: #3c9cff;
  183. cursor: pointer;
  184. }
  185. }
  186. .t-f {
  187. text-align: center;
  188. margin: 200rpx 0 0 0;
  189. color: #666;
  190. text {
  191. margin-left: 20rpx;
  192. color: #aaaaaa;
  193. font-size: 27rpx;
  194. }
  195. }
  196. .t-e {
  197. text-align: center;
  198. width: 250rpx;
  199. margin: 20rpx auto 0;
  200. .t-g {
  201. float: left;
  202. width: 50%;
  203. }
  204. image {
  205. width: 50rpx;
  206. height: 50rpx;
  207. }
  208. }
  209. </style>