login.vue 1.2 KB

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