login.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="loginPage">
  3. <image class="bk" :src="$fileUrl() + '/loginBk.png'" mode="widthFix"></image>
  4. <view class="box">
  5. <image class="logo" :src="$fileUrl() + '/logo.png'" mode="widthFix"></image>
  6. <button @click="wxLogin" class="button" type="default">微信授权登录</button>
  7. <view class="textButton" @click="noLogin">暂不登录</view>
  8. <view class="tip">
  9. <radio :checked="checkbox1" @click="checkbox1 = !checkbox1" style="transform: scale(0.6)" color="#333333" />
  10. <view class="text">
  11. 我已阅读并同意
  12. <span class="textColor2">《用户协议》</span>
  13. <span class="textColor2">《隐私政策》</span>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import { loginByWeixinApi } from '@/api/user.js'
  21. import { up } from '@/api/monitor'
  22. export default {
  23. data() {
  24. return {
  25. checkbox1: false,
  26. }
  27. },
  28. onShow() {
  29. console.log(getCurrentPages(), '宋宋宋宋宋宋宋')
  30. },
  31. methods: {
  32. noLogin() {
  33. console.log('sssssssss')
  34. wx.switchTab({
  35. url: '/pages/index/index',
  36. })
  37. },
  38. wxLogin: function (e) {
  39. if (!this.checkbox1) {
  40. wx.showToast({
  41. title: '请先阅读并同意《用户协议》',
  42. icon: 'none',
  43. })
  44. }
  45. let _this = this
  46. wx.getUserProfile({
  47. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  48. success: res => {
  49. console.log(res, 'res111')
  50. _this.getWXCode(res.userInfo)
  51. },
  52. fail: () => {
  53. console.log('微信登录失败')
  54. // util.showErrorToast('微信登录失败');
  55. },
  56. })
  57. },
  58. getWXCode(userInfo) {
  59. let _this = this
  60. wx.login({
  61. success: function (res) {
  62. console.log(res, 'res222')
  63. if (res.code) {
  64. let params = {
  65. code: res.code,
  66. userInfo: userInfo,
  67. }
  68. _this.executeLoginApi(params)
  69. }
  70. },
  71. fail: function (err) {
  72. reject(err)
  73. },
  74. })
  75. },
  76. executeLoginApi(params) {
  77. let _this = this
  78. console.log(222)
  79. let inviteId = getApp().globalData.inviteId
  80. if (inviteId) {
  81. console.log('有邀请id', inviteId)
  82. params.inviteId = inviteId
  83. }
  84. loginByWeixinApi(params).then(res => {
  85. console.log('调用登录api', res)
  86. //存储用户信息
  87. wx.setStorageSync('userInfo', res.data.userInfo)
  88. wx.setStorageSync('token', res.data.token)
  89. wx.setStorageSync('userId', res.data.userId)
  90. getApp().globalData.hasLogin = true
  91. up()
  92. let routerList = getCurrentPages()
  93. let index = 0
  94. for (var i = 0; i < routerList.length; i++) {
  95. if (routerList[i].route == 'pages/login/login') {
  96. index += 1
  97. }
  98. }
  99. wx.navigateBack({
  100. delta: index,
  101. })
  102. })
  103. },
  104. },
  105. }
  106. </script>
  107. <style scoped lang="scss">
  108. .loginPage {
  109. background: #e6f2ff;
  110. height: 100vh;
  111. overflow: hidden;
  112. // background: url(https://mall.rongtongh.cn/storage/img/ka.jpeg) no-repeat;
  113. // background-size: 100% 100%;
  114. .bk {
  115. height: 100%;
  116. width: 100%;
  117. }
  118. .box {
  119. position: absolute;
  120. bottom: 15%;
  121. display: flex;
  122. align-items: center;
  123. justify-content: center;
  124. flex-direction: column;
  125. width: 100%;
  126. // background-color: rgba(255, 255, 255, 0.7);
  127. // padding: 30px 10px;
  128. .logo {
  129. width: 94px;
  130. height: 94px;
  131. margin-bottom: 20vh;
  132. }
  133. .tip {
  134. display: flex;
  135. justify-content: center;
  136. align-items: center;
  137. margin-bottom: 10px;
  138. color: #000;
  139. font-size: 12px;
  140. .checkBox {
  141. // font-size: 12px;
  142. height: 12px;
  143. width: 12px;
  144. }
  145. }
  146. .button {
  147. height: 48px;
  148. width: calc(100% - 60px);
  149. border-radius: 24px;
  150. line-height: 48px;
  151. font-size: 14px;
  152. background: #fea200;
  153. color: #fff;
  154. margin-bottom: 20px;
  155. }
  156. .textButton {
  157. font-size: 14px;
  158. color: #666;
  159. margin-bottom: 75px;
  160. }
  161. }
  162. }
  163. </style>