index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.u-tabs-tag {
  86. --tabs-line-height: 64rpx;
  87. --tabs-card-height: 64rpx;
  88. --tabs-bottom-bar-height: rpx;
  89. --tab-active-text-color: #E57519;
  90. --tab-background-color: #F5F5F5;
  91. --tab-active-background-color: #F9E3D1;
  92. --tab-margin-right: 10rpx;
  93. --tab-border-radius: 20rpx;
  94. .van-tab{
  95. font-size: $fontSize2;
  96. line-height: 50rpx;
  97. }
  98. .van-tabs--line{
  99. height: 50rpx;
  100. }
  101. .van-tabs__scroll--line{
  102. height: 100%;
  103. }
  104. }
  105. .u-tabs.u-tabs-detault{
  106. --tabs-line-height: 48rpx;
  107. --tabs-card-height: 50rpx;
  108. --tabs-bottom-bar-height: 0;
  109. --tab-active-text-color: #FFFFFF;
  110. --tab-background-color: #FFFFFF;
  111. --tab-active-background-color: #E57519;
  112. --tab-margin-right: 12rpx;
  113. --tab-border-radius: 6rpx;
  114. .van-tabs__nav{
  115. padding: 0;
  116. }
  117. .van-tab{
  118. font-size: $fontSize1;
  119. border: 1rpx solid #7D7D7D;
  120. height: 50rpx;
  121. color: #7D7D7D;
  122. }
  123. .van-tab--active{
  124. border-color: #E57519!important;
  125. color: #FFFFFF;
  126. }
  127. .van-tabs__wrap--scrollable .van-tab--complete{
  128. flex: none!important;
  129. padding: 0 30rpx;
  130. }
  131. .van-tabs--line{
  132. height: 50rpx;
  133. }
  134. }
  135. .u-tab{
  136. margin-right: 20rpx;
  137. }
  138. </style>