<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">
            <h3 style="padding: 0 20px;">组件</h3>
            <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">
.layout-container__component {
  margin-top: 60px;
  .layout-aside__component {
    position: fixed;
    height: calc(100vh - 60px);
    background: #f5f7fb;
    box-shadow: 0px 0px 16px #e6e6e6;
    .layout-aside-menu__component {
      background: #f5f7fb;
      border-right: 0;
    }
  }
  .layout-main__component {
    margin-left: 200px;
    padding: 20px 40px;
  }
}
</style>
