<script setup lang="ts">
import initVersionRocket from "@/config/versionRocket";
import { Constant, elLocale } from "@/constants";
import { useEventBus, useTheme } from "@/hooks";
import { useAppStore, useRouteStore, useTabStore } from "@/stores";
import { $t, setDocumentTitle } from "@/utils";

const appStore = useAppStore();

const locale = computed(() => {
  return elLocale[appStore.locale];
});

const { initTheme } = useTheme();
onMounted(initTheme);

const tabStore = useTabStore();
const routeStore = useRouteStore();
const router = useRouter();
const route = useRoute();

// 监听语言变化
const { on } = useEventBus();
on(Constant.LOCALE_EVENT, async () => {
  if (route.path === "/login") {
    setDocumentTitle($t("page.login.title"));
  } else {
    console.log("页面刷新");
    await routeStore.initAuthRoute();
    await router.replace(route.fullPath);
    tabStore.tabLocale();
  }
});

// 初始化版本检测
initVersionRocket();
</script>

<template>
  <el-config-provider :locale :size="appStore.size" :message="{ max: 1 }">
    <router-view />
  </el-config-provider>
</template>

<style>
*{
  padding: 0;margin: 0;
}
</style>
