<template>
  <section class="app-main">
    <transition name="fade-transform" mode="out-in">
      <keep-alive :include="cachedViews">
        <router-view :key="key" />
      </keep-alive>
    </transition>
  </section>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { useAppStore } from '@/stores/app'

const route = useRoute()
const appStore = useAppStore()

// 缓存的视图
const cachedViews = computed(() => appStore.cachedViews)

// 路由key，用于强制刷新组件
const key = computed(() => route.path)
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';

.app-main {
  min-height: calc(100vh - #{$header-height} - #{$tags-height});
  width: 100%;
  position: relative;
  overflow: hidden;
  background-color: $bg-color;
}

// 暗色模式
.dark {
  .app-main {
    background-color: $bg-color-dark;
  }
}

// 页面切换动画
.fade-transform-leave-active,
.fade-transform-enter-active {
  transition: all 0.5s;
}

.fade-transform-enter-from {
  opacity: 0;
  transform: translateX(-30px);
}

.fade-transform-leave-to {
  opacity: 0;
  transform: translateX(30px);
}
</style>
