Login.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="loginBox">
  3. <image src="../../static/image/logo.png" class="logo"></image>
  4. <view class="logoText">
  5. 快报嗨享平台
  6. </view>
  7. <view class="btnBox">
  8. <view class="isShowGetPhone" v-if="!isAgree" @click="valiAgree">一键授权登录</view>
  9. <button class="loginBtn" v-else open-type="getPhoneNumber" @getphonenumber="login">
  10. 一键授权登录
  11. </button>
  12. </view>
  13. <view class="tips">
  14. <checkbox :value="isAgree" @click="agreeChange()" :checked="isAgree" />
  15. <view>
  16. 我已阅读并同意
  17. <text class="primaryText" @click="toUserArgeement()">《服务协议》</text>
  18. <text class="primaryText" @click="toPrivacyPolicy()">《隐私政策》</text>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import {
  25. mapMutations
  26. } from 'vuex';
  27. import {
  28. getMobile
  29. } from '../../network/api.js';
  30. export default {
  31. data() {
  32. return {
  33. isAgree: false
  34. };
  35. },
  36. methods: {
  37. ...mapMutations(['setUserInfo']),
  38. agreeChange() {
  39. this.isAgree = !this.isAgree;
  40. },
  41. toUserArgeement() {
  42. uni.navigateTo({
  43. url: '/pages/userAgreement/userAgreement'
  44. });
  45. },
  46. toPrivacyPolicy() {
  47. uni.navigateTo({
  48. url: '/pages/privacyPolicy/privacyPolicy'
  49. });
  50. },
  51. valiAgree() {
  52. if (!this.isAgree) {
  53. uni.showToast({
  54. title: '请先同意《服务协议》与《隐私政策》',
  55. duration: 2000,
  56. icon: 'none'
  57. });
  58. return;
  59. }
  60. },
  61. async login(e) {
  62. if (e.detail.errMsg !== 'getPhoneNumber:ok') return
  63. if (e.detail.iv) {
  64. let data = {
  65. departmentId: 1,
  66. code: e.detail.code
  67. };
  68. console.log(data);
  69. let res = await getMobile(data);
  70. let result = res.data;
  71. if (result.state == 200) {
  72. let userInfo = {
  73. phone: result.data.phoneNumber,
  74. };
  75. uni.setStorageSync('userInfo', JSON.stringify(userInfo));
  76. this.setUserInfo(userInfo);
  77. uni.showToast({
  78. title: '登录成功',
  79. icon: 'none'
  80. });
  81. setTimeout(() => {
  82. uni.navigateBack();
  83. }, 300);
  84. } else {
  85. console.log(result)
  86. uni.showToast({
  87. title: result.message,
  88. icon: 'none'
  89. });
  90. }
  91. } else {
  92. uni.showToast({
  93. title: '授权失败',
  94. icon: 'none'
  95. });
  96. }
  97. },
  98. onAuthError(e) {
  99. uni.showToast({
  100. title: '您已拒绝授权~',
  101. icon: 'none'
  102. });
  103. }
  104. }
  105. };
  106. </script>
  107. <style>
  108. /* #ifdef H5 */
  109. uni-checkbox .uni-checkbox-input {
  110. border: none !important;
  111. }
  112. uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
  113. color: #ff6903;
  114. }
  115. .uni-checkbox-input.uni-checkbox-input-checked {
  116. border: none !important;
  117. }
  118. /* #endif */
  119. /* 微信中样式 */
  120. /* #ifdef APP-PLUS ||MP-WEIXIN */
  121. checkbox .wx-checkbox-input {
  122. border-radius: 50% !important;
  123. }
  124. checkbox .wx-checkbox-input-disabled {
  125. background: #fff !important;
  126. border-radius: 50% !important;
  127. }
  128. checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  129. background-color: #2468f2;
  130. color: #ffffff;
  131. }
  132. .wx-checkbox-input.wx-checkbox-input-checked {
  133. border-radius: 50% !important;
  134. }
  135. /* #endif */
  136. </style>
  137. <style lang="scss" scoped>
  138. .loginBox {
  139. width: 100%;
  140. height: 100vh;
  141. box-sizing: border-box;
  142. padding: 100px 0 63px 0;
  143. display: flex;
  144. flex-direction: column;
  145. align-items: center;
  146. .logo {
  147. width: 150px;
  148. height: 150px;
  149. }
  150. .logoText {
  151. margin-top: 30px;
  152. font-size: 18px;
  153. }
  154. .btnBox {
  155. position: relative;
  156. width: 526rpx;
  157. height: 44px;
  158. display: flex;
  159. margin-top: auto;
  160. margin-bottom: 50px;
  161. .loginBtn {
  162. width: 526rpx;
  163. height: 44px;
  164. text-align: center;
  165. line-height: 44px;
  166. color: #ffffff;
  167. border-radius: 50px;
  168. background-color: #2468f2;
  169. font-size: 16px;
  170. }
  171. .isShowGetPhone {
  172. position: absolute;
  173. top: 0;
  174. right: 0;
  175. bottom: 0;
  176. left: 0;
  177. width: 526rpx;
  178. height: 44px;
  179. line-height: 44px;
  180. text-align: center;
  181. color: #ffffff;
  182. border-radius: 50px;
  183. background-color: #2468f2;
  184. z-index: 100;
  185. font-size: 16px;
  186. }
  187. }
  188. .tips {
  189. display: flex;
  190. }
  191. .primaryText {
  192. color: #2468f2;
  193. }
  194. }
  195. </style>