Skip to content

Commit df6341f

Browse files
authored
feat(tabbar): 添加右键菜单过滤功能 (#5820)
1 parent dbc0b7e commit df6341f

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

packages/effects/layouts/src/basic/tabbar/use-tabbar.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ export function useTabbar() {
209209
text: $t('preferences.tabbar.contextMenu.closeAll'),
210210
},
211211
];
212-
return menus;
212+
213+
return menus.filter((item) => tabbarStore.getMenuList.includes(item.key));
213214
};
214215

215216
return {

packages/stores/src/modules/tabbar.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ interface TabbarState {
2626
* @zh_CN 需要排除缓存的标签页
2727
*/
2828
excludeCachedTabs: Set<string>;
29+
/**
30+
* @zh_CN 标签右键菜单列表
31+
*/
32+
menuList: string[];
2933
/**
3034
* @zh_CN 是否刷新
3135
*/
@@ -372,6 +376,14 @@ export const useTabbarStore = defineStore('core-tabbar', {
372376
}
373377
},
374378

379+
/**
380+
* @zh_CN 更新菜单列表
381+
* @param list
382+
*/
383+
setMenuList(list: string[]) {
384+
this.menuList = list;
385+
},
386+
375387
/**
376388
* @zh_CN 设置标签页标题
377389
* @param tab
@@ -388,7 +400,6 @@ export const useTabbarStore = defineStore('core-tabbar', {
388400
await this.updateCacheTabs();
389401
}
390402
},
391-
392403
setUpdateTime() {
393404
this.updateTime = Date.now();
394405
},
@@ -406,6 +417,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
406417
this.tabs.splice(newIndex, 0, currentTab);
407418
this.dragEndIndex = this.dragEndIndex + 1;
408419
},
420+
409421
/**
410422
* @zh_CN 切换固定标签页
411423
* @param tab
@@ -439,7 +451,6 @@ export const useTabbarStore = defineStore('core-tabbar', {
439451
// 交换位置重新排序
440452
await this.sortTabs(index, newIndex);
441453
},
442-
443454
/**
444455
* 根据当前打开的选项卡更新缓存
445456
*/
@@ -480,6 +491,9 @@ export const useTabbarStore = defineStore('core-tabbar', {
480491
getExcludeCachedTabs(): string[] {
481492
return [...this.excludeCachedTabs];
482493
},
494+
getMenuList(): string[] {
495+
return this.menuList;
496+
},
483497
getTabs(): TabDefinition[] {
484498
const normalTabs = this.tabs.filter((tab) => !isAffixTab(tab));
485499
return [...this.affixTabs, ...normalTabs].filter(Boolean);
@@ -496,6 +510,17 @@ export const useTabbarStore = defineStore('core-tabbar', {
496510
cachedTabs: new Set(),
497511
dragEndIndex: 0,
498512
excludeCachedTabs: new Set(),
513+
menuList: [
514+
'close',
515+
'affix',
516+
'maximize',
517+
'reload',
518+
'open-in-new-window',
519+
'close-left',
520+
'close-right',
521+
'close-other',
522+
'close-all',
523+
],
499524
renderRouteView: true,
500525
tabs: [],
501526
updateTime: Date.now(),

playground/src/layouts/basic.vue

+14-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@ import {
1414
UserDropdown,
1515
} from '@vben/layouts';
1616
import { preferences } from '@vben/preferences';
17-
import { useAccessStore, useUserStore } from '@vben/stores';
17+
import { useAccessStore, useTabbarStore, useUserStore } from '@vben/stores';
1818
import { openWindow } from '@vben/utils';
1919
2020
import { $t } from '#/locales';
2121
import { useAuthStore } from '#/store';
2222
import LoginForm from '#/views/_core/authentication/login.vue';
2323
24+
const { setMenuList } = useTabbarStore();
25+
setMenuList([
26+
'close',
27+
'affix',
28+
'maximize',
29+
'reload',
30+
'open-in-new-window',
31+
'close-left',
32+
'close-right',
33+
'close-other',
34+
'close-all',
35+
]);
36+
2437
const notifications = ref<NotificationItem[]>([
2538
{
2639
avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB',

0 commit comments

Comments
 (0)