<template>
  <el-scrollbar wrap-class="scrollbar-wrapper">
    <el-menu
      :show-timeout="200"
      :default-active="activeMenu"
      :collapse="isCollapse"
      mode="vertical"
    >
      <sidebar-item v-for="route in permission_routers" :key="route.name" :item="route" :base-path="route.path"/>
    </el-menu>
  </el-scrollbar>
</template>

<script>
import { mapGetters } from 'vuex'
import SidebarItem from './SidebarItem'

export default {
  components: { SidebarItem },
  computed: {
    ...mapGetters([
      'sidebar'
    ]),
    permission_routers() {
      let permission_routers = this.$store.getters.permission_routers
      const currentSystem = this.$store.getters.currentSystem
      permission_routers = permission_routers.filter(item => {
        if (item.meta && item.meta.sys && item.meta.sys === currentSystem.url) {
          return true
        }
      })
      return permission_routers
    },
    activeMenu() {
      const route = this.$route
      const { meta, path } = route
      // 如果meta中上设置activeMenu，按照meta中设置高亮
      if (meta.activeMenu) {
        return meta.activeMenu
      }
      return path
    },
    isCollapse() {
      return !this.sidebar.opened
    }
  }
}
</script>
