login.vue 2.9 KB

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