<template>
  <ConfigProvider :locale="getAntdLocale">
    <AppProvider>
      <RouterView />
    </AppProvider>
  </ConfigProvider>
</template>

<script lang="ts" setup>
  import { ConfigProvider } from 'ant-design-vue';
  import { AppProvider } from '/@/components/Application';
  import { useTitle } from '/@/hooks/web/useTitle';
  import { useLocale } from '/@/locales/useLocale';
  import { computed, onMounted, ref } from 'vue';
  import { useUserStore } from '/@/store/modules/user';

  // 解决日期时间国际化问题
  import 'dayjs/locale/zh-cn';
  // support Multi-language
  const { getAntdLocale } = useLocale();
  
  const beforeUnload_time = ref(0)
  const unload_time = ref(0)
  const userStore = useUserStore();

  // 自动请求并暴露内部方法
  onMounted(() => {
    beforeunload()
  });

  function beforeunload() {
    window.addEventListener('beforeunload', (event) => {
      beforeUnload_time.value = new Date().getTime()
      if (localStorage.getItem('timeoutlogin')) {
        unload_time.value = Number(localStorage.getItem('timeoutlogin'))
        let timestamp = (beforeUnload_time.value - unload_time.value)/(1000*60*60*3)
        localStorage.setItem('timestamp', timestamp.toString())
        if (timestamp > 1) {
          userStore.logout();
        }
      }
      
      localStorage.setItem('timeoutlogin', beforeUnload_time.value.toString())
    });
  }
  useTitle();
</script>
<style>
.ant-input {
  font-size: 14px;
}
</style>
