index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="tab-bar-container">
  3. <a-affix ref="affixRef" :offset-top="offsetTop">
  4. <div class="tab-bar-box">
  5. <div class="tab-bar-scroll">
  6. <div class="tags-wrap">
  7. <tab-item
  8. v-for="(tag, index) in tagList"
  9. :key="tag.fullPath"
  10. :index="index"
  11. :item-data="tag"
  12. />
  13. </div>
  14. </div>
  15. <div class="tag-bar-operation"></div>
  16. </div>
  17. </a-affix>
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. import { ref, computed, watch, onUnmounted } from 'vue';
  22. import type { RouteLocationNormalized } from 'vue-router';
  23. import {
  24. listenerRouteChange,
  25. removeRouteListener,
  26. } from '@/utils/route-listener';
  27. import { useAppStore, useTabBarStore } from '@/store';
  28. import tabItem from './tab-item.vue';
  29. const appStore = useAppStore();
  30. const tabBarStore = useTabBarStore();
  31. const affixRef = ref();
  32. const tagList = computed(() => {
  33. return tabBarStore.getTabList;
  34. });
  35. const offsetTop = computed(() => {
  36. return appStore.navbar ? 60 : 0;
  37. });
  38. watch(
  39. () => appStore.navbar,
  40. () => {
  41. affixRef.value.updatePosition();
  42. }
  43. );
  44. listenerRouteChange((route: RouteLocationNormalized) => {
  45. if (
  46. !route.meta.noAffix &&
  47. !tagList.value.some((tag) => tag.fullPath === route.fullPath)
  48. ) {
  49. tabBarStore.updateTabList(route);
  50. }
  51. }, true);
  52. onUnmounted(() => {
  53. removeRouteListener();
  54. });
  55. </script>
  56. <style scoped lang="less">
  57. .tab-bar-container {
  58. position: relative;
  59. background-color: var(--color-bg-2);
  60. .tab-bar-box {
  61. display: flex;
  62. padding: 0 0 0 20px;
  63. background-color: var(--color-bg-2);
  64. border-bottom: 1px solid var(--color-border);
  65. .tab-bar-scroll {
  66. height: 32px;
  67. flex: 1;
  68. overflow: hidden;
  69. .tags-wrap {
  70. padding: 4px 0;
  71. height: 48px;
  72. white-space: nowrap;
  73. overflow-x: auto;
  74. :deep(.arco-tag) {
  75. display: inline-flex;
  76. align-items: center;
  77. margin-right: 6px;
  78. cursor: pointer;
  79. &:first-child {
  80. .arco-tag-close-btn {
  81. display: none;
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. .tag-bar-operation {
  89. width: 100px;
  90. height: 32px;
  91. }
  92. }
  93. </style>