tabs.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="tab" :class="isRow ? 'tab_row' : ''">
  3. <view
  4. class="tab_list"
  5. :class="[activeNum == index ? 'active' : '', isRow ? 'tab_list_row' : '']"
  6. v-for="(item, index) in tabList"
  7. :key="index"
  8. @click="tabClick(item, index)"
  9. :style="{ fontSize: size, height: height }"
  10. >
  11. <i class="icon-font" :class="item.icon" v-if="item.icon"></i>
  12. <image class="img" :src="item.img" v-if="item.img"></image>
  13. <trans :_t="keyName ? item[keyName] : item" v-if="!isTran" />
  14. <text v-else>{{ keyName ? item[keyName] : item }}</text>
  15. <view class="tab-badge" v-if="item.badge > 0">{{ item.badge }}</view>
  16. </view>
  17. </view>
  18. </template>
  19. <script setup>
  20. import { ref, computed, onMounted, watch, nextTick } from "vue";
  21. import { debounce } from "@/utils";
  22. const props = defineProps({
  23. tabList: {
  24. type: Object,
  25. default: () => [],
  26. },
  27. keyName: {
  28. type: String,
  29. default: "",
  30. },
  31. active: {
  32. type: Number,
  33. default: 0,
  34. },
  35. size: {
  36. type: String,
  37. default: "32rpx",
  38. },
  39. height: {
  40. type: String,
  41. default: "110rpx",
  42. },
  43. isTran: Boolean,
  44. isRow: Boolean,
  45. });
  46. const emit = defineEmits(["confirm"]);
  47. const activeNum = computed(() => props.active);
  48. const tabClick = (item, index) => {
  49. emit("confirm", item, index);
  50. };
  51. </script>
  52. <style lang="less" scoped>
  53. @import url("@/style.less");
  54. .tab {
  55. .ver();
  56. gap: 16rpx;
  57. overflow-x: auto;
  58. overflow-y: hidden;
  59. scrollbar-width: none;
  60. -ms-overflow-style: none;
  61. padding: 0 16rpx;
  62. &.tab_row {
  63. gap: 16rpx 44rpx;
  64. }
  65. &::-webkit-scrollbar {
  66. display: none;
  67. }
  68. .tab_list {
  69. flex: 1;
  70. padding: 0 24rpx;
  71. white-space: nowrap;
  72. color: var(--text-01);
  73. font-weight: 700;
  74. // line-height: 60rpx;
  75. position: relative;
  76. text-align: center;
  77. .flex_center();
  78. &.tab_list_row {
  79. flex: none;
  80. height: auto;
  81. min-width: auto;
  82. }
  83. .icon-font {
  84. .size(48rpx);
  85. font-weight: 400;
  86. }
  87. .img {
  88. width: 48rpx;
  89. height: 48rpx;
  90. display: block;
  91. margin-right: 6rpx;
  92. }
  93. .tab-badge {
  94. position: absolute;
  95. top: 16rpx;
  96. right: 30%;
  97. min-width: 32rpx;
  98. height: 32rpx;
  99. padding: 0 8rpx;
  100. background-color: #f53f3f;
  101. color: #fff;
  102. .size(24rpx);
  103. border-radius: 16rpx;
  104. text-align: center;
  105. line-height: 32rpx;
  106. }
  107. &::before {
  108. position: absolute;
  109. content: "";
  110. bottom: 0;
  111. left: 0;
  112. right: 0;
  113. height: 4px;
  114. border-radius: 50rpx;
  115. background-color: transparent;
  116. }
  117. }
  118. .active {
  119. color: var(--black);
  120. &::before {
  121. background-color: var(--black);
  122. }
  123. }
  124. }
  125. </style>