<template>
  <div id="app">
    <router-view />
    <theme-picker />
  </div>
</template>

<script>
import ThemePicker from "@/components/ThemePicker";
import { refreshToken } from "@/api/login";
import { getToken } from "@/utils/auth";

export default {
  name: "App",
  components: { ThemePicker },
  data() {
    return {
      timer: null,
    };
  },
  methods: {
    async startTokenRefresh() {
      if (this.timer) {
        clearInterval(this.timer);
      }
      let outTime = 5 * 60 * 60 * 1000;
      this.timer = setInterval(async () => {
        try {
          if (!getToken()) return;
          const response = await refreshToken();
          console.log(object);
        } catch (error) {
          console.error("token刷新失败:", error);
        }
      }, outTime);
    },
  },
  mounted() {
    this.startTokenRefresh();
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },
  metaInfo() {
    return {
      title:
        this.$store.state.settings.dynamicTitle &&
        this.$store.state.settings.title,
      titleTemplate: (title) => {
        return title
          ? `${title} - ${process.env.VUE_APP_TITLE}`
          : process.env.VUE_APP_TITLE;
      },
    };
  },
};
</script>
<style>
#app .theme-picker {
  display: none;
}
</style>
