App.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <router-view v-slot="{ Component }">
  3. <keep-alive :include="cacheViews">
  4. <component :is="Component" />
  5. </keep-alive>
  6. </router-view>
  7. </template>
  8. <script setup lang="ts">
  9. import { onMounted, onBeforeUnmount, computed } from 'vue';
  10. import { useRouter } from 'vue-router';
  11. import { useMainStore } from './store';
  12. const router = useRouter();
  13. const mainStore = useMainStore();
  14. const cacheViews = computed(() => mainStore.getCacheViews);
  15. const handleLinkClick = (e: MouseEvent) => {
  16. const target = (e.target as HTMLElement).closest('a') as HTMLAnchorElement | null;
  17. if (target && target.tagName === 'A' && target.href) {
  18. e.preventDefault();
  19. window.open(target.href, '_blank', 'noopener,noreferrer');
  20. }
  21. };
  22. onMounted(() => {
  23. if (location.pathname !== '/') {
  24. router.push('/');
  25. }
  26. document.addEventListener('click', handleLinkClick);
  27. });
  28. onBeforeUnmount(() => {
  29. document.removeEventListener('click', handleLinkClick);
  30. });
  31. </script>
  32. <style>
  33. /* 全局样式 */
  34. .help-tip {
  35. width: 540px;
  36. /* height: 110px; */
  37. display: flex;
  38. flex-direction: column;
  39. /* box-sizing: border-box; */
  40. padding: 20px 20px !important;
  41. .title {
  42. font-weight: bold;
  43. font-size: 16px;
  44. color: #282e30;
  45. margin-bottom: 10px;
  46. }
  47. .value {
  48. font-weight: 400;
  49. font-size: 14px;
  50. color: #282e30;
  51. }
  52. }
  53. </style>