login.vue 1.2 KB

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