wuc-tab.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <scroll-view class="wuc-tab" :class="tabClass" :style="tabStyle" scroll-with-animation scroll-x
  3. :scroll-left="scrollLeft" style="background: #fff">
  4. <div v-if="!textFlex">
  5. <div class="wuc-tab-item" :class="[index === tabCur ? selectClass + ' cur':'']"
  6. v-for="(item,index) in tabList" :key="index" :id="index" @tap="tabSelect(index,$event)">
  7. <text :class="item.icon"></text>
  8. <span>{{item.name}}</span>
  9. <text class="cur-line"></text>
  10. </div>
  11. </div>
  12. <div class="flex text-center" v-if="textFlex">
  13. <div class="wuc-tab-item flex-sub" :class="index === tabCur ? selectClass + ' cur':''"
  14. v-for="(item,index) in tabList" :key="index" :id="index" @tap="tabSelect(index,$event)">
  15. <text :class="item.icon"></text>
  16. <span>{{item.name}}</span>
  17. <text class="cur-line"></text>
  18. </div>
  19. </div>
  20. </scroll-view>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'wuc-tab',
  25. data() {
  26. return {};
  27. },
  28. props: {
  29. tabList: {
  30. type: Array,
  31. default () {
  32. return [];
  33. }
  34. },
  35. tabCur: {
  36. type: Number,
  37. default () {
  38. return 0;
  39. }
  40. },
  41. tabClass: {
  42. type: String,
  43. default () {
  44. return '';
  45. }
  46. },
  47. tabStyle: {
  48. type: String,
  49. default () {
  50. return '';
  51. }
  52. },
  53. textFlex: {
  54. type: Boolean,
  55. default () {
  56. return true;
  57. }
  58. },
  59. selectClass: {
  60. type: String,
  61. default () {
  62. return 'text-blue';
  63. }
  64. }
  65. },
  66. methods: {
  67. tabSelect(index, e) {
  68. if (this.currentTab === index) return false;
  69. this.$emit('update:tabCur', index);
  70. this.$emit('change', index);
  71. }
  72. },
  73. computed: {
  74. scrollLeft() {
  75. return (this.tabCur - 1) * 60;
  76. }
  77. }
  78. };
  79. </script>
  80. <style>
  81. div,
  82. scroll-view,
  83. swiper {
  84. box-sizing: border-box;
  85. }
  86. .wuc-tab {
  87. white-space: nowrap;
  88. }
  89. .wuc-tab-item {
  90. display: inline-block;
  91. height: 90upx;
  92. line-height: 90upx;
  93. padding: 0 10px;
  94. font-size: 16px;
  95. color: #999;
  96. border-bottom: solid 1px #f5f5f5;
  97. }
  98. .wuc-tab-item.cur {
  99. color: #4779ff;
  100. position: relative;
  101. }
  102. .cur .cur-line {
  103. position: absolute;
  104. width: 50px;
  105. height: 2px;
  106. background: #4779ff;
  107. bottom: -1px;
  108. left: 36%;
  109. border-radius: 4px;
  110. }
  111. .wuc-tab.fixed {
  112. position: fixed;
  113. width: 100%;
  114. top: 0;
  115. z-index: 1024;
  116. box-shadow: 0 1upx 6upx rgba(0, 0, 0, 0.1);
  117. }
  118. .flex {
  119. display: flex;
  120. }
  121. .text-center {
  122. text-align: center;
  123. }
  124. .flex-sub {
  125. flex: 1;
  126. }
  127. .text-blue {
  128. font-weight: bold;
  129. }
  130. .text-white {
  131. color: #ffffff;
  132. }
  133. .bg-white {
  134. background-color: #ffffff;
  135. }
  136. .bg-blue {
  137. background-color: #c00000;
  138. }
  139. .text-orange {
  140. color: #f37b1d
  141. }
  142. .text-xl {
  143. font-size: 16px;
  144. }
  145. </style>