Files
orion-visor/orion-ops-ui/src/components/tab-bar/index.vue

109 lines
2.5 KiB
Vue
Raw Normal View History

2023-07-24 10:05:07 +08:00
<template>
<div class="tab-bar-container">
<a-affix ref="affixRef" :offset-top="offsetTop">
<div class="tab-bar-box">
<div class="tab-bar-scroll">
<div class="tags-wrap">
2023-08-02 17:08:40 +08:00
<TabItem
2023-07-24 10:05:07 +08:00
v-for="(tag, index) in tagList"
:key="tag.fullPath"
:index="index"
:item-data="tag"
/>
</div>
</div>
<div class="tag-bar-operation"></div>
</div>
</a-affix>
</div>
</template>
<script lang="ts" setup>
2023-08-02 17:08:40 +08:00
import { computed, onUnmounted, ref, watch } from 'vue';
2023-07-24 10:05:07 +08:00
import type { RouteLocationNormalized } from 'vue-router';
2023-08-02 17:54:12 +08:00
import { routerToTag } from '@/router/constants';
2023-08-02 17:08:40 +08:00
import { listenerRouteChange, removeRouteListener, } from '@/utils/route-listener';
2023-07-24 10:05:07 +08:00
import { useAppStore, useTabBarStore } from '@/store';
2023-08-02 17:08:40 +08:00
import TabItem from './tab-item.vue';
2023-07-24 10:05:07 +08:00
const appStore = useAppStore();
const tabBarStore = useTabBarStore();
const affixRef = ref();
const tagList = computed(() => {
return tabBarStore.getTabList;
});
const offsetTop = computed(() => {
return appStore.navbar ? 60 : 0;
});
watch(
() => appStore.navbar,
() => {
affixRef.value.updatePosition();
}
);
2023-08-02 17:08:40 +08:00
/**
* 监听路由变化
*/
2023-07-24 10:05:07 +08:00
listenerRouteChange((route: RouteLocationNormalized) => {
if (
2023-08-02 17:54:12 +08:00
!route.meta.noAffix &&
2023-07-24 10:05:07 +08:00
!tagList.value.some((tag) => tag.fullPath === route.fullPath)
) {
2023-08-02 17:54:12 +08:00
// 固定并且没有此 tab 则添加
tabBarStore.addTab(routerToTag(route), route.meta?.ignoreCache as unknown as any);
2023-07-24 10:05:07 +08:00
}
}, true);
onUnmounted(() => {
removeRouteListener();
});
</script>
<style scoped lang="less">
.tab-bar-container {
position: relative;
background-color: var(--color-bg-2);
2023-07-27 18:48:15 +08:00
2023-07-24 10:05:07 +08:00
.tab-bar-box {
display: flex;
2023-08-02 17:08:40 +08:00
padding: 0 0 0 6px;
2023-07-24 10:05:07 +08:00
background-color: var(--color-bg-2);
border-bottom: 1px solid var(--color-border);
2023-07-27 18:48:15 +08:00
2023-07-24 10:05:07 +08:00
.tab-bar-scroll {
height: 32px;
flex: 1;
overflow: hidden;
2023-07-27 18:48:15 +08:00
2023-07-24 10:05:07 +08:00
.tags-wrap {
padding: 4px 0;
height: 48px;
white-space: nowrap;
overflow-x: auto;
:deep(.arco-tag) {
display: inline-flex;
align-items: center;
margin-right: 6px;
cursor: pointer;
2023-07-27 18:48:15 +08:00
2023-07-24 10:05:07 +08:00
&:first-child {
.arco-tag-close-btn {
display: none;
}
}
}
}
}
}
.tag-bar-operation {
width: 100px;
height: 32px;
}
}
</style>