splash.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <ie-page :fix-height="true">
  3. <view class="flex-1 min-h-1 h-full flex items-center justify-center">
  4. <uv-image :src="imgLaunch" width="55vw" height="auto" mode="widthFix" bgColor="white" custom-class="-mt-300">
  5. <template #loading>
  6. <span></span>
  7. </template>
  8. </uv-image>
  9. </view>
  10. <maintain-popup ref="maintainPopupRef" />
  11. </ie-page>
  12. </template>
  13. <script lang="ts" setup>
  14. import config from '@/config';
  15. import { useEnv } from '@/hooks/useEnv';
  16. import { useAppStore } from '@/store/appStore';
  17. import { useTransferPage } from '@/hooks/useTransferPage';
  18. import { load } from '@/utils/loadFont';
  19. import MaintainPopup from './components/maintain-popup.vue';
  20. const { platform } = useEnv();
  21. const splashTimeout = 1200;
  22. const appStore = useAppStore();
  23. const { transferTo, routes } = useTransferPage();
  24. // #ifdef H5
  25. uni.hideTabBar();
  26. // #endif
  27. const imgLaunch = computed(() => {
  28. return config.ossUrl + '/launch.png'
  29. });
  30. const maintainPopupRef = ref();
  31. const handleLoad = () => {
  32. if (typeof window !== 'undefined' && window !== null && window.platform === 'wap2app') {
  33. window.webviewBridge.getStatusBarHeight().then(height => {
  34. appStore.statusBarHeight = height;
  35. });
  36. }
  37. appStore.getMaintainNotice().then(async (isMaintaining) => {
  38. // 执行初始化的操作:预加载字典、提前校验token是否有效等
  39. if (!isMaintaining) {
  40. appStore.init().then(async () => {
  41. try {
  42. const usedTime = await load();
  43. if (usedTime < splashTimeout) {
  44. await new Promise(resolve => setTimeout(resolve, splashTimeout - usedTime));
  45. }
  46. } catch (error) {
  47. console.error('初始化失败: ', error);
  48. } finally {
  49. transferTo('/pagesMain/pages/index/index', {
  50. type: 'reLaunch'
  51. });
  52. // transferTo('/pagesStudy/pages/knowledge-practice/knowledge-practice', {
  53. // type: 'reLaunch'
  54. // });
  55. }
  56. });
  57. } else {
  58. setTimeout(() => {
  59. nextTick(() => {
  60. maintainPopupRef.value?.open().then(() => {
  61. // #ifdef H5
  62. if (platform.value === 'wap2app') {
  63. plus.runtime.quit();
  64. } else {
  65. window.close();
  66. }
  67. // #endif
  68. // #ifdef MP-WEIXIN
  69. wx.exitMiniProgram();
  70. // #endif
  71. });
  72. });
  73. }, 800);
  74. }
  75. });
  76. };
  77. onLoad(() => {
  78. handleLoad();
  79. });
  80. </script>
  81. <style></style>