<template>
  <div :class="{'has-logo':showLogo}">
    <logo v-if="showLogo" :collapse="isCollapse" />
    <el-menu :default-active="defaultActive" :router="false" unique-opened :collapse="!isAsideActive"
             class="el-menu-aside" :collapse-transition="false">
      <el-menu-item index="/home" @click.native="handleSelectMenu('/dashboard')">
       首页
      </el-menu-item>
      <el-menu-item index="/user/center" @click.native="handleSelectMenu('/user/center')">
        用户中心
      </el-menu-item>

      <el-menu-item index="/duochaxun/view1" @click.native="handleSelectMenu('/duochaxun/view1')">
        测试1
      </el-menu-item>
    </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Logo from './Logo'
import SidebarItem from './SidebarItem'
import variables from '@/assets/styles/variables.scss'

export default {
  components: { SidebarItem, Logo },
  computed: {
    ...mapGetters([
      'sidebarRouters',
      'sidebar'
    ]),
    defaultActive() {
      return this.$route.path
    },
    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() {
      return !this.sidebar.opened
    }
  },
  methods: {
    // 点击 el-submenu 时可以跳转
    handleSelectMenu(path) {
      this.$router.push(path)
    }
  }
}
</script>
