login.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. } else if (event === 'bind') { // 场景二:绑定
  25. sheep.$platform.useProvider().bind(code, state);
  26. }
  27. if(!res){
  28. showAuthModal("officialAccountFirstLogin");
  29. return;
  30. }
  31. // 检测 H5 登录回调
  32. let returnUrl = uni.getStorageSync('returnUrl');
  33. if (returnUrl) {
  34. uni.removeStorage('returnUrl');
  35. location.replace(returnUrl);
  36. } else {
  37. uni.switchTab({
  38. url: '/',
  39. });
  40. }
  41. // #endif
  42. });
  43. </script>