<template>
<div
class="sidebar-container"
:class="{ 'has-logo': showLogo, collapse: isCollapse }"
:style="{
backgroundColor:
settings.sideTheme === 'theme-dark'
? variables.menuBackground
: variables.menuLightBackground,
}"
>
<!-- Logo 区域 -->
<logo v-if="showLogo" :collapse="isCollapse" />
<!-- 滚动区域(区分主题滚动条样式) -->
<el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
<el-menu
:default-active="activeMenu"
:collapse="isCollapse"
mode="vertical"
:background-color="
settings.sideTheme === 'theme-dark'
? variables.menuBackground
: variables.menuLightBackground
"
:text-color="
settings.sideTheme === 'theme-dark'
? variables.menuColor
: variables.menuLightColor
"
:active-text-color="settings.theme"
:unique-opened="true"
:collapse-transition="false"
>
<sidebar-item
v-for="(route, index) in sidebarRouters"
:key="route.path + index"
:item="route"
:base-path="route.path"
/>
</el-menu>
</el-scrollbar>
</div>
</template>
<script>
import { mapGetters, mapState } from "vuex";
import Logo from "./Logo";
import SidebarItem from "./SidebarItem";
import variables from "@/assets/styles/variables.scss";
export default {
components: { SidebarItem, Logo },
data() {
return {
variables,
};
},
computed: {
...mapState(["settings"]),
...mapGetters(["sidebarRouters", "sidebar"]),
activeMenu() {
const route = this.$route;
if (route.meta?.activeMenu) return route.meta.activeMenu;
return route.path;
},
showLogo() {
return this.$store.state.settings.sidebarLogo;
},
isCollapse() {
return !this.sidebar.opened;
},
},
};
</script>
<style lang="scss" scoped>
$base-menu-item-height: 50px;
$base-menu-margin: 6px 8px;
$base-menu-border-radius: 12px;
.logo-container {
background: v-bind(
"settings.sideTheme === 'theme-dark' ? 'rgba(255,255,255,0.06)' : '#f5f5f5'"
);
border-bottom: v-bind(
"settings.sideTheme === 'theme-dark' ? '1px solid rgba(255,255,255,0.1)' : '1px solid #ddd'"
);
}
.sidebar-container {
transition: width 0.3s, background-color 0.3s;
height: 100%;
overflow: hidden;
box-shadow: 4px 0 16px rgba(0, 0, 0, 0.15);
position: relative;
z-index: 9;
::v-deep .scrollbar-wrapper {
overflow-x: hidden !important;
padding-right: 6px;
// 垂直滚动条样式 - 暗色主题
.el-scrollbar__bar.is-vertical {
right: 2px;
opacity: 0.6;
&-thumb {
background-color: rgba(100, 150, 255, 0.4);
border-radius: 4px;
transition: background-color 0.3s ease;
&:hover {
background-color: #5d8bfb;
}
}
}
// 明色主题下更明显的滚动条
.theme-light & .el-scrollbar__bar.is-vertical {
opacity: 0.8;
&-thumb {
background-color: #c8c9cc;
}
}
}
::v-deep .el-menu {
border: none;
padding-top: 12px;
.el-menu-item,
.el-submenu__title {
height: $base-menu-item-height !important;
line-height: $base-menu-item-height !important;
margin: $base-menu-margin;
color: v-bind(
'settings.sideTheme === "theme-dark" ? variables.menuColor : variables.menuLightColor'
);
font-weight: 500;
border-radius: $base-menu-border-radius;
background: transparent;
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.5, 1);
position: relative;
overflow: hidden;
padding-left: 20px !important;
&:hover {
transform: translateY(-2px) scale(1.01);
box-shadow: 0 6px 18px rgba(42, 74, 128, 0.35);
// 暗色主题:霓虹渐变
&[class*="theme-dark"] & {
background: linear-gradient(90deg, #3a2d6d, #2a4a80) !important;
color: #ffffff !important;
}
// 明色主题:柔和高亮
&[class*="theme-light"] & {
background: #e8f4ff !important;
color: #000 !important;
}
}
&.is-active {
color: #ffffff !important;
&[class*="theme-dark"] & {
background: linear-gradient(90deg, #3a2d6d, #2a4a80) !important;
border: 1px solid #5d8bfb;
box-shadow: 0 0 10px #5d8bfb, 0 0 20px rgba(93, 139, 251, 0.5);
animation: pulse-glow 2.5s infinite alternate ease-in-out;
}
&[class*="theme-light"] & {
background: #eff6ff !important;
border-left: 3px solid #5d8bfb;
font-weight: 600;
}
}
}
// 子菜单嵌套项
.nest-menu {
.el-menu-item {
padding-left: 50px !important;
font-size: 13px;
opacity: 0.9;
&:hover {
background: linear-gradient(90deg, #4a3a7d, #3a5a90) !important;
}
}
}
}
}
// 💫 脉冲发光动画(仅用于暗色主题)
@keyframes pulse-glow {
0% {
box-shadow: 0 0 10px #5d8bfb, 0 0 20px rgba(93, 139, 251, 0.5);
}
100% {
box-shadow: 0 0 16px #79a7ff, 0 0 32px rgba(93, 139, 251, 0.8),
inset 0 0 8px rgba(255, 255, 255, 0.1);
}
}
</style>
换个适合疗养院的主题
最新发布