ui-tabs.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="tab-box">
  3. <view class="tab-box-scroll">
  4. <view class="tab-box-item" :class="{ 'active': active === item[nodeKey] }" :style="customStyle"
  5. v-for="(item, index) in list" :key="index" @tap="tabsClick(item[nodeKey])">
  6. {{item[nodeValue]}}
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. /**
  13. ** ui-tabs 组件
  14. * 作者:李成龙
  15. * @property {[Number|String,|Boolean} active 当前选中默认值
  16. * @property {Array} list 选项列表
  17. * @property {Number} size 字体大小
  18. * @description 通用tab选项组件
  19. * @example
  20. */
  21. import {
  22. throttle
  23. } from '@/utils/utils.js'
  24. export default {
  25. name: "ui-tabs",
  26. props: {
  27. active: {
  28. type: [Number, String, Boolean],
  29. default: 1
  30. },
  31. list: {
  32. type: Array,
  33. default: () => {
  34. return []
  35. }
  36. },
  37. size: {
  38. type: Number,
  39. default: 28
  40. },
  41. defaultProps: {
  42. type: Object,
  43. default () {
  44. return {
  45. text: "text",
  46. value: "value"
  47. }
  48. }
  49. },
  50. wait: {
  51. type: Number,
  52. default: 500
  53. },
  54. // 整个组件的样式
  55. customStyle: {
  56. type: Object,
  57. default () {
  58. return {}
  59. }
  60. }
  61. },
  62. computed: {
  63. nodeKey() {
  64. return this.defaultProps.value;
  65. },
  66. nodeValue() {
  67. return this.defaultProps.text;
  68. },
  69. },
  70. mounted() {
  71. this.tabsClick = throttle(this.tabsClick, this, this.wait);
  72. },
  73. methods: {
  74. tabsClick(type) {
  75. this.$emit('clickTab', type)
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .tab-box {
  82. position: relative;
  83. z-index: 10;
  84. overflow-x: scroll;
  85. display: flex;
  86. width: 100%;
  87. font-size: 30rpx;
  88. background-color: #fff;
  89. box-shadow: 0 5rpx 5rpx rgba(0, 0, 0, 0.02);
  90. .tab-box-scroll{
  91. display: flex;
  92. width: max-content;
  93. }
  94. .tab-box-item {
  95. display: inline-block;
  96. box-sizing: border-box;
  97. width: max-content;
  98. height: 90rpx;
  99. padding: 0 32rpx;
  100. line-height: 90rpx;
  101. text-align: center;
  102. }
  103. .active {
  104. position: relative;
  105. font-size: 32rpx;
  106. color: #333;
  107. &::after {
  108. content: ' ';
  109. display: block;
  110. width: 100rpx;
  111. height: 7rpx;
  112. position: absolute;
  113. border-radius: 100px;
  114. bottom: 0rpx;
  115. margin: auto;
  116. left: 0;
  117. right: 0;
  118. background-color: $color-primary;
  119. }
  120. }
  121. }
  122. </style>