<template>
    <router-view v-slot="{ Component, route }" class="mx-2 my-2">
        <template v-if="!Component">
            <Empty class="full-empty" />
        </template>
        <transition name="ma-fade" mode="out-in" appear>
            <!-- 这里主要在路由定义是否缓存页面 -->
            <component :is="Component" v-if="route.meta.ignoreCache" :key="route.fullPath" />
            <keep-alive v-else :include="cacheList">
                <component :is="Component" ref="viewChild" :key="route.fullPath"></component>
            </keep-alive>
        </transition>
    </router-view>
</template>

<script setup>
import { computed, ref } from "vue"
import { useTabBarStore } from "@/store"
import Empty from "@/components/Empty/index.vue"
// 获取缓存列表
const tabBarStore = useTabBarStore()
const cacheList = computed(() => tabBarStore.getCacheList)
// 调用router-view组件的刷新方法
const viewChild = ref()
const refresh = () => {
    try {
        viewChild.value.refreshCrudTable()
    } catch (err) {
        console.log("无法找到router-view动态组件的刷新函数")
    } finally {
    }
}
defineExpose({ refresh })
</script>

<style lang="less" scoped>
.full-empty {
    width: 79vw;
}
</style>
