login.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. loginByWeixinApi(params).then(res => {
  66. console.log('调用登录api', res)
  67. //存储用户信息
  68. wx.setStorageSync('userInfo', res.data.userInfo);
  69. wx.setStorageSync('token', res.data.token);
  70. wx.setStorageSync('userId', res.data.userId);
  71. getApp().globalData.hasLogin = true;
  72. wx.navigateBack({
  73. delta: 1
  74. })
  75. })
  76. }
  77. }
  78. }
  79. </script>
  80. <style scoped lang="scss">
  81. .loginPage {
  82. height: 100vh;
  83. overflow: hidden;
  84. // background: url(@/static/img/ka.jpeg) no-repeat;
  85. // background-size: 100% 100%;
  86. .bk {
  87. height: 100%;
  88. width: 100%;
  89. }
  90. .box {
  91. position: absolute;
  92. bottom: 0;
  93. display: flex;
  94. align-items: center;
  95. justify-content: center;
  96. flex-direction: column;
  97. width: 100%;;
  98. background-color: rgba(255, 255, 255, 0.7);
  99. padding: 30px 10px;
  100. .tip {
  101. display: flex;
  102. justify-content: center;
  103. align-items: center;
  104. margin-bottom: 10px;
  105. color: #000;
  106. font-size: 12px;
  107. .checkBox {
  108. // font-size: 12px;
  109. height: 12px;
  110. width: 12px;
  111. }
  112. }
  113. .m_button {
  114. height: 40px;
  115. width: 50vw;
  116. border-radius: 20px;
  117. line-height: 40px;
  118. font-size: 16px;
  119. }
  120. }
  121. }
  122. </style>