<template>
  <router-view v-slot="{ Component }">
    <keep-alive :include="cacheViews">
      <component :is="Component" />
    </keep-alive>
  </router-view>
</template>

<script setup lang="ts">
import { onMounted, onBeforeUnmount, computed } from 'vue';
import { useRouter } from 'vue-router';
import { useMainStore } from './store';

const router = useRouter();
const mainStore = useMainStore();

const cacheViews = computed(() => mainStore.getCacheViews);

const handleLinkClick = (e: MouseEvent) => {
  const target = (e.target as HTMLElement).closest('a') as HTMLAnchorElement | null;
  if (target && target.tagName === 'A' && target.href) {
    e.preventDefault();
    window.open(target.href, '_blank', 'noopener,noreferrer');
  }
};

onMounted(() => {
  if (location.pathname !== '/') {
    router.push('/');
  }
  document.addEventListener('click', handleLinkClick);
});

onBeforeUnmount(() => {
  document.removeEventListener('click', handleLinkClick);
});
</script>

<style>
/* 全局样式 */
.help-tip {
  width: 540px;
  /* height: 110px; */
  display: flex;
  flex-direction: column;
  /* box-sizing: border-box; */
  padding: 20px 20px !important;
  .title {
    font-weight: bold;
    font-size: 16px;
    color: #282e30;
    margin-bottom: 10px;
  }

  .value {
    font-weight: 400;
    font-size: 14px;
    color: #282e30;
  }
}
</style>
