feat: 页面标签组件样式与功能优化

This commit is contained in:
ZhuRui
2026-07-30 18:02:41 +08:00
parent 7606bb7d8d
commit ea906a0d92
4 changed files with 208 additions and 4 deletions
+38
View File
@@ -69,10 +69,46 @@ export function useTabsStore() {
}
};
/** 关闭 path 左侧的所有 tab */
const removeLeftTabs = (path: string): void => {
const idx = state.tabs.findIndex((t) => t.path === path);
if (idx <= 0) return;
const currentPath = router.currentRoute.value.path;
const shouldRedirect = state.tabs.slice(0, idx).some((t) => t.path === currentPath);
state.tabs = state.tabs.slice(idx);
syncCachedViews();
if (shouldRedirect) {
router.push(path);
}
};
/** 关闭 path 右侧的所有 tab */
const removeRightTabs = (path: string): void => {
const idx = state.tabs.findIndex((t) => t.path === path);
if (idx === -1 || idx >= state.tabs.length - 1) return;
const currentPath = router.currentRoute.value.path;
const shouldRedirect = state.tabs.slice(idx + 1).some((t) => t.path === currentPath);
state.tabs = state.tabs.slice(0, idx + 1);
syncCachedViews();
if (shouldRedirect) {
router.push(path);
}
};
/** 关闭除 path 之外的所有 tab */
const removeOtherTabs = (path: string): void => {
const currentPath = router.currentRoute.value.path;
state.tabs = state.tabs.filter((t) => t.path === path);
syncCachedViews();
if (currentPath !== path && state.tabs.length > 0) {
router.push(path);
}
};
/** 关闭所有 tab,保留第一个并跳转过去 */
@@ -106,6 +142,8 @@ export function useTabsStore() {
cachedViews: computed(() => state.cachedViews),
addTab,
removeTab,
removeLeftTabs,
removeRightTabs,
removeOtherTabs,
removeAllTabs,
updateTab,