index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <van-tabs :class="clazz" :active="tabActive" :ellipsis="false" @change="tabChange">
  3. <template v-for="(item, index) in tabs">
  4. <van-tab class="u-tab" :title="item.label" :name="item.value" :key="item.value"></van-tab>
  5. </template>
  6. </van-tabs>
  7. </template>
  8. <script>
  9. import VanTabs from '@/wxcomponents/vant/tabs/index'
  10. import VanTab from '@/wxcomponents/vant/tab/index'
  11. export default {
  12. options: {
  13. styleIsolation: 'shared'
  14. },
  15. components: {
  16. VanTabs,
  17. VanTab
  18. },
  19. props: {
  20. tabStyle: String,
  21. active: [String, Number],
  22. tabs: [Array]
  23. },
  24. computed: {
  25. clazz() {
  26. if (this.tabStyle === 'default') {
  27. return 'u-tabs u-tabs-detault'
  28. } else if (this.tabStyle === 'tag') {
  29. return 'u-tabs u-tabs-tag'
  30. } else {
  31. return 'u-tabs'
  32. }
  33. }
  34. },
  35. watch: {
  36. active(val) {
  37. this.tabActive = val
  38. }
  39. },
  40. data() {
  41. return {
  42. tabActive: undefined,
  43. data: [{
  44. label: '表面贴装',
  45. value: 1
  46. }, {
  47. label: '线束加工',
  48. value: 2
  49. }, {
  50. label: '工厂自动化',
  51. value: 3
  52. }, {
  53. label: '点胶注胶',
  54. value: 4
  55. }, {
  56. label: '电子制造服务',
  57. value: 5
  58. }, {
  59. label: '未来服务',
  60. value: 6
  61. }]
  62. }
  63. },
  64. created() {
  65. this.tabActive = this.active
  66. },
  67. mounted() {
  68. },
  69. methods: {
  70. tabChange(tab) {
  71. const e = {}
  72. e.detail = {
  73. index: tab.index,
  74. label: tab.title,
  75. value: tab.name
  76. }
  77. this.tabActive = e.detail.value
  78. this.$emit('update:active', this.tabActive)
  79. this.$emit('change', e)
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. .u-tabs{
  86. .van-tabs__scroll{
  87. background-color: transparent;
  88. }
  89. }
  90. .u-tabs.u-tabs-tag {
  91. --tabs-line-height: 64rpx;
  92. --tabs-card-height: 64rpx;
  93. --tabs-bottom-bar-height: rpx;
  94. --tab-active-text-color: #E57519;
  95. --tab-background-color: #F5F5F5;
  96. --tab-active-background-color: #F9E3D1;
  97. --tab-margin-right: 10rpx;
  98. --tab-border-radius: 20rpx;
  99. .van-tab{
  100. font-size: $fontSize3;
  101. line-height: 50rpx;
  102. }
  103. .van-tabs--line{
  104. height: 50rpx;
  105. }
  106. .van-tabs__scroll--line{
  107. height: 100%;
  108. }
  109. }
  110. .u-tabs.u-tabs-detault{
  111. --tabs-line-height: 48rpx;
  112. --tabs-card-height: 50rpx;
  113. --tabs-bottom-bar-height: 0;
  114. --tab-active-text-color: #FFFFFF;
  115. --tab-background-color: #FFFFFF;
  116. --tab-active-background-color: #E57519;
  117. --tab-margin-right: 12rpx;
  118. --tab-border-radius: 6rpx;
  119. .van-tabs__nav{
  120. padding: 0;
  121. }
  122. .van-tab{
  123. font-size: $fontSize2;
  124. border: 1rpx solid #7D7D7D;
  125. height: 50rpx;
  126. color: #7D7D7D;
  127. }
  128. .van-tab--active{
  129. border-color: #E57519!important;
  130. color: #FFFFFF;
  131. }
  132. .van-tabs__wrap--scrollable .van-tab--complete{
  133. flex: none!important;
  134. padding: 0 30rpx;
  135. }
  136. .van-tabs--line{
  137. height: 50rpx;
  138. }
  139. }
  140. .u-tab{
  141. margin-right: 20rpx;
  142. }
  143. </style>