<template>
  <ie-page :fix-height="true">
    <view class="flex-1 min-h-1 h-full flex items-center justify-center">
      <uv-image :src="imgLaunch" width="55vw" height="auto" mode="widthFix" bgColor="white" custom-class="-mt-300">
        <template #loading>
          <span></span>
        </template>
      </uv-image>
    </view>
  </ie-page>
</template>

<script lang="ts" setup>
import config from '@/config';
import { useAppStore } from '@/store/appStore';
import { useAppConfig } from '@/hooks/useAppConfig';
import { useUserStore } from '@/store/userStore';
import { useTransferPage } from '@/hooks/useTransferPage';
import { load } from '@/utils/loadFont';

const splashTimeout = 1200;
const appStore = useAppStore();
const userStore = useUserStore();
const { transferTo } = useTransferPage();
// #ifdef H5
uni.hideTabBar();
// #endif
const imgLaunch = computed(() => {
  return config.ossUrl + '/launch.png'
});
const handleLoad = () => {
  if (typeof window !== 'undefined' && window !== null && window.platform === 'wap2app') {
    window.webviewBridge.getStatusBarHeight().then(height => {
      appStore.statusBarHeight = height;
    });
  }
  // 执行初始化的操作：预加载字典、提前校验token是否有效等
  appStore.init().then(async () => {
    try {
      const usedTime = await load();
      if (usedTime < splashTimeout) {
        await new Promise(resolve => setTimeout(resolve, splashTimeout - usedTime));
      }
    } catch (error) {
      console.error('初始化失败: ', error);
    } finally {
      transferTo('/pagesMain/pages/index/index', {
        type: 'reLaunch'
      });
      // transferTo('/pagesStudy/pages/knowledge-practice/knowledge-practice', {
      //   type: 'reLaunch'
      // });
    }
  });
};
onLoad(() => {
  handleLoad();
});
</script>

<style></style>
