<!--
 * @Description: 
 * @Author: zenghua.wang
 * @Date: 2024-01-27 20:01:45
 * @LastEditors: zenghua.wang
 * @LastEditTime: 2025-04-11 10:56:12
-->
<template>
  <div class="layout-sider" :class="{ 'has-logo': themeConfig.showLogo }">
    <Logo v-if="themeConfig.showLogo" :is-collapse="isCollapse" />
    <el-scrollbar wrap-class="layout-sider-scrollbar">
      <el-menu
        class="layout-sider-menu"
        background-color="#fff"
        text-color="#333"
        active-text-color=""
        :default-active="activeMenu"
        :unique-opened="SettingStore.themeConfig.uniqueOpened"
        :collapse-transition="false"
        :collapse="isCollapse"
      >
        <SubItem v-for="item in permissionRoutes" :key="item.path" :item="item" />
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script setup name="layout-sider">
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import Logo from '../Logo';
import SubItem from '../Menu/SubItem';
import { useSettingStore } from '@/store/modules/setting';
import { usePermissionStore } from '@/store/modules/permission';

const route = useRoute();
const PermissionStore = usePermissionStore();
const SettingStore = useSettingStore();

// 是否折叠
const isCollapse = computed(() => !SettingStore.isCollapse);

// 设置
const themeConfig = computed(() => SettingStore.themeConfig);

// 获取路由
const permissionRoutes = computed(() => PermissionStore.permissionRoutes);

const activeMenu = computed(() => {
  const { meta, path } = route;
  if (meta.activeMenu) {
    return meta.activeMenu;
  }
  return path;
});
</script>

<style lang="scss" scoped>
.layout-sider {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 98;
  overflow: hidden;
  width: 210px;
  height: 100%;
  background-color: #ffffff;
  box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
  transition: width 0.28s;
  &-scrollbar {
    height: calc(100vh - 60px) !important;
  }
  :deep(.el-scrollbar__wrap) {
    height: calc(100vh - 60px) !important;
  }
  &-menu {
    border-right: 0;
    :deep(.el-menu-item.is-active) {
      background-color: #f5f5f5;
    }
    &:not(.el-menu--collapse) {
      height: 100%;
    }
  }
}
</style>
