<style lang="scss">
  @import "@/uni_modules/uview-plus/index.scss";
	@import "@/common/scss/common.scss";
	@import "@/common/scss/global/base.scss";
</style>
<script setup lang="ts">
import { onLaunch } from '@dcloudio/uni-app'
import { useAuthStore } from './store/auth'
import AppConfig from '@/common/config/AppCofig'
import { getCurrentPageUrl, navTo } from "@imengyu/imengyu-utils/dist/uniapp/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);

  }
})
</script>

<style>
	/*每个页面公共css */
</style>
