Files
RuoYi-Vue3-Mirror/src/layout/components/Sidebar/index.vue
T

105 lines
2.9 KiB
Vue
Raw Normal View History

2021-11-30 09:55:37 +08:00
<template>
2026-03-24 10:31:29 +08:00
<div :class="['sidebar-theme-wrapper', {'has-logo':showLogo}, sideTheme]" class="sidebar-container">
2021-11-30 09:55:37 +08:00
<logo v-if="showLogo" :collapse="isCollapse" />
2024-12-04 20:32:06 +08:00
<el-scrollbar wrap-class="scrollbar-wrapper">
2021-11-30 09:55:37 +08:00
<el-menu
:default-active="activeMenu"
:collapse="isCollapse"
2024-12-04 20:32:06 +08:00
:background-color="getMenuBackground"
:text-color="getMenuTextColor"
2021-11-30 09:55:37 +08:00
:unique-opened="true"
:active-text-color="theme"
:collapse-transition="false"
mode="vertical"
2024-12-04 20:32:06 +08:00
:class="sideTheme"
2021-11-30 09:55:37 +08:00
>
<sidebar-item
v-for="(route, index) in sidebarRouters"
:key="route.path + index"
:item="route"
:base-path="route.path"
/>
</el-menu>
</el-scrollbar>
</div>
</template>
2026-01-28 12:21:57 +08:00
<script setup lang="ts">
import Logo from './Logo.vue'
import SidebarItem from './SidebarItem.vue'
2021-11-30 09:55:37 +08:00
import variables from '@/assets/styles/variables.module.scss'
2022-05-29 21:40:32 +08:00
import useAppStore from '@/store/modules/app'
import useSettingsStore from '@/store/modules/settings'
import usePermissionStore from '@/store/modules/permission'
2021-11-30 09:55:37 +08:00
2025-04-27 09:58:29 +08:00
const route = useRoute()
2022-05-29 21:40:32 +08:00
const appStore = useAppStore()
const settingsStore = useSettingsStore()
const permissionStore = usePermissionStore()
2021-11-30 09:55:37 +08:00
2025-04-27 09:58:29 +08:00
const sidebarRouters = computed(() => permissionStore.sidebarRouters)
const showLogo = computed(() => settingsStore.sidebarLogo)
const sideTheme = computed(() => settingsStore.sideTheme)
const theme = computed(() => settingsStore.theme)
const isCollapse = computed(() => !appStore.sidebar.opened)
2021-11-30 09:55:37 +08:00
2024-12-04 20:32:06 +08:00
// 获取菜单背景色
const getMenuBackground = computed(() => {
if (settingsStore.isDark) {
2025-04-27 09:58:29 +08:00
return 'var(--sidebar-bg)'
2024-12-04 20:32:06 +08:00
}
2025-04-27 09:58:29 +08:00
return sideTheme.value === 'theme-dark' ? variables.menuBg : variables.menuLightBg
})
2024-12-04 20:32:06 +08:00
// 获取菜单文字颜色
const getMenuTextColor = computed(() => {
if (settingsStore.isDark) {
2025-04-27 09:58:29 +08:00
return 'var(--sidebar-text)'
2024-12-04 20:32:06 +08:00
}
2025-04-27 09:58:29 +08:00
return sideTheme.value === 'theme-dark' ? variables.menuText : variables.menuLightText
})
2024-12-04 20:32:06 +08:00
2021-11-30 09:55:37 +08:00
const activeMenu = computed(() => {
2025-04-27 09:58:29 +08:00
const { meta, path } = route
2021-11-30 09:55:37 +08:00
if (meta.activeMenu) {
2025-04-27 09:58:29 +08:00
return meta.activeMenu
2021-11-30 09:55:37 +08:00
}
2025-04-27 09:58:29 +08:00
return path
})
2021-11-30 09:55:37 +08:00
</script>
2024-12-04 20:32:06 +08:00
<style lang="scss" scoped>
.sidebar-container {
background-color: v-bind(getMenuBackground);
.scrollbar-wrapper {
background-color: v-bind(getMenuBackground);
}
.el-menu {
border: none;
height: 100%;
width: 100% !important;
.el-menu-item, .el-sub-menu__title {
&:hover {
background-color: var(--menu-hover, rgba(0, 0, 0, 0.06)) !important;
}
}
.el-menu-item {
color: v-bind(getMenuTextColor);
&.is-active {
color: var(--menu-active-text, #409eff);
background-color: var(--menu-hover, rgba(0, 0, 0, 0.06)) !important;
}
}
.el-sub-menu__title {
color: v-bind(getMenuTextColor);
}
}
}
</style>