login.vue 3.8 KB

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