<style lang="scss">
	@import "@/common/scss/global/base.scss";
</style>

<script setup lang="ts">
import AppConfig from '@/common/config/AppCofig'
import { onLaunch } from '@dcloudio/uni-app'
import { useAuthStore } from './store/auth'
import { useCollectStore } from './store/collect';
import { configTheme } from './components/theme/ThemeDefine';
import { getCurrentPageUrl, navTo } from './components/utils/PageAction';

const authStore = useAuthStore();
const collectStore = useCollectStore();

onLaunch(async () => {
  console.log('App Launch');
  //加载登录信息。如果未登录，跳转登录页
  if (!await authStore.loadLoginState()) {

    const lastRedirectTime = uni.getStorageSync('lastRedirectTime') || 0;
    if (Date.now() - lastRedirectTime < 50000)
      return;
    uni.setStorageSync('lastRedirectTime', Date.now());

    setTimeout(() => {   
      const pageUrl = getCurrentPageUrl() || '';
      const noLoginPages = AppConfig.noLoginPages;
      if (noLoginPages.indexOf('/' + pageUrl) == -1 && noLoginPages.indexOf(pageUrl) == -1)
        navTo('/pages/user/login');
    }, 1500);
  }
  //加载采集板块信息
  await collectStore.loadCollectableModules();
})

//修改默认主题颜色
configTheme((theme) => {
  theme.colorConfigs.default.primary = '#00b66a';
  theme.colorConfigs.pressed.primary = '#00814b';
  theme.colorConfigs.background.primary = '#dcfff0';
  return theme;
});
</script>

<style lang="scss">
	/*每个页面公共css */
  @import "@/static/css/font.css";
  @import "@/components/index.scss";

  page {
    //color: #00b66a;
    background: #f7f8f9;
  }
</style>
