<!--
 * @Author: wj 1454560336@qq.com
 * @Date: 2023-09-18 10:57:47
 * @LastEditors: wj 1454560336@qq.com
 * @LastEditTime: 2023-11-03 09:40:23
 * @FilePath: \admin-manage\src\layout\components\Sidebar\index.vue
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<template>
  <div class="Sidebar-page" :style="{ '--bg': variables.menuActiveBg,'--borderBg':variables.menuActiveText,'--subMenuActiveBg':variables.subMenuActiveBg}" :class="{'has-logo':showLogo}">
    <logo v-if="showLogo" :collapse="isCollapse" />
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="false"
        :background-color="variables.menuBg"
        :text-color="variables.menuText"
        :unique-opened="true"
        :active-text-color="variables.menuActiveText"
        :collapse-transition="false"
        mode="vertical"
      >
        <sidebar-item v-for="route in routes" :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'

export default {
  components: { SidebarItem, Logo },
  computed: {
    ...mapGetters([
      'sidebar','menus'
    ]),
    routes() {
      return this.$router.options.routes
    },
    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
    }
  },
  created () {
  },
}
</script>
<style lang="scss">
.Sidebar-page{

  // 选择第一级菜单  不选择二级
  .el-submenu.is-active  .el-submenu__title:not(.nest-menu .el-submenu__title){
     background: var(--bg) !important;
     position: relative;
    &::before{
      content: '';
      width: 8px;
      height: 100%;
      background:  var(--borderBg);
      position: absolute;
      left: 0;
      top: 0;
    }
  } 
    .el-menu-item.is-active{
      background: var(--subMenuActiveBg) !important;
    }
}
</style>
