tab-item.vue 2.47 KB
Newer Older
Nature's avatar
Nature committed
1
<template>
Nature's avatar
Nature committed
2
  <section :class="[tabClass]" class="h-tab-item" @click="titleClick">
Nature's avatar
Nature committed
3 4
    <div class="h-item">
      <slot/>
5
      <div class="bottom-border"/>
Nature's avatar
Nature committed
6
    </div>
Nature's avatar
Nature committed
7 8
    <div v-show="showDivider" class="tab-divider"/>
  </section>
Nature's avatar
Nature committed
9

Nature's avatar
Nature committed
10 11 12 13 14 15
</template>

<script>
export default {
  name: 'TabItem',
  data () {
Nature's avatar
Nature committed
16 17 18
    return {

    }
Nature's avatar
Nature committed
19 20 21 22 23
  },
  computed: {
    showDivider () {
      return this.$parent.showDivider
    },
Nature's avatar
Nature committed
24 25 26 27 28
    tabClass () {
      if (this.$parent.hasBorder) {
        return this.$parent.position === 'top' ? 'vue-1px-b' : 'vue-1px-t'
      }
    },
Nature's avatar
Nature committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  },
  mounted () {
    this.$parent && this.$parent.items.push(this)
    this.$el.setAttribute('data-index', this.$parent.items.length - 1)
  },
  destroyed () {
    this.$parent && this.$parent.items.splice(this.$parent.items.indexOf(this), 1)
  },
  methods: {
    titleClick (event) {
      let vm = this
      vm.$parent.items.forEach(item => {
        item.$el.classList.remove('activated')
      })
      let clickIndex = Number(event.currentTarget.getAttribute('data-index'))
      event.currentTarget.classList.remove('activated')
      event.currentTarget.classList.add('activated')
Nature's avatar
Nature committed
46 47
      let clientWidth = event.currentTarget.clientWidth
      vm.$parent.actived(clickIndex, clientWidth)
Nature's avatar
Nature committed
48
    },
Nature's avatar
Nature committed
49

Nature's avatar
Nature committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  },
}
</script>

<style lang="less">
  .hls-switch-tab {

    .tab-content {
      width: 100%;
      display: flex;
      align-items: center;

      .h-tab-item {
        width: 100%;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
68
        position: relative;
Nature's avatar
Nature committed
69

Nature's avatar
Nature committed
70
        .h-item {
71 72
          width: 100%;
          min-width: 80px;
Nature's avatar
Nature committed
73 74 75 76 77 78 79
          font-size: 14px;
          height: 40px;
          color: #7c828d;
          line-height: 15px;
          display: flex;
          align-items: center;
          justify-content: center;
Nature's avatar
Nature committed
80
         // padding: 0 3px;
Nature's avatar
Nature committed
81
          border-bottom: 1px solid rgba(255, 255, 255, .0); /*no*/
82 83 84
          .bottom-border{
            bottom: 0;
          }
Nature's avatar
Nature committed
85 86
        }

Nature's avatar
Nature committed
87
        &.activated {
Nature's avatar
Nature committed
88
          .h-item {
89 90
            color: @headerColor;
            .bottom-border{
JingChao's avatar
JingChao committed
91 92
              width: 65%;
              position: absolute;
93 94
              border-bottom: 1px solid @headerColor; /*no*/
            }
Nature's avatar
Nature committed
95 96 97
          }
        }
        .tab-divider {
Nature's avatar
Nature committed
98 99 100 101 102 103 104 105 106
          width: 1px; /*no*/
          height: 50%;
          background-color: rgb(214, 217, 218);
        }

        &:last-child {
          .tab-divider {
            width: 0px;
          }
Nature's avatar
Nature committed
107 108 109 110 111 112
        }
      }
    }
  }

</style>