<template>
  <div class="system bgw flex flexc">
    <el-tabs :value="activeKey" @tab-click="changeRouter">
      <el-tab-pane v-for="v in subMenus" :key="v.path" :name="v.path">
        <template slot="label">
          <i v-if="v.meta.icon" :class="['mr5', 'primary', v.meta.icon]"></i>
          <span class="tab-label">{{ v.meta.title }}</span>
        </template>
      </el-tab-pane>
    </el-tabs>
    <div class="system-out-box flex1">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import { findBottomSubarrays } from "@/utils";
export default {
  data() {
    return {
      subMenus: [],
    };
  },
  computed: {
    activeKey() {
      return this.$route.path;
    },
  },
  created() {
    this.getSubMenus();
  },
  methods: {
    changeRouter(e) {
      this.$router.push(e.name);
    },
    // 获取当前顶层路由下的所有子路由
    getSubMenus() {
      let path = this.$route?.meta.activeMenu
        ? this.$route.meta.activeMenu
        : this.$route.path;
      let options = this.$router.options.routes[0].children;
      let curRouters = options.filter((v) => v.path == path);
      this.subMenus = findBottomSubarrays(curRouters).filter(
        (v) => !v.meta.hidden
      );
    },
  },
};
</script>

<style lang="less" scoped>
:deep(.el-tabs__nav-scroll) {
  padding-left: 15px;
}
.system {
  width: 100%;
  height: 100%;
  .system-out-box {
    padding: 15px;
    overflow-y: auto;
  }
}
</style>