<template>
  <div id="app">
    <el-container>
      <layout-header></layout-header>
      <el-container class="layout-container__component">
        <el-aside class="layout-aside__component" width="200px">
          <el-menu :default-active="activeMenu" class="layout-aside-menu__component" @select="handleSelect">
            <h4 style="padding: 0 20px;">组件</h4>
            <el-menu-item-group v-for="(component, idx) in components" :key="idx">
              <template slot="title">{{ component.group }}</template>
              <el-menu-item v-for="(data, index) in component.children" :key="index" :index="data.name">{{ data.meta.title }}</el-menu-item>
            </el-menu-item-group>
          </el-menu>
        </el-aside>
        <el-main class="layout-main__component">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import LayoutHeader from './components/header';
import { components } from '@/router/routes';

export default {
  name: 'componentLayout',
  components: { LayoutHeader },
  data() {
    return {
      activeMenu: 'select',
      components
    }
  },
  created() {
    const { name } = this.$route || {};
    this.activeMenu = name;
  },
  methods: {
    handleSelect(key) {
      this.$router.push({ name: key });
    }
  }
}
</script>

<style lang="scss">
@import '@/styles/variables.scss';

.layout-container__component {
  margin-top: 60px;
  .layout-aside__component {
    &::after {
      position: absolute;
      top: 50%;
      right: 0;
      content: '';
      display: inline-block;
      transform: translateY(-50%);
      height: 90%;
      border-right: 1px solid #e6e6e6;
    }
    position: fixed;
    height: calc(100vh - 60px);
    background: #fff;
    .el-menu-item {
      border-right: 3px solid rgba(0, 0, 0, 0);
    }
    .el-menu-item.is-active {
      background-color: rgba($primary, 0.1);
      border-right: 3px solid $primary;
    }
    .el-menu-item, .el-submenu__title {
      height: 40px;
      line-height: 40px;
    }
    .layout-aside-menu__component {
      background: transparent;
      border-right: 0;
    }
  }
  .layout-main__component {
    margin-left: 200px;
    padding: 20px 40px;
  }
}
</style>
