<template>
  <div :class="{ 'has-logo': showLogo }">
<!--    <logo v-if="isCollapse" :collapse="isCollapse" />-->
<!--    <logo v-else :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"
      >
        <!-- v-for="route in routes" -->
        <!-- :key="route.path" -->
        <sidebar-item
          v-for="(route, index) in list[mes]"
          :key="route.path"
          class="tabLink"
          :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'
export default {
   name: 'Sidebar',
  components: { SidebarItem, Logo },
  data() {
    return {
      routes: [],
      isCollapse:false
    }
  },
  props: {
    mes:0,
     list: {
          type: Array, // 一维数组
          required: true, // 如果这个属性是必须的
          validator: function(value) {
            // 自定义验证器来检查数组中的每个元素是否也是数组
            return value.every(item => Array.isArray(item));
          }
        }
  },

  mounted(){

  },
  watch: {
     $route(to, from) {
        // 这里可以添加逻辑来处理路由变化时的行为
        // 例如，更新 activeMenu
        this.activeMenu = to.meta.activeMenu || to.path;
      }
    // mes(newVal, oldVal) {
    //   console.log(this.routers)
    //   let list1=[]
    //   this.routers.map(item=>{
    //     this.list[newVal].map(el=>{
    //       if(item.meta){
    //         if(item.meta.title==el){
    //           list1.push(item)
    //         }
    //       }
    //     })
    //   })
    //   this.list[newVal]=list1
    // }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'routers'
    ]),
    // routes() {
    //   // return this.$router.options.routes;
    //   return JSON.parse(localStorage.getItem("permissionList"));
    // },

    activeMenu () {
      const route = this.$route
      const { meta, path } = route
      // if set path, the sidebar will highlight the path you set
      // if(show)

      if (meta.activeMenu) {
        return meta.activeMenu
      }
      return path
    },
    showLogo() {
      return this.$store.state.settings.sidebarLogo
    },
    variables() {
      return variables
    },
    // isCollapse() {
    //   return !this.sidebar.opened
    // }
  },
}
</script>
<style scoped>
  ::v-deep .el-scrollbar__thumb {
             background-color: #DEEBE2;

    }

.el-menu{
  padding:12px 0;
  width:200px;
}
::v-deep .el-submenu__icon-arrow{
      position: absolute;
      top: 50%;
      color:#4C4C4C !important;
      right: 20px !important;
      margin-top: -7px;
}
</style>
