feat: 新增 affix 属性,用于将其固定在tab卡

This commit is contained in:
zuihou 2022-12-02 17:00:49 +08:00
parent d064f6285a
commit e772ff05fb
3 changed files with 13 additions and 7 deletions

View File

@ -23,6 +23,8 @@ interface Props {
visible?: boolean;
/** 当前路由路径 */
currentPath?: string;
/** 是否固定在tab卡不可关闭 */
affix?: boolean;
/** 鼠标x坐标 */
x: number;
/** 鼠标y坐标 */
@ -72,7 +74,7 @@ const options = computed<Option[]>(() => [
{
label: '关闭',
key: 'close-current',
disabled: props.currentPath === tab.homeTab.fullPath,
disabled: props.currentPath === tab.homeTab.fullPath || Boolean(props.affix),
icon: iconRender({ icon: 'ant-design:close-outlined' })
},
{

View File

@ -6,12 +6,12 @@
:key="item.fullPath"
:is-active="tab.activeTab === item.fullPath"
:primary-color="theme.themeColor"
:closable="item.name !== tab.homeTab.name"
:closable="!(item.name === tab.homeTab.name || item.meta.affix)"
:dark-mode="theme.darkMode"
:class="{ '!mr-0': isChromeMode && index === tab.tabs.length - 1, 'mr-10px': !isChromeMode }"
@click="tab.handleClickTab(item.fullPath)"
@close="tab.removeTab(item.fullPath)"
@contextmenu="handleContextMenu($event, item.fullPath)"
@contextmenu="handleContextMenu($event, item.fullPath, item.meta.affix)"
>
<svg-icon
:icon="item.meta.icon"
@ -24,6 +24,7 @@
<context-menu
:visible="dropdown.visible"
:current-path="dropdown.currentPath"
:affix="dropdown.affix"
:x="dropdown.x"
:y="dropdown.y"
@update:visible="handleDropdownVisible"
@ -66,6 +67,7 @@ async function getActiveTabClientX() {
const dropdown = reactive({
visible: false,
affix: false,
x: 0,
y: 0,
currentPath: ''
@ -76,8 +78,8 @@ function showDropdown() {
function hideDropdown() {
dropdown.visible = false;
}
function setDropdown(x: number, y: number, currentPath: string) {
Object.assign(dropdown, { x, y, currentPath });
function setDropdown(x: number, y: number, currentPath: string, affix?: boolean) {
Object.assign(dropdown, { x, y, currentPath, affix });
}
let isClickContextMenu = false;
@ -89,7 +91,7 @@ function handleDropdownVisible(visible: boolean) {
}
/** 点击右键菜单 */
async function handleContextMenu(e: MouseEvent, fullPath: string) {
async function handleContextMenu(e: MouseEvent, fullPath: string, affix?: boolean) {
e.preventDefault();
const { clientX, clientY } = e;
@ -101,7 +103,7 @@ async function handleContextMenu(e: MouseEvent, fullPath: string) {
hideDropdown();
setTimeout(() => {
setDropdown(clientX, clientY, fullPath);
setDropdown(clientX, clientY, fullPath, affix);
showDropdown();
isClickContextMenu = false;
}, DURATION);

View File

@ -60,6 +60,8 @@ declare namespace AuthRoute {
activeMenu?: RouteKey;
/** 表示是否是多级路由的中间级路由(用于转换路由数据时筛选多级路由的标识,定义路由时不用填写) */
multi?: boolean;
/** 是否固定在tab卡不可关闭 */
affix?: boolean;
}
type Route<K extends AllRouteKey = AllRouteKey> = K extends AllRouteKey