2021-01-20 18:52:41 +08:00
|
|
|
<template>
|
2021-03-15 12:44:58 +08:00
|
|
|
<div class="h100">
|
|
|
|
<router-view v-slot="{ Component }">
|
|
|
|
<transition :name="setTransitionName" mode="out-in">
|
2021-04-01 11:13:38 +08:00
|
|
|
<keep-alive :include="keepAliveNameList">
|
2021-03-15 12:44:58 +08:00
|
|
|
<component :is="Component" :key="refreshRouterViewKey" class="w100" />
|
|
|
|
</keep-alive>
|
|
|
|
</transition>
|
|
|
|
</router-view>
|
|
|
|
</div>
|
2021-01-20 18:52:41 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-08-01 18:30:30 +08:00
|
|
|
import { computed, defineComponent, toRefs, reactive, getCurrentInstance, onBeforeMount, onUnmounted, nextTick, watch } from 'vue';
|
2021-03-15 12:44:58 +08:00
|
|
|
import { useRoute } from 'vue-router';
|
2021-06-19 17:49:42 +08:00
|
|
|
import { useStore } from '/@/store/index';
|
2021-01-20 18:52:41 +08:00
|
|
|
export default defineComponent({
|
2021-03-15 12:44:58 +08:00
|
|
|
name: 'layoutParentView',
|
|
|
|
setup() {
|
|
|
|
const { proxy } = getCurrentInstance() as any;
|
|
|
|
const route = useRoute();
|
|
|
|
const store = useStore();
|
|
|
|
const state: any = reactive({
|
|
|
|
refreshRouterViewKey: null,
|
2021-04-01 11:13:38 +08:00
|
|
|
keepAliveNameList: [],
|
|
|
|
keepAliveNameNewList: [],
|
2021-03-15 12:44:58 +08:00
|
|
|
});
|
|
|
|
// 设置主界面切换动画
|
|
|
|
const setTransitionName = computed(() => {
|
|
|
|
return store.state.themeConfig.themeConfig.animation;
|
|
|
|
});
|
|
|
|
// 获取布局配置信息
|
|
|
|
const getThemeConfig = computed(() => {
|
|
|
|
return store.state.themeConfig.themeConfig;
|
|
|
|
});
|
|
|
|
// 获取组件缓存列表(name值)
|
|
|
|
const getKeepAliveNames = computed(() => {
|
|
|
|
return store.state.keepAliveNames.keepAliveNames;
|
|
|
|
});
|
2021-04-01 11:13:38 +08:00
|
|
|
// 页面加载前,处理缓存,页面刷新时路由缓存处理
|
2021-03-15 12:44:58 +08:00
|
|
|
onBeforeMount(() => {
|
2021-04-01 11:13:38 +08:00
|
|
|
state.keepAliveNameList = getKeepAliveNames.value;
|
2021-08-01 18:30:30 +08:00
|
|
|
proxy.mittBus.on('onTagsViewRefreshRouterView', (fullPath: string) => {
|
2021-04-01 11:13:38 +08:00
|
|
|
state.keepAliveNameList = getKeepAliveNames.value.filter((name: string) => route.name !== name);
|
2021-08-01 18:30:30 +08:00
|
|
|
state.refreshRouterViewKey = null;
|
2021-03-15 12:44:58 +08:00
|
|
|
nextTick(() => {
|
2021-08-01 18:30:30 +08:00
|
|
|
state.refreshRouterViewKey = fullPath;
|
2021-04-01 11:13:38 +08:00
|
|
|
state.keepAliveNameList = getKeepAliveNames.value;
|
2021-03-15 12:44:58 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// 页面卸载时
|
|
|
|
onUnmounted(() => {
|
|
|
|
proxy.mittBus.off('onTagsViewRefreshRouterView');
|
|
|
|
});
|
2021-08-01 18:30:30 +08:00
|
|
|
// 监听路由变化,防止 tagsView 多标签时,切换动画消失
|
|
|
|
watch(
|
|
|
|
() => route.fullPath,
|
|
|
|
() => {
|
|
|
|
state.refreshRouterViewKey = route.fullPath;
|
|
|
|
}
|
|
|
|
);
|
2021-03-15 12:44:58 +08:00
|
|
|
return {
|
|
|
|
getThemeConfig,
|
|
|
|
getKeepAliveNames,
|
|
|
|
setTransitionName,
|
|
|
|
...toRefs(state),
|
|
|
|
};
|
|
|
|
},
|
2021-01-20 18:52:41 +08:00
|
|
|
});
|
|
|
|
</script>
|