Skip to content

Commit

Permalink
feat: 新增 affix 属性,用于将其固定在tab卡
Browse files Browse the repository at this point in the history
  • Loading branch information
zuihou committed Dec 2, 2022
1 parent d064f62 commit e772ff0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface Props {
visible?: boolean;
/** 当前路由路径 */
currentPath?: string;
/** 是否固定在tab卡不可关闭 */
affix?: boolean;
/** 鼠标x坐标 */
x: number;
/** 鼠标y坐标 */
Expand Down Expand Up @@ -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' })
},
{
Expand Down
14 changes: 8 additions & 6 deletions src/layouts/common/GlobalTab/components/TabDetail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -66,6 +67,7 @@ async function getActiveTabClientX() {
const dropdown = reactive({
visible: false,
affix: false,
x: 0,
y: 0,
currentPath: ''
Expand All @@ -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) {

This comment has been minimized.

Copy link
@yyqxjwxy

yyqxjwxy Feb 2, 2023

这里我看最新代码不是这么写的是为啥呢

This comment has been minimized.

Copy link
@zuihou

zuihou Feb 3, 2023

Author Contributor

作者优化了呗, 编码规范一个方法参数不超过3个还是5个哦

Object.assign(dropdown, { x, y, currentPath, affix });
}
let isClickContextMenu = false;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/typings/route.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ declare namespace AuthRoute {
activeMenu?: RouteKey;
/** 表示是否是多级路由的中间级路由(用于转换路由数据时筛选多级路由的标识,定义路由时不用填写) */
multi?: boolean;
/** 是否固定在tab卡不可关闭 */
affix?: boolean;
}

type Route<K extends AllRouteKey = AllRouteKey> = K extends AllRouteKey
Expand Down

0 comments on commit e772ff0

Please sign in to comment.