Skip to content

Commit

Permalink
feat: tag加上删除按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Sep 3, 2022
1 parent b25b453 commit a20fe1a
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/layout/components/header/components/tagBar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
@contextmenu.prevent="setContextmenu($event.currentTarget as any, tag)"
>
{{ $t(tag.meta.title!) }}
<div v-if="!tag.meta.affix" class="del-icon" @click.stop="close($event.currentTarget as any, tag)">
<mel-icon-close />
</div>
<div></div>
</div>
</div>
</el-scrollbar>
Expand All @@ -41,6 +45,7 @@
</div>
<contextmenu
v-if="virtualRef"
ref="contextmenuRef"
v-model:visible="showContextmenu"
:virtual-ref="virtualRef"
:current="contextmenuCurrent"
Expand All @@ -53,7 +58,7 @@
>
</contextmenu>
</template>
<script setup lang="ts" name="tagBar">
<script setup lang="ts" name="TagBar">
import { mitter, event } from '@/event';
import { useRouteStore, useSettingStore } from '@/store';
import { ElScrollbar } from 'element-plus';
Expand Down Expand Up @@ -164,10 +169,15 @@ const push = (route: RouteLocationNormalized) => {
const contextmenuCurrent = ref(currentTag.value);
const virtualRef = ref<HTMLElement>();
const showContextmenu = ref(false);
const setContextmenu = (event: HTMLElement, current: RouteLocationNormalized) => {
const contextmenuRef = ref<InstanceType<typeof contextmenu>>();
const setContextmenu = (event: HTMLElement, current: RouteLocationNormalized, show = true) => {
virtualRef.value = event;
contextmenuCurrent.value = current;
showContextmenu.value = true;
showContextmenu.value = show;
};
const close = (event: HTMLElement, current: RouteLocationNormalized) => {
setContextmenu(event, current, false);
contextmenuRef.value?.closeCurrent();
};
const reload = () => {
// 刷新
Expand Down Expand Up @@ -237,10 +247,26 @@ watch(route, () => {
height: 100%;
align-items: center;
display: flex;
padding: 0 16px;
padding-left: 16px;
padding-right: 16px;
flex-shrink: 0;
flex-grow: 0;
position: relative;
.del-icon {
height: 100%;
width: 22px;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
margin-right: -16px;
visibility: hidden;
}
.del-icon:hover {
font-size: 14px;
}
}
.item:first-child {
Expand All @@ -251,6 +277,10 @@ watch(route, () => {
// background-color: rgba(var(--el-color-primary-rgb), 0.5);
background-color: rgba(var(--el-color-primary-rgb), 0.1);
color: var(--el-color-primary);
.del-icon {
visibility: unset;
}
}
.item.active {
Expand Down

0 comments on commit a20fe1a

Please sign in to comment.