login.vue 1.0 KB

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