refactor: refacotr preference

This commit is contained in:
vben
2024-06-01 23:15:29 +08:00
parent f7b97e8a83
commit fed47f5e05
139 changed files with 2205 additions and 1450 deletions

View File

@@ -1,14 +1,13 @@
<script lang="ts" setup>
import { preferences, usePreferences } from '@vben-core/preferences';
import { storeToRefs, useTabsStore } from '@vben-core/stores';
import type { RouteLocationNormalizedLoaded } from 'vue-router';
import { preference, usePreference } from '@vben/preference';
import { storeToRefs, useTabsStore } from '@vben/stores';
import { IFrameRouterView } from '../../iframe';
defineOptions({ name: 'LayoutContent' });
const { keepAlive } = usePreference();
const { keepAlive } = usePreferences();
const tabsStore = useTabsStore();
const { getCacheTabs, getExcludeTabs, renderRouteView } =
@@ -17,15 +16,15 @@ const { getCacheTabs, getExcludeTabs, renderRouteView } =
// 页面切换动画
function getTransitionName(route: RouteLocationNormalizedLoaded) {
// 如果偏好设置未设置,则不使用动画
const { keepAlive, pageTransition, pageTransitionEnable, tabsVisible } =
preference;
if (!pageTransition || !pageTransitionEnable) {
const { tabbar, transition } = preferences;
const transitionName = transition.name;
if (!transitionName || !transition.enable) {
return;
}
// 标签页未启用或者未开启缓存,则使用全局配置动画
if (!tabsVisible || !keepAlive) {
return pageTransition;
if (!tabbar.enable || !keepAlive) {
return transitionName;
}
// 如果页面已经加载过,则不使用动画
@@ -34,7 +33,7 @@ function getTransitionName(route: RouteLocationNormalizedLoaded) {
}
// 已经打开且已经加载过的页面不使用动画
const inTabs = getCacheTabs.value.includes(route.name as string);
return inTabs && route.meta.loaded ? undefined : pageTransition;
return inTabs && route.meta.loaded ? undefined : transitionName;
}
</script>