Files
cdTestPlant3/cdTMP/src/layout/components/tab-bar.vue

90 lines
2.3 KiB
Vue
Raw Normal View History

2023-06-05 21:02:25 +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">
<tab-item 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>
2023-06-08 21:09:28 +08:00
<script setup>
import { ref, computed, watch, onUnmounted } from "vue"
import { listenerRouteChange, removeRouteListener } from "@/utils/route-listener"
import { useAppStore, useTabBarStore } from "@/store"
import tabItem from "./tab-item.vue"
2023-06-05 21:02:25 +08:00
2023-06-08 21:09:28 +08:00
const appStore = useAppStore()
const tabBarStore = useTabBarStore()
2023-06-05 21:02:25 +08:00
2023-06-08 21:09:28 +08:00
const affixRef = ref()
const tagList = computed(() => {
return tabBarStore.getTabList
})
const offsetTop = computed(() => {
return appStore.navbar ? 60 : 0
})
2023-06-05 21:02:25 +08:00
2023-06-08 21:09:28 +08:00
watch(
() => appStore.navbar,
() => {
affixRef.value.updatePosition()
}
)
listenerRouteChange((route) => {
if (!route.meta.noAffix && !tagList.value.some((tag) => tag.fullPath === route.fullPath)) {
tabBarStore.updateTabList(route)
}
}, true)
2023-06-05 21:02:25 +08:00
2023-06-08 21:09:28 +08:00
onUnmounted(() => {
removeRouteListener()
})
2023-06-05 21:02:25 +08:00
</script>
<style scoped lang="less">
2023-06-08 21:09:28 +08:00
.tab-bar-container {
position: relative;
background-color: var(--color-bg-2);
.tab-bar-box {
display: flex;
padding: 0 0 0 20px;
2023-06-05 21:02:25 +08:00
background-color: var(--color-bg-2);
2023-06-08 21:09:28 +08:00
border-bottom: 1px solid var(--color-border);
.tab-bar-scroll {
height: 32px;
flex: 1;
overflow: hidden;
.tags-wrap {
padding: 4px 0;
height: 48px;
white-space: nowrap;
overflow-x: auto;
2023-06-05 21:02:25 +08:00
2023-06-08 21:09:28 +08:00
:deep(.arco-tag) {
display: inline-flex;
align-items: center;
margin-right: 6px;
cursor: pointer;
&:first-child {
.arco-tag-close-btn {
display: none;
2023-06-05 21:02:25 +08:00
}
}
}
}
}
2023-06-08 21:09:28 +08:00
}
2023-06-05 21:02:25 +08:00
2023-06-08 21:09:28 +08:00
.tag-bar-operation {
width: 100px;
height: 32px;
2023-06-05 21:02:25 +08:00
}
2023-06-08 21:09:28 +08:00
}
2023-06-05 21:02:25 +08:00
</style>