diff --git a/packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap b/packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap index 81df9682161..486bf0487d0 100644 --- a/packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap +++ b/packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap @@ -80,6 +80,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj "enable": true, "height": 38, "keepAlive": true, + "middleClickToClose": false, "persist": true, "showIcon": true, "showMaximize": true, diff --git a/packages/@core/preferences/src/config.ts b/packages/@core/preferences/src/config.ts index 10971de5cc3..8f82e4fc453 100644 --- a/packages/@core/preferences/src/config.ts +++ b/packages/@core/preferences/src/config.ts @@ -80,6 +80,7 @@ const defaultPreferences: Preferences = { enable: true, height: 38, keepAlive: true, + middleClickToClose: false, persist: true, showIcon: true, showMaximize: true, diff --git a/packages/@core/preferences/src/types.ts b/packages/@core/preferences/src/types.ts index f8b35242c6a..b554b219a40 100644 --- a/packages/@core/preferences/src/types.ts +++ b/packages/@core/preferences/src/types.ts @@ -168,6 +168,8 @@ interface TabbarPreferences { height: number; /** 开启标签页缓存功能 */ keepAlive: boolean; + /** 是否点击中键时关闭标签 */ + middleClickToClose: boolean; /** 是否持久化标签 */ persist: boolean; /** 是否开启多标签页图标 */ diff --git a/packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue b/packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue index 7ab875a780c..eb977ce4935 100644 --- a/packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue +++ b/packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue @@ -56,6 +56,20 @@ const tabsView = computed(() => { } as TabConfig; }); }); + +function onMouseDown(e: MouseEvent, tab: TabConfig) { + if ( + e.button === 1 && + tab.closable && + !tab.affixTab && + tabsView.value.length > 1 && + props.middleClickToClose + ) { + e.preventDefault(); + e.stopPropagation(); + emit('close', tab.key); + } +}