index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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/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="/pages/about/protect">《用户使用协议》</navigator>
  25. <navigator hover-class="none" class="txt-about" url="/pages/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: false
  44. };
  45. },
  46. onShow() {
  47. this.checked = false
  48. },
  49. methods: {
  50. getPhoneNumber(e) {
  51. let _this = this
  52. if (!_this.checked) {
  53. uni.$u.toast('请阅读并勾选底部协议');
  54. return
  55. }
  56. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  57. uni.showLoading({
  58. title: '登录中'
  59. });
  60. if (e.detail & e.detail.code) {
  61. $http.post('/api/v1/mp/user/wxauth/mobile', {
  62. ...e.detail,
  63. identity: 1,
  64. noToken: true
  65. }).then(res => {
  66. uni.hideLoading();
  67. if (res.code == 0) {
  68. uni.setStorageSync('token', res.token)
  69. _this.getBaseInfo()
  70. } else {
  71. uni.getSystemInfo({
  72. success(res) {
  73. log.info(
  74. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  75. )
  76. }
  77. })
  78. }
  79. }).catch(() => {
  80. uni.hideLoading();
  81. uni.getSystemInfo({
  82. success(res) {
  83. log.info(
  84. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  85. )
  86. }
  87. })
  88. })
  89. } else {
  90. uni.login({
  91. success(res) {
  92. $http.post('/api/v1/mp/user/wxauth/mobile', {
  93. ...e.detail,
  94. loginCode: res.code,
  95. identity: 1,
  96. noToken: true
  97. }).then(res => {
  98. uni.hideLoading();
  99. if (res.code == 0) {
  100. uni.setStorageSync('token', res.token)
  101. _this.getBaseInfo()
  102. } else {
  103. uni.getSystemInfo({
  104. success(res) {
  105. log.info(
  106. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  107. )
  108. }
  109. })
  110. }
  111. }).catch(() => {
  112. uni.hideLoading();
  113. uni.getSystemInfo({
  114. success(res) {
  115. log.info(
  116. `错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`
  117. )
  118. }
  119. })
  120. })
  121. }
  122. })
  123. }
  124. }
  125. },
  126. // 关闭授权
  127. authClose() {
  128. this.authShow = false
  129. setTimeout(() => {
  130. uni.navigateBack({
  131. delta: 1
  132. })
  133. }, 500)
  134. },
  135. changeChecked(e) {
  136. this.checked = e
  137. },
  138. toCode() {
  139. if (!this.checked) {
  140. uni.$u.toast('请阅读并勾选底部协议');
  141. return
  142. }
  143. uni.navigateTo({
  144. url: '/pages/login/code'
  145. })
  146. },
  147. getBaseInfo() {
  148. $http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
  149. uni.hideLoading();
  150. if (res.code == 0) {
  151. uni.setStorageSync('userInfo', res.data)
  152. if (res.data.openId) {
  153. uni.$u.toast('登录成功');
  154. setTimeout(() => {
  155. uni.navigateBack({
  156. delta: 1
  157. })
  158. }, 500)
  159. } else {
  160. this.authShow = true
  161. }
  162. }
  163. }).catch(() => {
  164. uni.hideLoading();
  165. })
  166. },
  167. }
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. .container {
  172. height: 100vh;
  173. width: 100%;
  174. }
  175. .login {
  176. flex-direction: column;
  177. &-image {
  178. flex-direction: column;
  179. padding: 128rpx 0 200rpx;
  180. image {
  181. width: 296rpx;
  182. height: 296rpx;
  183. margin-bottom: 28rpx;
  184. }
  185. &-txt {
  186. text-align: center;
  187. line-height: 40rpx;
  188. font-weight: bold;
  189. margin-bottom: 20rpx;
  190. font-size: 28rpx;
  191. }
  192. }
  193. &-txt {
  194. text-align: center;
  195. line-height: 40rpx;
  196. font-weight: bold;
  197. margin-bottom: 20rpx;
  198. }
  199. &-title {
  200. text-align: center;
  201. font-size: 24rpx;
  202. font-weight: normal;
  203. margin-bottom: 50rpx;
  204. }
  205. &-btn {
  206. margin-bottom: 44rpx;
  207. button {
  208. width: 600rpx;
  209. height: 80rpx;
  210. line-height: 80rpx;
  211. border-radius: 40rpx;
  212. background-color: rgba(235, 112, 9, 100);
  213. color: rgba(255, 255, 255, 100);
  214. text-align: center;
  215. font-size: 28rpx;
  216. }
  217. }
  218. &-code {
  219. text-align: center;
  220. color: rgba(242, 113, 32, 100);
  221. }
  222. }
  223. .footer-fixed {
  224. position: fixed;
  225. bottom: var(--window-bottom);
  226. left: 0;
  227. right: 0;
  228. z-index: 11;
  229. background: #fff;
  230. // 设置ios刘海屏底部横线安全区域
  231. padding-bottom: constant(safe-area-inset-bottom);
  232. padding-bottom: env(safe-area-inset-bottom);
  233. .about {
  234. padding: 60rpx 0;
  235. font-size: 24rpx;
  236. .txt-about {
  237. color: #007aff;
  238. }
  239. }
  240. }
  241. </style>