login.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="loginPage">
  3. <image class="bk" :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/loginBk.png'" mode="widthFix"></image>
  4. <view class="box">
  5. <image class="logo" :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/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" @click="$navigateTo('/pages/userAgreement/userAgreement')">《用户协议》</span>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import { loginByWeixinApi } from '@/api/user.js'
  20. import { up } from '@/api/monitor'
  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. up()
  91. let routerList = getCurrentPages()
  92. let index = 0
  93. for (var i = 0; i < routerList.length; i++) {
  94. if (routerList[i].route == 'pages/login/login') {
  95. index += 1
  96. }
  97. }
  98. wx.navigateBack({
  99. delta: index,
  100. })
  101. })
  102. },
  103. },
  104. }
  105. </script>
  106. <style scoped lang="scss">
  107. .loginPage {
  108. background: #e6f2ff;
  109. height: 100vh;
  110. overflow: hidden;
  111. // background: url(https://mall.rongtongh.cn/storage/img/ka.jpeg) no-repeat;
  112. // background-size: 100% 100%;
  113. .bk {
  114. height: 100%;
  115. width: 100%;
  116. }
  117. .box {
  118. position: absolute;
  119. bottom: 15%;
  120. display: flex;
  121. align-items: center;
  122. justify-content: center;
  123. flex-direction: column;
  124. width: 100%;
  125. // background-color: rgba(255, 255, 255, 0.7);
  126. // padding: 30px 10px;
  127. .logo {
  128. width: 94px;
  129. height: 94px;
  130. margin-bottom: 20vh;
  131. }
  132. .tip {
  133. display: flex;
  134. justify-content: center;
  135. align-items: center;
  136. margin-bottom: 10px;
  137. color: #000;
  138. font-size: 12px;
  139. .checkBox {
  140. // font-size: 12px;
  141. height: 12px;
  142. width: 12px;
  143. }
  144. }
  145. .button {
  146. height: 48px;
  147. width: calc(100% - 60px);
  148. border-radius: 24px;
  149. line-height: 48px;
  150. font-size: 14px;
  151. background: #fea200;
  152. color: #fff;
  153. margin-bottom: 20px;
  154. }
  155. .textButton {
  156. font-size: 14px;
  157. color: #666;
  158. margin-bottom: 75px;
  159. }
  160. }
  161. }
  162. </style>