login.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <!-- 微信公众号的登录回调页 -->
  2. <template>
  3. <!-- 空登陆页 -->
  4. <view />
  5. <view>登录</view>
  6. </template>
  7. <script setup>
  8. import sheep from '@/sheep';
  9. import { onLoad } from '@dcloudio/uni-app';
  10. import {
  11. closeAuthModal,
  12. showAuthModal
  13. } from '@/sheep/hooks/useModal';
  14. onLoad(async (options) => {
  15. // #ifdef H5
  16. // 将 search 参数赋值到 options 中,方便下面解析
  17. new URLSearchParams(location.search).forEach((value, key) => {
  18. options[key] = value;
  19. });
  20. const event = options.event;
  21. const code = options.code;
  22. const state = options.state;
  23. if (event === 'login') { // 场景一:登录
  24. const res = await sheep.$platform.useProvider().login(code, state);
  25. console.log("login.vue res:",res)
  26. if(!res){
  27. console.log("返回第一次登录了",res)
  28. setTimeout(showAuthModal("officialAccountFirstLogin"),100)
  29. return false;
  30. }
  31. } else if (event === 'bind') { // 场景二:绑定
  32. sheep.$platform.useProvider().bind(code, state);
  33. }
  34. // 检测 H5 登录回调
  35. let returnUrl = uni.getStorageSync('returnUrl');
  36. if (returnUrl) {
  37. uni.removeStorage('returnUrl');
  38. location.replace(returnUrl);
  39. } else {
  40. uni.switchTab({
  41. url: '/',
  42. });
  43. }
  44. // #endif
  45. });
  46. </script>