tabs.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <!-- components/tabs/tabs.wxml -->
  3. <view class="tabs tab-class">
  4. <view class="tabs-header tab-header-class">
  5. <view class="tabs-header-content">
  6. <view class="tabs-item tab-item-class" @tap="selectIndexFun" :data-index="index" v-for="(item, index) in list" :key="index">
  7. <view class="tabs-item-name tab-item-name-class" :style="'color: ' + (currentClone == index ? activeColor : normalColor) + ';'">{{ item.name }}</view>
  8. <view :style="'width: 100%;height:10rpx;display: block; background: ' + (currentClone == index ? activeColor : '#FFFFFF00') + ';border-radius: 4rpx;'"></view>
  9. <view class="tabs-item-badge tab-item-badge-class" v-if="showBadge && item.count > 0">{{ item.count }}</view>
  10. </view>
  11. </view>
  12. </view>
  13. <swiper class="tabs-page tab-page-class" :current="currentClone" :circular="circular" @change="swiperChangeFun">
  14. <swiper-item @touchmove.stop.prevent="parseEventDynamicCode($event, swiper ? '' : '_onTouchMove')" v-for="(item, index) in list" :key="index">
  15. <slot :name="item.name"></slot>
  16. </swiper-item>
  17. </swiper>
  18. </view>
  19. </template>
  20. <script>
  21. // components/tabs/tabs.js
  22. export default {
  23. unicomGroup: ['tab-page'],
  24. data() {
  25. return {
  26. currentClone: ''
  27. };
  28. },
  29. /**
  30. * 组件的属性列表
  31. */
  32. props: {
  33. list: {
  34. type: Array,
  35. default: () => []
  36. },
  37. current: {
  38. type: Number,
  39. default: 0
  40. },
  41. normalColor: {
  42. type: String,
  43. default: '#101010'
  44. },
  45. activeColor: {
  46. type: String,
  47. default: '#55b428'
  48. },
  49. showBadge: {
  50. type: Boolean,
  51. default: true
  52. },
  53. circular: {
  54. type: Boolean,
  55. default: true
  56. },
  57. swiper: {
  58. type: Boolean,
  59. default: false
  60. }
  61. },
  62. relations: {
  63. '../tab-page/tab-page': {
  64. type: 'child'
  65. }
  66. },
  67. options: {
  68. multipleSlots: true
  69. },
  70. externalClasses: ['tab-class', 'tab-header-class', 'tab-item-class', 'tab-item-name-class', 'tab-item-badge-class', 'tab-page-class'],
  71. /**
  72. * 组件的方法列表
  73. */
  74. methods: {
  75. selectIndexFun: function (e) {
  76. this.currentClone = e.currentTarget.dataset.index
  77. this.$emit('change', {
  78. detail: {
  79. current: e.currentTarget.dataset.index
  80. }
  81. });
  82. },
  83. swiperChangeFun: function (e) {
  84. this.currentClone = e.detail.current
  85. this.$emit('change', {
  86. detail: {
  87. current: e.detail.current
  88. }
  89. });
  90. },
  91. onTouchMoveFun: function (e) {}
  92. },
  93. created: function () {},
  94. watch: {
  95. current: {
  96. handler: function (newVal, oldVal) {
  97. this.currentClone = newVal;
  98. },
  99. immediate: true
  100. }
  101. }
  102. };
  103. </script>
  104. <style>
  105. @import './tabs.css';
  106. </style>