login.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.navigateBack({
  34. delta: 1
  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. wx.navigateBack({
  91. delta: 1
  92. })
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style scoped lang="scss">
  99. .loginPage {
  100. background: #E6F2FF;
  101. height: 100vh;
  102. overflow: hidden;
  103. // background: url(https://mall.rongtongh.cn/storage/img/ka.jpeg) no-repeat;
  104. // background-size: 100% 100%;
  105. .bk {
  106. height: 100%;
  107. width: 100%;
  108. }
  109. .box {
  110. position: absolute;
  111. bottom: 15%;
  112. display: flex;
  113. align-items: center;
  114. justify-content: center;
  115. flex-direction: column;
  116. width: 100%;;
  117. // background-color: rgba(255, 255, 255, 0.7);
  118. // padding: 30px 10px;
  119. .logo {
  120. width: 94px;
  121. height: 94px;
  122. margin-bottom: 20vh;
  123. }
  124. .tip {
  125. display: flex;
  126. justify-content: center;
  127. align-items: center;
  128. margin-bottom: 10px;
  129. color: #000;
  130. font-size: 12px;
  131. .checkBox {
  132. // font-size: 12px;
  133. height: 12px;
  134. width: 12px;
  135. }
  136. }
  137. .button {
  138. height: 48px;
  139. width: calc(100% - 60px);
  140. border-radius: 24px;
  141. line-height: 48px;
  142. font-size: 14px;
  143. background: #FEA200;
  144. color: #fff;
  145. margin-bottom: 20px;
  146. }
  147. .textButton {
  148. font-size: 14px;
  149. color: #666;
  150. margin-bottom: 75px;
  151. }
  152. }
  153. }
  154. </style>