<template>
  <div class="elmenu" :class="{'has-logo':showLogo}">
    <logo v-if="showLogo" :collapse="isCollapse"/>
    <el-scrollbar wrap-class="scrollbar-wrapper">

      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color="variables.menuBg"
        :text-color="variables.menuText"
        :unique-opened="false"
        :active-text-color="variables.menuActiveText"
        :collapse-transition="false"
        mode="vertical"
      >
        <sidebar-item v-for="route in allRoute" :key="route.path" :item="route" :base-path="route.path"/>
      </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'
  import generateMenus from '@/utils/menus'
  export default {
    components: {SidebarItem, Logo},
    data() {
      return {
        allRoute: {},
        fileUploadNodeShowSysValue: '1',
      }
    },
    created() {
      this.allRoute = this.$router.options.routes
      // this.getMenu()
    },
    destoryed() {
      this.allRoute = {}
    },
    mounted(){
      // this.getCookie()

    },
    methods: {
      getMenu() {
        this.$axios.get('/sysMenuController/').then(res => {

          this.$router.addRoutes(generateMenus(res.data))
          // this.allRoute = this.$router.Route
        }).catch(e => {
          this.$message.error('查询菜单异常：' + e)
        })
      }
    },

    computed: {
      ...
        mapGetters([
          'sidebar'
        ]),
      activeMenu() {
        const route = this.$route
        const {meta, path} = route
        // if set path, the sidebar will highlight the path you set
        if (meta.activeMenu) {
          return meta.activeMenu
        }
        return path
      }
      ,
      showLogo() {
        return this.$store.state.settings.sidebarLogo
      }
      ,
      variables() {
        return variables
      }
      ,
      isCollapse() {
        if (!this.sidebar.opened) {
          this.variables.menuBg = 'rgb(0,0,0)'
        } else {
          this.variables.menuBg = 'rgba(48, 65, 86,0)'
        }
        return !this.sidebar.opened
      }
    }
  }
</script>
<style scoped>
  /*.elmenu {*/
  /*  background: url('../../img/pageBg.png');*/
  /*  border: 1px solid #ffffff;*/
  /*  height: 100%;*/
  /*}*/
</style>
