pcLogin.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="pcLogins">
  3. <u-navbar :is-back="false" title="登录" :border-bottom="false" title-color="#333333" back-icon-color="#ffffff">
  4. </u-navbar>
  5. <u-line color="#D6D6DB" />
  6. <view class="contents">
  7. <!-- 正文内容 -->
  8. <image class="logo" src="/static/me/logo.png" style="width: 360rpx;height: 72rpx;"></image>
  9. <text>登录后您可在网页端继续浏览课程</text>
  10. <!-- <view class="login_bt" @click="pcLogin()">微信登录</view> -->
  11. <button type="default" open-type="getPhoneNumber" @getphonenumber="wxLogin" class="login_bt">微信登录</button>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. scanCode: '', // 获取扫码的路径最后面的6位标识码
  20. code: '',
  21. }
  22. },
  23. onLoad(query) {
  24. const q = decodeURIComponent(query.q)
  25. this.scanCode = q.substring(q.length - 6)
  26. console.log('扫描后得:', q, this.scanCode)
  27. // 扫描二维码后调用,小程序已扫码
  28. if (this.scanCode) {
  29. this.$api.scanhasCode({scanCode: this.scanCode}).then((res) => {
  30. console.log('调用扫码接口返回的:', res)
  31. if (res.data.code == 200) {
  32. console.log()
  33. }
  34. })
  35. }
  36. },
  37. onShow() {
  38. // 获取code
  39. this.getwxCode()
  40. },
  41. methods: {
  42. getwxCode() {
  43. uni.login({
  44. provider: 'weixin',
  45. success: (loginRes) => {
  46. this.code = loginRes.code
  47. console.log('获取的code:', this.code)
  48. }
  49. })
  50. },
  51. wxLogin(e) {
  52. this.$api.wxLogin({
  53. code: this.code,
  54. encryptedData: e.detail.encryptedData,
  55. iv: e.detail.iv
  56. }).then(res => {
  57. if (res.data.code == 200) {
  58. this.loginCallback(res)
  59. } else {
  60. this.getwxCode() // code用完一次就会过期,防止用户点击取消后再点微信登录后code过期
  61. }
  62. })
  63. },
  64. // 微信登录成功的回调
  65. loginCallback(res) {
  66. // console.log('登录后的回调',res)
  67. // if(res.data.data && res.data.data.full_info){
  68. //信息完善,直接进入页面
  69. uni.setStorageSync('user_account', res.data.data.user_account);
  70. uni.setStorageSync('token', res.data.data.token);
  71. // /app/user/getInfo 登录用户信息// fromPlat来源平台 1小程序 2PC网站
  72. this.$api.getInfo({ fromPlat: 1 }).then(resdata => {
  73. if(resdata.data.code == 200){
  74. this.$store.state.userInfo = resdata.data.data;
  75. this.submitCode()
  76. }
  77. });
  78. // } else {
  79. // //未完善信息,存为临时信息
  80. // uni.setStorageSync('user_account_temp', res.data.data.user_account);
  81. // uni.setStorageSync('token_temp', res.data.data.token);
  82. // this.$navTo.togo('/pages2/register/bind', {scanCode: this.scanCode})
  83. // }
  84. },
  85. // scanLoginCheck小程序校验PC登录二维码,执行登录获取到令牌,然后把扫码的路径最后面的6位标识码提交给后台就行
  86. submitCode() {
  87. this.$api.scanLoginCheck({
  88. scanCode: this.scanCode
  89. }).then((res) => {
  90. if (res.data.code == 200) {
  91. uni.navigateTo({
  92. url: '/pages4/login/pcLoginSuccess'
  93. })
  94. } else {
  95. this.$u.toast(res.data.msg)
  96. }
  97. })
  98. },
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .contents {
  104. width: 100%;
  105. height: 100%;
  106. text-align: center;
  107. display: flex;
  108. flex-direction: column;
  109. align-items: center;
  110. .logo {
  111. margin: 90rpx 0rpx 250rpx;
  112. }
  113. >text {
  114. font-size: 22rpx;
  115. color: #666;
  116. }
  117. .login_bt {
  118. width: 400rpx;
  119. height: 70rpx;
  120. line-height: 70rpx;
  121. text-align: center;
  122. background: #09ba08;
  123. color: #fff;
  124. font-size: 28rpx;
  125. border-radius: 35rpx;
  126. margin-top: 20rpx;
  127. }
  128. }
  129. </style>