<template>
  <div id="admin-menu" style="background-color: rgb(0, 20, 42);">
    <scroll-bar>
      <div class="logo">
        <img src="https://img.alicdn.com/tfs/TB13UQpnYGYBuNjy0FoXXciBFXa-242-134.png" width="40" />
        <span class="site-name">ADMIN LITE</span>
      </div>
      <el-menu mode="vertical" :show-timeout="200" background-color="#00142a" text-color="hsla(0, 0%, 100%, .65)" active-text-color="#409EFF">
        <span v-for="(item, index) in menu" :key="index">
          <!-- <span v-if="`${item.role}` === `${user.role}` || !item.role"> -->
          <!--  v-if="`${item.role}` === `${user.role}`" -->
          <span v-if="!item.children" :to="item.path" :key="item.name">
            <el-menu-item :index="item.path" @click="selectMenu(item.path, item.module)">
              <i v-if="item.icon" :class="item.icon"></i>
              <span v-if="item.name" slot="title">{{ item.name }}</span>
            </el-menu-item>
          </span>

          <el-submenu v-else :index="item.name || item.path" :key="item.name">
            <template slot="title">
              <i v-if="item && item.icon" :class="item.icon"></i>
              <span v-if="item && item.name" slot="title">{{ item.name }}</span>
            </template>
            <template v-for="(child, childIndex) in item.children">
              <div :key="childIndex" v-if="!child.hidden">
                <el-menu-item :index="item.path + child.path" @click="selectMenu(item.path + child.path, item.module)">
                  <span v-if="child && child.name" slot="title">{{ child.name }}</span>
                </el-menu-item>
              </div>
            </template>
          </el-submenu>
        </span>
      </el-menu>
    </scroll-bar>
  </div>
</template>

<script>
import * as menus from '@frame/config/menu-config';
import scrollBar from './scrollBar.vue';
import _ from 'lodash';
export default {
  name: 'admin-menu',
  props: {},
  components: {
    scrollBar,
  },
  data: () => ({
    menu: [],
  }),
  created() {},
  computed: {
    project_modules() {
      return process.env.VUE_APP_MODULE;
    },
  },
  mounted() {
    let arr = _.get(menus, this.project_modules, []);
    this.$set(this, `menu`, arr);
  },
  methods: {
    selectMenu(path, modules) {
      if (this.project_modules === modules) this.$router.push({ path: path });
    },
  },
};
</script>

<style lang="less" scoped>
.logo {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 4rem;
  line-height: 4rem;
  background: #002140;
  color: #fff;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  overflow: hidden;
}
.site-name {
  margin-left: 0.325rem;
}
.sidebar-container {
  box-shadow: 0.125rem 0 0.375rem rgba(0, 21, 41, 0.35);
  transition: width 0.28s;
  width: 12rem !important;
  height: 100%;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1001;
  overflow: hidden;
  a {
    display: inline-block;
    width: 100%;
  }
  .el-menu {
    padding-top: 1rem;
    width: 100% !important;
    border: none;
  }
  .el-submenu .el-menu-item {
    min-width: 16rem !important;
    padding-left: 3rem !important;
    background-color: #000c17 !important;
    &:hover {
      color: #fff !important;
    }
  }
  .el-menu-item,
  .el-submenu .el-menu-item {
    &.is-active {
      background-color: #188fff !important;
      color: #fff !important;
    }
  }
  .el-submenu__title i {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.65);
  }
}
</style>
