123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <template>
- <el-scrollbar class="vab-side-bar" :class="{ 'is-collapse': collapse }">
- <vab-logo v-if="layout === 'comprehensive' || layout === 'vertical'" class="fixed-logo" />
- <el-menu
- background-color="var(--el-menu-background-color)"
- :collapse="collapse"
- :collapse-transition="false"
- :default-active="activeMenu.data"
- :default-openeds="defaultOpeneds"
- menu-trigger="click"
- mode="vertical"
- text-color="var(--el-menu-color-text)"
- :unique-opened="uniqueOpened"
- >
- <vab-menu v-for="(item, index) in handleRoutes" :key="index + item.name" :item="item" />
- </el-menu>
- </el-scrollbar>
- </template>
- <script lang="ts" setup>
- import { defaultOpeneds, uniqueOpened } from '/@/config'
- import { useRoutesStore } from '/@/store/modules/routes'
- import { useSettingsStore } from '/@/store/modules/settings'
- defineOptions({
- name: 'VabSideBar',
- })
- const props = defineProps({
- layout: {
- type: String,
- default: 'vertical',
- },
- })
- const settingsStore = useSettingsStore()
- const { collapse } = storeToRefs(settingsStore)
- const routesStore = useRoutesStore()
- const { getRoutes: routes, getActiveMenu: activeMenu, getPartialRoutes: partialRoutes } = storeToRefs(routesStore)
- const handleRoutes = computed(() =>
- props.layout === 'comprehensive'
- ? partialRoutes.value
- : routes.value.flatMap((route: any) => (route.meta.levelHidden && route.children ? [...route.children] : route))
- )
- </script>
- <style lang="scss" scoped>
- @mixin active {
- &:hover {
- color: var(--el-color-white);
- background-color: var(--el-color-primary);
- }
- &.is-active {
- color: var(--el-color-white);
- background-color: var(--el-color-primary);
- }
- }
- .vab-side-bar {
- position: fixed;
- top: 0;
- bottom: 0;
- left: 0;
- width: var(--el-left-menu-width);
- overflow: hidden;
- background: var(--el-menu-background-color);
- transition: var(--el-transition);
- .fixed-logo {
- position: absolute;
- top: 0;
- left: 0;
- z-index: var(--el-z-index);
- width: 100%;
- height: var(--el-header-height);
- background: var(--el-menu-background-color);
- }
- &.is-collapse {
- z-index: calc(var(--el-z-index) + 1);
- width: var(--el-left-menu-width-min);
- border-right: 0;
- :deep() {
- .el-menu {
- border-right: 0 !important;
- }
- .el-menu--collapse.el-menu {
- > .el-menu-item,
- > .el-sub-menu .el-sub-menu__title {
- justify-content: center;
- height: calc(var(--el-menu-item-height) - 6px);
- padding: 0;
- line-height: calc(var(--el-menu-item-height) - 6px);
- text-align: center;
- [class*='ri'] {
- display: block;
- padding: 0 !important;
- margin: 0 !important;
- }
- .el-tag {
- display: none;
- }
- }
- }
- .el-menu-item,
- .el-sub-menu {
- text-align: left;
- }
- .el-menu--collapse {
- border-right: 0;
- .el-sub-menu__icon-arrow {
- right: 10px;
- margin-top: -3px;
- }
- }
- }
- }
- :deep() {
- .el-menu.el-menu--vertical {
- margin-top: var(--el-header-height);
- }
- .el-scrollbar__wrap {
- overflow-x: hidden;
- }
- .el-menu-item,
- .el-sub-menu__title {
- height: var(--el-menu-item-height);
- margin: 0 10px 5px 10px;
- overflow: hidden;
- line-height: var(--el-menu-item-height);
- text-overflow: ellipsis;
- white-space: nowrap;
- border-radius: var(--el-border-radius-base);
- @include active;
- }
- }
- }
- </style>
- <style lang="scss">
- .el-menu {
- border-right: 0;
- }
- .el-menu--popup-right-start {
- --el-menu-hover-bg-color: var(--el-color-primary) !important;
- --el-menu-active-color: var(--el-color-white) !important;
- .is-active {
- background: var(--el-color-primary) !important;
- }
- }
- </style>
|