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"
|
|
|
|
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-04-21 18:20:39 +08:00
|
|
|
const sidebar = computed(() => {
|
2022-08-24 16:52:01 +08:00
|
|
|
return appStore.sidebar
|
2022-04-21 18:20:39 +08:00
|
|
|
})
|
|
|
|
const routes = computed(() => {
|
2022-08-24 16:52:01 +08:00
|
|
|
return permissionStore.routes
|
2022-04-21 18:20:39 +08:00
|
|
|
})
|
|
|
|
const showLogo = computed(() => {
|
2022-08-24 16:52:01 +08:00
|
|
|
return settingsStore.showSidebarLogo
|
2022-04-21 18:20:39 +08:00
|
|
|
})
|
|
|
|
const activeMenu = computed(() => {
|
|
|
|
const { meta, path } = route
|
|
|
|
if (meta !== null || meta !== undefined) {
|
|
|
|
if (meta.activeMenu) {
|
|
|
|
return meta.activeMenu
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return path
|
|
|
|
})
|
|
|
|
const isCollapse = computed(() => {
|
|
|
|
return !sidebar.value.opened
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2022-04-22 12:47:04 +08:00
|
|
|
<template>
|
|
|
|
<div :class="{ 'has-logo': showLogo }">
|
|
|
|
<SidebarLogo v-if="showLogo" :collapse="isCollapse" />
|
|
|
|
<el-scrollbar wrap-class="scrollbar-wrapper">
|
|
|
|
<el-menu
|
|
|
|
:collapse="isCollapse"
|
|
|
|
:unique-opened="true"
|
|
|
|
:default-active="activeMenu"
|
2022-05-25 21:53:38 +08:00
|
|
|
:background-color="v3SidebarMenuBgColor"
|
|
|
|
:text-color="v3SidebarMenuTextColor"
|
|
|
|
:active-text-color="v3SidebarMenuActiveTextColor"
|
2022-04-22 12:47:04 +08:00
|
|
|
mode="vertical"
|
|
|
|
>
|
|
|
|
<SidebarItem
|
|
|
|
v-for="routeItem in routes"
|
|
|
|
:key="routeItem.path"
|
|
|
|
:item="routeItem"
|
|
|
|
:base-path="routeItem.path"
|
|
|
|
:is-collapse="isCollapse"
|
|
|
|
/>
|
|
|
|
</el-menu>
|
|
|
|
</el-scrollbar>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-04-21 18:20:39 +08:00
|
|
|
<style lang="scss">
|
|
|
|
.sidebar-container {
|
2022-07-01 16:25:51 +08:00
|
|
|
// 重置当前页面的 Element-Plus CSS, ,注意,虽然没有加 scoped 标识,但是被该页面的 sidebar-container 类名包裹,所以不会影响其他页面
|
2022-04-21 18:20:39 +08:00
|
|
|
.horizontal-collapse-transition {
|
|
|
|
transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
|
|
|
|
}
|
|
|
|
.scrollbar-wrapper {
|
|
|
|
overflow-x: hidden !important;
|
|
|
|
}
|
|
|
|
.el-scrollbar__view {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
.el-scrollbar__bar {
|
|
|
|
&.is-vertical {
|
|
|
|
right: 0;
|
|
|
|
}
|
|
|
|
&.is-horizontal {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-scrollbar {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.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>
|