pcLogin.vue 3.9 KB

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