mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-26 08:36:19 +08:00
feat: allow close tab when mouse middle button click (#5347)
* 偏好设置增加鼠标中键关闭标签页的设置
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -82,6 +96,7 @@ const tabsView = computed(() => {
|
||||
class="tabs-chrome__item draggable translate-all group relative -mr-3 flex h-full select-none items-center"
|
||||
data-tab-item="true"
|
||||
@click="active = tab.key"
|
||||
@mousedown="onMouseDown($event, tab)"
|
||||
>
|
||||
<VbenContextMenu
|
||||
:handler-data="tab"
|
||||
|
@@ -62,6 +62,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);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -85,6 +99,7 @@ const tabsView = computed(() => {
|
||||
class="tab-item [&:not(.is-active)]:hover:bg-accent translate-all group relative flex cursor-pointer select-none"
|
||||
data-tab-item="true"
|
||||
@click="active = tab.key"
|
||||
@mousedown="onMouseDown($event, tab)"
|
||||
>
|
||||
<VbenContextMenu
|
||||
:handler-data="tab"
|
||||
|
@@ -33,6 +33,11 @@ export interface TabsProps {
|
||||
* 仅限 tabs-chrome
|
||||
*/
|
||||
maxWidth?: number;
|
||||
/**
|
||||
* @zh_CN 点击中键时关闭Tab
|
||||
*/
|
||||
middleClickToClose?: boolean;
|
||||
|
||||
/**
|
||||
* @zh_CN tab最小宽度
|
||||
* 仅限 tabs-chrome
|
||||
@@ -43,11 +48,11 @@ export interface TabsProps {
|
||||
* @zh_CN 是否显示图标
|
||||
*/
|
||||
showIcon?: boolean;
|
||||
|
||||
/**
|
||||
* @zh_CN 标签页风格
|
||||
*/
|
||||
styleType?: TabsStyleType;
|
||||
|
||||
/**
|
||||
* @zh_CN 选项卡数据
|
||||
*/
|
||||
|
Reference in New Issue
Block a user