SubNav.vue 1.63 KB
<template>
  <div class="scrm-base-sub-nav">
    <el-tabs v-model="activeName" @tab-click="handleClick()">
      <el-tab-pane :label="item.title" :name="item.path" v-for="item in subNavs" :key="item.id"></el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'SubNav',
  data() {
    return {
      activeName: '',
      subNavs: []
    }
  },
  mounted() {},
  methods: {
    handleClick() {}
  },
  computed: {
    ...mapGetters(['app'])
  },
  watch: {
    activeName(n) {
      if (n.startsWith('/')) {
        this.$router.push(n)
      }
    },
    'app.currentNav2': {
      handler(v) {
        if (!v) return
        const sub = v.children
        if (sub && sub.length) {
          this.subNavs = sub.filter(item => !item.hidden)
        }
        const curPage = this.app.currentPage
        if (curPage) {
          const nav2 = this.app.currentNav2
          if (nav2 && curPage.id.startsWith(nav2.id)) {
            this.activeName = curPage.path
            return
          }
        }
        if (this.subNavs && this.subNavs.length) {
          this.activeName = this.subNavs[0].path
        }
      },
      immediate: true
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/style/variables.scss';
.scrm-base-sub-nav {
  /deep/.el-tabs {
    &__nav-wrap {
      &::after {
        opacity: 0;
      }
    }
    &__item {
      &.is-active,
      &:hover {
        color: $main-color;
      }
      font-weight: 400;
      color: #717171;
      height: 36px;
      line-height: 36px;
    }
    &__active-bar {
      background-color: $main-color;
    }
  }
}
</style>