mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-14 06:50:52 +08:00
Merge branch 'main' of https://github.com/vbenjs/vue-vben-admin into dev
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import type { ComputedRef } from 'vue';
|
||||
import type { ComputedRef, VNode } from 'vue';
|
||||
import type {
|
||||
RouteLocationNormalized,
|
||||
RouteLocationNormalizedLoaded,
|
||||
RouteLocationNormalizedLoadedGeneric,
|
||||
Router,
|
||||
RouteRecordNormalized,
|
||||
} from 'vue-router';
|
||||
|
||||
import type { TabDefinition } from '@vben-core/typings';
|
||||
|
||||
import { toRaw } from 'vue';
|
||||
import { markRaw, toRaw } from 'vue';
|
||||
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
import {
|
||||
@@ -20,7 +22,14 @@ import {
|
||||
|
||||
import { acceptHMRUpdate, defineStore } from 'pinia';
|
||||
|
||||
interface RouteCached {
|
||||
component: VNode;
|
||||
key: string;
|
||||
route: RouteLocationNormalizedLoadedGeneric;
|
||||
}
|
||||
|
||||
interface TabbarState {
|
||||
cachedRoutes: Map<string, RouteCached>;
|
||||
/**
|
||||
* @zh_CN 当前打开的标签页列表缓存
|
||||
*/
|
||||
@@ -553,6 +562,25 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
}
|
||||
this.cachedTabs = cacheMap;
|
||||
},
|
||||
/**
|
||||
* 添加缓存的route
|
||||
* @param component
|
||||
* @param route
|
||||
*/
|
||||
addCachedRoute(component: VNode, route: RouteLocationNormalizedLoaded) {
|
||||
const key = getTabKey(route);
|
||||
if (this.cachedRoutes.has(key)) {
|
||||
return;
|
||||
}
|
||||
this.cachedRoutes.set(key, {
|
||||
key,
|
||||
component: markRaw(component),
|
||||
route: markRaw(route),
|
||||
});
|
||||
},
|
||||
removeCachedRoute(key: string) {
|
||||
this.cachedRoutes.delete(key);
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
affixTabs(): TabDefinition[] {
|
||||
@@ -577,6 +605,9 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
const normalTabs = this.tabs.filter((tab) => !isAffixTab(tab));
|
||||
return [...this.affixTabs, ...normalTabs].filter(Boolean);
|
||||
},
|
||||
getCachedRoutes(): Map<string, RouteCached> {
|
||||
return this.cachedRoutes;
|
||||
},
|
||||
},
|
||||
persist: [
|
||||
// tabs不需要保存在localStorage
|
||||
@@ -604,6 +635,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
],
|
||||
state: (): TabbarState => ({
|
||||
visitHistory: createStack<string>(true, MAX_VISIT_HISTORY),
|
||||
cachedRoutes: new Map<string, RouteCached>(),
|
||||
cachedTabs: new Set(),
|
||||
dragEndIndex: 0,
|
||||
excludeCachedTabs: new Set(),
|
||||
|
||||
Reference in New Issue
Block a user