BaseTabs.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <script setup lang="ts">
  2. const props = defineProps<{
  3. data: any[];
  4. type: string;
  5. listWidth: string;
  6. }>()
  7. const { locale } = useI18n();
  8. const emit = defineEmits<{
  9. (e:'on-click', i: number): void
  10. }>()
  11. const modelValue = defineModel<number>();
  12. const tabItemWidth = computed(() => {
  13. // const proportion = Number((100 / props.data.length).toFixed(2));
  14. return props.data.length === 4 ? 'w-[50%]' : 'w-[33%]';
  15. })
  16. const handleClickTab = (index: number) => {
  17. if (process.client) {
  18. const scrollTop = document.documentElement.scrollTop;
  19. if ( scrollTop >= 506 ) {
  20. window.scrollTo({ top: 437, left: 0, behavior: 'smooth' });
  21. }
  22. }
  23. modelValue.value = index;
  24. emit('on-click', index);
  25. }
  26. </script>
  27. <template>
  28. <n-affix :top="70" :trigger-top="70">
  29. <div class="tab-container" :class="locale">
  30. <ul
  31. class="tab-list px-[10px] text-[16px] md:text-[18px]"
  32. :class="[type === 'center'? 'center' : 'between']"
  33. :style="listWidth === '1380'&& locale === 'en'? 'max-width: 1380px; margin: 0 auto;' : ''"
  34. >
  35. <li v-for="(item, index) in data" :key="item.langKey"
  36. :class="['tab-item', tabItemWidth, 'md:w-[25%]', { active: index === modelValue }]"
  37. @click="handleClickTab(index)"
  38. >
  39. <span class="px-[20px] py-[5px] md:py:[10px]">{{ $t(item.langKey) }}</span>
  40. </li>
  41. </ul>
  42. </div>
  43. </n-affix>
  44. </template>
  45. <style scoped lang="scss">
  46. .n-affix {
  47. z-index: 101;
  48. }
  49. .tab-container {
  50. width: 100vw;
  51. background: linear-gradient(90deg, #A5EAFD 0%, #6CF098 100%);
  52. .n-affix {
  53. z-index: 10;
  54. }
  55. }
  56. .tab-list {
  57. display: flex;
  58. align-items: center;
  59. flex-flow: wrap;
  60. max-width: 1080px;
  61. margin: 0 auto;
  62. padding-top: 16px;
  63. padding-bottom: 16px;
  64. line-height: 26px;
  65. color: $t-color-primary;
  66. .tab-item {
  67. text-align: center;
  68. white-space: nowrap;
  69. cursor: pointer;
  70. span {
  71. border: 1px solid transparent;
  72. display: inline-block;
  73. padding: 10px 20px;
  74. }
  75. }
  76. .active {
  77. span {
  78. border-color: #000;
  79. border-radius: 24px;
  80. font-weight: bold;
  81. transition: all 0.3s;
  82. }
  83. }
  84. }
  85. .center {
  86. justify-content: center;
  87. }
  88. .between {
  89. justify-content: space-between;
  90. }
  91. @media screen and (max-width: 640px) {
  92. .en {
  93. .tab-list {
  94. padding: 10px 0;
  95. .tab-item {
  96. font-size: 12px;
  97. span {
  98. padding: 10px;
  99. }
  100. }
  101. }
  102. .tab-container{
  103. .tab-list{
  104. .tab-item {
  105. width: 100%;
  106. }
  107. }
  108. }
  109. }
  110. }
  111. .en{
  112. .tab-list{
  113. /*max-width: 1280px;*/
  114. .tab-item {
  115. width: 25%;
  116. font-size: 14px !important;
  117. }
  118. }
  119. }
  120. </style>