feat(tabbar): 添加右键菜单过滤功能 (#5820)

This commit is contained in:
Jin Mao 2025-03-30 16:23:24 +08:00 committed by GitHub
parent dbc0b7e4a9
commit df6341f0b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 4 deletions

View File

@ -209,7 +209,8 @@ export function useTabbar() {
text: $t('preferences.tabbar.contextMenu.closeAll'), text: $t('preferences.tabbar.contextMenu.closeAll'),
}, },
]; ];
return menus;
return menus.filter((item) => tabbarStore.getMenuList.includes(item.key));
}; };
return { return {

View File

@ -26,6 +26,10 @@ interface TabbarState {
* @zh_CN * @zh_CN
*/ */
excludeCachedTabs: Set<string>; excludeCachedTabs: Set<string>;
/**
* @zh_CN
*/
menuList: string[];
/** /**
* @zh_CN * @zh_CN
*/ */
@ -372,6 +376,14 @@ export const useTabbarStore = defineStore('core-tabbar', {
} }
}, },
/**
* @zh_CN
* @param list
*/
setMenuList(list: string[]) {
this.menuList = list;
},
/** /**
* @zh_CN * @zh_CN
* @param tab * @param tab
@ -388,7 +400,6 @@ export const useTabbarStore = defineStore('core-tabbar', {
await this.updateCacheTabs(); await this.updateCacheTabs();
} }
}, },
setUpdateTime() { setUpdateTime() {
this.updateTime = Date.now(); this.updateTime = Date.now();
}, },
@ -406,6 +417,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
this.tabs.splice(newIndex, 0, currentTab); this.tabs.splice(newIndex, 0, currentTab);
this.dragEndIndex = this.dragEndIndex + 1; this.dragEndIndex = this.dragEndIndex + 1;
}, },
/** /**
* @zh_CN * @zh_CN
* @param tab * @param tab
@ -439,7 +451,6 @@ export const useTabbarStore = defineStore('core-tabbar', {
// 交换位置重新排序 // 交换位置重新排序
await this.sortTabs(index, newIndex); await this.sortTabs(index, newIndex);
}, },
/** /**
* *
*/ */
@ -480,6 +491,9 @@ export const useTabbarStore = defineStore('core-tabbar', {
getExcludeCachedTabs(): string[] { getExcludeCachedTabs(): string[] {
return [...this.excludeCachedTabs]; return [...this.excludeCachedTabs];
}, },
getMenuList(): string[] {
return this.menuList;
},
getTabs(): TabDefinition[] { getTabs(): TabDefinition[] {
const normalTabs = this.tabs.filter((tab) => !isAffixTab(tab)); const normalTabs = this.tabs.filter((tab) => !isAffixTab(tab));
return [...this.affixTabs, ...normalTabs].filter(Boolean); return [...this.affixTabs, ...normalTabs].filter(Boolean);
@ -496,6 +510,17 @@ export const useTabbarStore = defineStore('core-tabbar', {
cachedTabs: new Set(), cachedTabs: new Set(),
dragEndIndex: 0, dragEndIndex: 0,
excludeCachedTabs: new Set(), excludeCachedTabs: new Set(),
menuList: [
'close',
'affix',
'maximize',
'reload',
'open-in-new-window',
'close-left',
'close-right',
'close-other',
'close-all',
],
renderRouteView: true, renderRouteView: true,
tabs: [], tabs: [],
updateTime: Date.now(), updateTime: Date.now(),

View File

@ -14,13 +14,26 @@ import {
UserDropdown, UserDropdown,
} from '@vben/layouts'; } from '@vben/layouts';
import { preferences } from '@vben/preferences'; import { preferences } from '@vben/preferences';
import { useAccessStore, useUserStore } from '@vben/stores'; import { useAccessStore, useTabbarStore, useUserStore } from '@vben/stores';
import { openWindow } from '@vben/utils'; import { openWindow } from '@vben/utils';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { useAuthStore } from '#/store'; import { useAuthStore } from '#/store';
import LoginForm from '#/views/_core/authentication/login.vue'; import LoginForm from '#/views/_core/authentication/login.vue';
const { setMenuList } = useTabbarStore();
setMenuList([
'close',
'affix',
'maximize',
'reload',
'open-in-new-window',
'close-left',
'close-right',
'close-other',
'close-all',
]);
const notifications = ref<NotificationItem[]>([ const notifications = ref<NotificationItem[]>([
{ {
avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB', avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB',