<script>
import menuList from '@/data/json/menuList.json'

export default {
  props: {
    collapse: Boolean,
  },
  data() {
    return {
      asideStyle: {},
      menuList,
    }
  },
  watch: {
    collapse(val) {
      this.suitHeight(val)
    },
  },
  mounted() {
    this.suitHeight(this.collapse)
  },
  methods: {
    suitHeight(val) {
      this.$nextTick(() => {
        let height = document.getElementsByClassName('home')[0].clientHeight
        this.asideStyle = { height: `${height - 60}px` }
        if (val)
          this.asideStyle.width = '60px'
      })
    },
    handleSelected(item) {
      //this.$router.push({name: item.key})
      if (item.key=='nav') {
        this.$router.push({name: 'nav'})
      } else {
        console.log(item.key)
        console.log(item && item.key!='')
        if (item && item.key!=='') {
          let obj = this.menuList[item.key]
          console.log(obj)
          this.$router.push({path: obj.router})
        } else {
          this.$router.push({name: 'empty'})
        }
      }

    },
  },
}
</script>

<template>
  <div class="aside">
    <a-menu
      class="menu"
      theme="dark"
      :style="asideStyle"
      :default-selected-keys="['1']"
      mode="inline"
      @select="handleSelected"
    >
      <a-menu-item v-for="(item,index) in menuList" :key="index" :route="item.key">
        <span class="anticon"><i-icon-park-outline-more-app /></span>
        <span>
            {{ item.name }}
          </span>
      </a-menu-item>
    </a-menu>
  </div>
</template>

<style lang="less" scoped>
.aside {
  //width: 100%;
  height: 100%;
  /deep/ .ant-menu-sub {
    box-shadow: none !important;
  }
  /deep/ .ant-menu-item-selected {
    color: @menu-dark-selected-item-text-color !important;
  }
  .ant-menu-inline-collapsed > .ant-menu-item {
    padding: 0 !important;
    margin-left: 0 !important;
    padding-left: 33% !important;
  }
  /deep/ .ant-menu-inline-collapsed > .ant-menu-item-group > .ant-menu-item-group-list > .ant-menu-item {
    padding: 0 !important;
    margin-left: 0 !important;
    padding-left: 33% !important;
  }

}
</style>
