refactor: Separate store

This commit is contained in:
vben
2024-07-30 21:10:28 +08:00
parent cf0ec053e4
commit 89dcf522f5
40 changed files with 338 additions and 345 deletions

View File

@@ -4,7 +4,7 @@ import { useRoute } from 'vue-router';
import { useContentMaximize, useTabs } from '@vben/hooks';
import { preferences } from '@vben/preferences';
import { useCoreTabbarStore } from '@vben/stores';
import { useTabbarStore } from '@vben/stores';
import {
TabsToolMore,
TabsToolRefresh,
@@ -21,7 +21,7 @@ defineOptions({
defineProps<{ showIcon?: boolean; theme?: string }>();
const route = useRoute();
const coreTabbarStore = useCoreTabbarStore();
const tabbarStore = useTabbarStore();
const { toggleMaximize } = useContentMaximize();
const { refreshTab, unpinTab } = useTabs();
@@ -34,7 +34,7 @@ const {
} = useTabbar();
const menus = computed(() => {
const tab = coreTabbarStore.getTabByPath(currentActive.value);
const tab = tabbarStore.getTabByPath(currentActive.value);
const menus = createContextMenus(tab);
return menus.map((item) => {
return {
@@ -47,7 +47,7 @@ const menus = computed(() => {
// 刷新后如果不保持tab状态关闭其他tab
if (!preferences.tabbar.persist) {
coreTabbarStore.closeOtherTabs(route);
tabbarStore.closeOtherTabs(route);
}
</script>
@@ -61,7 +61,7 @@ if (!preferences.tabbar.persist) {
:style-type="preferences.tabbar.styleType"
:tabs="currentTabs"
@close="handleClose"
@sort-tabs="coreTabbarStore.sortTabs"
@sort-tabs="tabbarStore.sortTabs"
@unpin="unpinTab"
@update:active="handleClick"
/>

View File

@@ -23,19 +23,14 @@ import {
X,
} from '@vben/icons';
import { $t, useI18n } from '@vben/locales';
import {
storeToRefs,
useCoreAccessStore,
useCoreTabbarStore,
} from '@vben/stores';
import { useAccessStore, useTabbarStore } from '@vben/stores';
import { filterTree } from '@vben/utils';
export function useTabbar() {
const router = useRouter();
const route = useRoute();
const accessStore = useCoreAccessStore();
const coreTabbarStore = useCoreTabbarStore();
const { accessMenus } = storeToRefs(accessStore);
const accessStore = useAccessStore();
const tabbarStore = useTabbarStore();
const { contentIsMaximize, toggleMaximize } = useContentMaximize();
const {
closeAllTabs,
@@ -58,8 +53,8 @@ export function useTabbar() {
const currentTabs = ref<RouteLocationNormalizedGeneric[]>();
watch(
[
() => coreTabbarStore.getTabs,
() => coreTabbarStore.updateTime,
() => tabbarStore.getTabs,
() => tabbarStore.updateTime,
() => locale.value,
],
([tabs]) => {
@@ -74,7 +69,7 @@ export function useTabbar() {
const affixTabs = filterTree(router.getRoutes(), (route) => {
return !!route.meta?.affixTab;
});
coreTabbarStore.setAffixTabs(affixTabs);
tabbarStore.setAffixTabs(affixTabs);
};
// 点击tab,跳转路由
@@ -98,7 +93,7 @@ export function useTabbar() {
}
watch(
() => accessMenus.value,
() => accessStore.accessMenus,
() => {
initAffixTabs();
},
@@ -108,7 +103,7 @@ export function useTabbar() {
watch(
() => route.path,
() => {
coreTabbarStore.addTab(route as RouteLocationNormalized);
tabbarStore.addTab(route as RouteLocationNormalized);
},
{ immediate: true },
);