<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 { configTheme } from './components/theme/ThemeDefine';
import { getCurrentPageUrl, navTo } from './components/utils/PageAction';

const authStore = useAuthStore();

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);

  }
})

//修改默认主题颜色
configTheme((theme) => {
  theme.colorConfigs.default.primary = '#ff8719';
  theme.colorConfigs.pressed.primary = '#b86212';
  theme.colorConfigs.background.primary = '#ffe8d2';
  return theme;
});
</script>

<style>
	/*每个页面公共css */
  @import "@/static/css/font.css";

  page {
    background: #F8F8F8;
  }
</style>
