<template>
  <div :class="{'has-logo':showLogo}">
    <logo v-if="showLogo" :collapse="isCollapse" />
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <el-menu :collapse="isCollapse" :unique-opened="true" :background-color="variables.menuBg"
        :collapse-transition="false" mode="vertical">
        <sidebar-item v-for="menu in menuItems" :key="menu.path" :item="menu" :base-path="menu.path"
                      @menuClick="menuClick"/>
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Logo from './Logo'
import SidebarItem from './SidebarItem'
import variables from '../../../styles/variables.scss'
export default {
  components: { SidebarItem, Logo },
  computed: {
    ...mapGetters([
      'sidebar',
       'menuItems'
    ]),
    showLogo() {
      return this.$store.state.settings.sidebarLogo
    },
    variables() {
      return variables
    },
    isCollapse() {
      return !this.sidebar.opened
    }
  },
    mounted(){
      //如果地址有需要马上打开的菜单？
      if(this.$route.query.menuId) {
        this.$store.dispatch("openMenu",{id:this.$route.query.menuId,default:this.menuItems[0]});
      }else{
        this.$emit("openMenu",this.menuItems[0]);
      }
    },
    methods:{
        menuClick(menu){
            this.$emit("openMenu",menu);
        }
    }
}
</script>
