login.vue 3.4 KB

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