<template>
    <div class="sidebar-container">
        <el-menu :default-active="activeMenu" :collapse="collapse" :collapse-transition="false" unique-opened>
            <sidebar-item v-for="(item, index) in menus" :key="index" :item="item" :index="index" />
        </el-menu>
    </div>
</template>

<script>
import SidebarItem from './SidebarItem'

export default {
    components: { SidebarItem },
    props: {
        menus: {
            type: Array,
            default: []
        },
        collapse: {
            type: Boolean,
            default: false
        }
    },
    watch: {
        collapse() {
            setTimeout(() => {
                window.echartsArr &&
                    window.echartsArr.forEach(item => {
                        item.resize()
                    })
            }, 200)
        }
    },
    computed: {
        activeMenu() {
            if (this.$route.meta.activeMenu) {
                return this.$route.meta.activeMenu
            }
            if(this.$route.fullPath.indexOf('iframe') > -1){
                return this.$route.fullPath
            }else{
                return this.$route.path
            }
        }
    }
}
</script>
<style lang="scss" scoped>
@import './sidebar.scss';
</style>
