<template>
  <div :class="{ 'has-logo': logo }">
    <logo v-if="logo" :collapse="!collapse" />
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="!collapse"
        :background-color="variables.menuBg"
        :text-color="variables.menuText"
        :active-text-color="variables.menuActiveText"
        :collapse-transition="false"
        :default-openeds="defaultOpens"
        :unique-opened="uniqueOpened"
        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";
import { defaultOopeneds, uniqueOpened } from "@/config/settings";

export default {
  components: { SidebarItem, Logo },
  data() {
    return {
      uniqueOpened,
    };
  },
  computed: {
    ...mapGetters({
      routes: "routes/routes",
      logo: "settings/logo",
      collapse: "settings/collapse",
    }),
    activeMenu() {
      const route = this.$route;
      const { meta, path } = route;
      // 如果设置了路径，则侧边栏将突出显示您设置的路径
      if (meta.activeMenu) {
        return meta.activeMenu;
      }
      return path;
    },
    defaultOpens() {
      return defaultOopeneds;
    },
    variables() {
      return variables;
    },
  },
};
</script>
