<template>
  <div class="max-box sidebar-container" :class="{'has-logo':showLogo}">
    <el-scrollbar class="router-button-box" :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :unique-opened="true"
        :active-text-color="settings.theme"
        :collapse-transition="false"
        mode="vertical"
      >
        <sidebar-item
          v-for="(route, index) in sidebarRouters"
          :key="route.path  + index"
          :item="route"
          :base-path="route.path"
        />
      </el-menu>
    </el-scrollbar>
    <p style="height:30px;"></p>
  </div>
</template>

<script>
  import { mapGetters, mapState } from "vuex";
  import SidebarItem from "./SidebarItem";

  export default {
    components: {
      SidebarItem
    },
    computed: {
      ...mapState(["settings"]),
      ...mapGetters(["sidebarRouters", "sidebar","avatar","name"]),
      activeMenu() {
        const route = this.$route;
        const { meta, path } = route;
        if (meta.activeMenu) {
          return meta.activeMenu;
        }
        this.$parent.setTagsType(path);
        return path;
      },
      showLogo() {
        return this.$store.state.settings.sidebarLogo;
      },
      isCollapse() {
        // return !this.sidebar.opened;
      },
      setting: {
        get() {
          return this.$store.state.settings.showSettings
        },
        set(val) {
          this.$store.dispatch('settings/changeSetting', {
            key: 'showSettings',
            value: val
          })
        }
      },
    },
    methods: {
      //退出登录
      async logout() {
        this.$confirm('确定注销并退出系统吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('LogOut').then(() => {
            let list = [];
            list.push(this.$store.state.tagsView.visitedViews[0]);
            this.$store.state.tagsView.visitedViews = [];
            this.$store.state.tagsView.visitedViews.push(list[0]);
            if(process.env.VUE_APP_LOGIN_TYPE === 'certification'){
              window.location.href = process.env.VUE_APP_OUT_URL;
            }else{
              this.$router.push({ path:"/login" }).catch(()=>{});
            }
          })
        }).catch(() => {});
      }
    }

  };
</script>
<style lang="scss" scoped>
  .max-box{
    display: flex;
    flex-direction: column;
    margin:5px 10px 0 0;
    border-bottom-right-radius: 10px;
    border-top-right-radius: 10px;

    .router-button-box{
      flex:1;
    }
    .user-box {
      width:230px;
      height:40px;
      margin:28px 0;
      margin-right: 30px;
      .avatar-wrapper {
        display: flex;
        position: relative;
        img{
          height:40px;
          width:40px;
          border-radius:50%;
        }
        p{
          flex:1;
          line-height:40px;
          margin:0 15px;
          font-size:14px;
        }
        i{
          -webkit-transform: rotateZ(-90deg);
          -ms-transform: rotate(-90deg);
          transform: rotateZ(-90deg);
        }
      }
    }
  }
  .el-dropdown-menu--medium{
    /*backAnimation: red!important;*/
    /*top:810px!important;*/
  }
</style>
