index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="container">
  3. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" title="登录"></u-navbar>
  4. <view class="flex login">
  5. <view class="flex login-image">
  6. <image src="../../static/public/logo.png" mode=""></image>
  7. <view class="login-image-txt">盲票</view>
  8. </view>
  9. <view class="login-btn">
  10. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" v-if="checked">微信登录</button>
  11. <button @click="getPhoneNumber" v-else>微信登录</button>
  12. </view>
  13. <view class="flex login-code" @click="toCode">手机号登录/注册</view>
  14. </view>
  15. <view class="footer-fixed">
  16. <view class="flex about">
  17. <view class="checked">
  18. <u-checkbox-group>
  19. <u-checkbox :value="checked" :checked="checked" size="20" shape="circle" activeColor="#E96737"
  20. @change="changeChecked"></u-checkbox>
  21. </u-checkbox-group>
  22. </view>
  23. <view class="txt">登录代表您已同意</view>
  24. <navigator hover-class="none" class="txt-about" url="/packageOther/about/protect">《用户使用协议》</navigator>
  25. <navigator hover-class="none" class="txt-about" url="/packageOther/about/conceal">、《隐私保护声明》</navigator>
  26. </view>
  27. </view>
  28. <auth :auth-show="authShow" :auth-token="token" @close="authClose" />
  29. </view>
  30. </template>
  31. <script>
  32. import $http from '@/utils/request.js'
  33. import log from '@/common/log.js'
  34. import Auth from '../../components/auth/auth.vue'
  35. export default {
  36. components: {
  37. Auth
  38. },
  39. data() {
  40. return {
  41. authShow: false,
  42. token: '',
  43. checked: true
  44. };
  45. },
  46. methods: {
  47. getPhoneNumber(e) {
  48. let _this = this
  49. if (!_this.checked) {
  50. uni.$u.toast('请阅读并勾选底部协议');
  51. return
  52. }
  53. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  54. uni.showLoading({
  55. title: '登录中'
  56. });
  57. if (e.detail & e.detail.code) {
  58. $http.post('/api/v1/mp/user/wxauth/mobile', {
  59. ...e.detail,
  60. identity: 1,
  61. noToken: true
  62. }).then(res => {
  63. uni.hideLoading();
  64. if (res.code == 0) {
  65. uni.setStorageSync('token', res.token)
  66. _this.getBaseInfo()
  67. } else {
  68. uni.getSystemInfo({
  69. success(res) {
  70. log.info(
  71. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  72. )
  73. }
  74. })
  75. }
  76. }).catch(() => {
  77. uni.hideLoading();
  78. uni.getSystemInfo({
  79. success(res) {
  80. log.info(
  81. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  82. )
  83. }
  84. })
  85. })
  86. } else {
  87. uni.login({
  88. success(res) {
  89. $http.post('/api/v1/mp/user/wxauth/mobile', {
  90. ...e.detail,
  91. loginCode: res.code,
  92. identity: 1,
  93. noToken: true
  94. }).then(res => {
  95. uni.hideLoading();
  96. if (res.code == 0) {
  97. uni.setStorageSync('token', res.token)
  98. _this.getBaseInfo()
  99. } else {
  100. uni.getSystemInfo({
  101. success(res) {
  102. log.info(
  103. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  104. )
  105. }
  106. })
  107. }
  108. }).catch(() => {
  109. uni.hideLoading();
  110. uni.getSystemInfo({
  111. success(res) {
  112. log.info(
  113. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  114. )
  115. }
  116. })
  117. })
  118. }
  119. })
  120. }
  121. }
  122. },
  123. // 关闭授权
  124. authClose() {
  125. this.authShow = false
  126. setTimeout(() => {
  127. uni.navigateBack({
  128. delta: 1
  129. })
  130. }, 500)
  131. },
  132. changeChecked(e) {
  133. this.checked = e
  134. },
  135. toCode() {
  136. if (!this.checked) {
  137. uni.$u.toast('请阅读并勾选底部协议');
  138. return
  139. }
  140. uni.navigateTo({
  141. url: '/pages/login/code'
  142. })
  143. },
  144. getBaseInfo() {
  145. $http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
  146. uni.hideLoading();
  147. if (res.code == 0) {
  148. uni.setStorageSync('userInfo', res.data)
  149. if (res.data.openId) {
  150. uni.$u.toast('登录成功');
  151. setTimeout(() => {
  152. uni.navigateBack({
  153. delta: 1
  154. })
  155. }, 500)
  156. } else {
  157. this.authShow = true
  158. }
  159. }
  160. }).catch(() => {
  161. uni.hideLoading();
  162. })
  163. },
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .container {
  169. height: 100vh;
  170. width: 100%;
  171. }
  172. .login {
  173. flex-direction: column;
  174. &-image {
  175. flex-direction: column;
  176. padding: 128rpx 0 200rpx;
  177. image {
  178. width: 296rpx;
  179. height: 296rpx;
  180. margin-bottom: 28rpx;
  181. }
  182. &-txt {
  183. text-align: center;
  184. line-height: 40rpx;
  185. font-weight: bold;
  186. margin-bottom: 20rpx;
  187. font-size: 28rpx;
  188. }
  189. }
  190. &-txt {
  191. text-align: center;
  192. line-height: 40rpx;
  193. font-weight: bold;
  194. margin-bottom: 20rpx;
  195. }
  196. &-title {
  197. text-align: center;
  198. font-size: 24rpx;
  199. font-weight: normal;
  200. margin-bottom: 50rpx;
  201. }
  202. &-btn {
  203. margin-bottom: 44rpx;
  204. button {
  205. width: 600rpx;
  206. height: 80rpx;
  207. line-height: 80rpx;
  208. border-radius: 40rpx;
  209. background-color: rgba(235, 112, 9, 100);
  210. color: rgba(255, 255, 255, 100);
  211. text-align: center;
  212. font-size: 28rpx;
  213. }
  214. }
  215. &-code {
  216. text-align: center;
  217. color: rgba(242, 113, 32, 100);
  218. }
  219. }
  220. .footer-fixed {
  221. position: fixed;
  222. bottom: var(--window-bottom);
  223. left: 0;
  224. right: 0;
  225. z-index: 11;
  226. background: #fff;
  227. // 设置ios刘海屏底部横线安全区域
  228. padding-bottom: constant(safe-area-inset-bottom);
  229. padding-bottom: env(safe-area-inset-bottom);
  230. .about {
  231. padding: 60rpx 0;
  232. font-size: 24rpx;
  233. .txt-about {
  234. color: #007aff;
  235. }
  236. }
  237. }
  238. </style>