pcLogin.vue 3.9 KB

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