2022-04-21 18:20:39 +08:00
|
|
|
<script lang="ts" setup>
|
2022-04-22 01:16:02 +08:00
|
|
|
import { computed } from "vue"
|
|
|
|
import { useRoute } from "vue-router"
|
2022-08-25 16:26:28 +08:00
|
|
|
import { storeToRefs } from "pinia"
|
2022-04-22 01:16:02 +08:00
|
|
|
import { useAppStore } from "@/store/modules/app"
|
|
|
|
import { usePermissionStore } from "@/store/modules/permission"
|
|
|
|
import { useSettingsStore } from "@/store/modules/settings"
|
|
|
|
import SidebarItem from "./SidebarItem.vue"
|
|
|
|
import SidebarLogo from "./SidebarLogo.vue"
|
2022-05-25 21:53:38 +08:00
|
|
|
import { getCssVariableValue } from "@/utils"
|
|
|
|
|
|
|
|
const v3SidebarMenuBgColor = getCssVariableValue("--v3-sidebar-menu-bg-color")
|
|
|
|
const v3SidebarMenuTextColor = getCssVariableValue("--v3-sidebar-menu-text-color")
|
|
|
|
const v3SidebarMenuActiveTextColor = getCssVariableValue("--v3-sidebar-menu-active-text-color")
|
2022-04-21 18:20:39 +08:00
|
|
|
|
|
|
|
const route = useRoute()
|
2022-08-24 16:52:01 +08:00
|
|
|
const appStore = useAppStore()
|
|
|
|
const permissionStore = usePermissionStore()
|
|
|
|
const settingsStore = useSettingsStore()
|
2022-04-22 12:47:04 +08:00
|
|
|
|
2022-08-25 16:26:28 +08:00
|
|
|
const { showSidebarLogo } = storeToRefs(settingsStore)
|
|
|
|
|
2022-04-21 18:20:39 +08:00
|
|
|
const activeMenu = computed(() => {
|
|
|
|
const { meta, path } = route
|
2022-08-25 16:26:28 +08:00
|
|
|
if (meta?.activeMenu) {
|
|
|
|
return meta.activeMenu
|
2022-04-21 18:20:39 +08:00
|
|
|
}
|
|
|
|
return path
|
|
|
|
})
|
2022-08-25 16:26:28 +08:00
|
|
|
|
2022-04-21 18:20:39 +08:00
|
|
|
const isCollapse = computed(() => {
|
2022-08-25 16:26:28 +08:00
|
|
|
return !appStore.sidebar.opened
|
2022-04-21 18:20:39 +08:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2022-04-22 12:47:04 +08:00
|
|
|
<template>
|
2022-08-25 16:26:28 +08:00
|
|
|
<div :class="{ 'has-logo': showSidebarLogo }">
|
|
|
|
<SidebarLogo v-if="showSidebarLogo" :collapse="isCollapse" />
|
2022-04-22 12:47:04 +08:00
|
|
|
<el-scrollbar wrap-class="scrollbar-wrapper">
|
|
|
|
<el-menu
|
|
|
|
:default-active="activeMenu"
|
2022-08-25 16:26:28 +08:00
|
|
|
:collapse="isCollapse"
|
2022-05-25 21:53:38 +08:00
|
|
|
:background-color="v3SidebarMenuBgColor"
|
|
|
|
:text-color="v3SidebarMenuTextColor"
|
|
|
|
:active-text-color="v3SidebarMenuActiveTextColor"
|
2022-08-25 16:26:28 +08:00
|
|
|
:unique-opened="true"
|
|
|
|
:collapse-transition="false"
|
2022-04-22 12:47:04 +08:00
|
|
|
mode="vertical"
|
|
|
|
>
|
|
|
|
<SidebarItem
|
2022-08-25 16:26:28 +08:00
|
|
|
v-for="route in permissionStore.routes"
|
|
|
|
:key="route.path"
|
|
|
|
:item="route"
|
|
|
|
:base-path="route.path"
|
2022-04-22 12:47:04 +08:00
|
|
|
:is-collapse="isCollapse"
|
|
|
|
/>
|
|
|
|
</el-menu>
|
|
|
|
</el-scrollbar>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-04-21 18:20:39 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
@mixin tip-line {
|
|
|
|
&::before {
|
2022-04-22 01:16:02 +08:00
|
|
|
content: "";
|
2022-04-21 18:20:39 +08:00
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 4px;
|
|
|
|
height: 100%;
|
2022-05-25 21:53:38 +08:00
|
|
|
background-color: var(--v3-sidebar-menu-tip-line-bg-color);
|
2022-04-21 18:20:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.has-logo {
|
|
|
|
.el-scrollbar {
|
2022-05-25 21:53:38 +08:00
|
|
|
height: calc(100% - var(--v3-header-height));
|
2022-04-21 18:20:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 16:26:28 +08:00
|
|
|
.el-scrollbar {
|
|
|
|
height: 100%;
|
|
|
|
::v-deep(.scrollbar-wrapper) {
|
|
|
|
// 限制水平宽度
|
|
|
|
overflow-x: hidden !important;
|
|
|
|
.el-scrollbar__view {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 滚动条
|
|
|
|
::v-deep(.el-scrollbar__bar) {
|
|
|
|
&.is-horizontal {
|
|
|
|
// 隐藏水平滚动条
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 18:20:39 +08:00
|
|
|
.el-menu {
|
|
|
|
border: none;
|
|
|
|
height: 100%;
|
|
|
|
width: 100% !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
::v-deep(.el-menu-item),
|
|
|
|
::v-deep(.el-sub-menu__title),
|
|
|
|
::v-deep(.el-sub-menu .el-menu-item) {
|
2022-05-25 21:53:38 +08:00
|
|
|
height: var(--v3-sidebar-menu-item-height);
|
|
|
|
line-height: var(--v3-sidebar-menu-item-height);
|
2022-04-21 18:20:39 +08:00
|
|
|
&:hover {
|
2022-05-25 21:53:38 +08:00
|
|
|
background-color: var(--v3-sidebar-menu-hover-bg-color);
|
2022-04-21 18:20:39 +08:00
|
|
|
}
|
|
|
|
display: block;
|
|
|
|
* {
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
::v-deep(.el-menu-item) {
|
|
|
|
&.is-active {
|
|
|
|
@include tip-line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-menu--collapse {
|
|
|
|
::v-deep(.el-sub-menu) {
|
|
|
|
&.is-active {
|
|
|
|
.el-sub-menu__title {
|
2022-05-25 21:53:38 +08:00
|
|
|
color: var(--v3-sidebar-menu-active-text-color) !important;
|
2022-04-21 18:20:39 +08:00
|
|
|
@include tip-line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|