Files
education/frontend/src/layout/components/Sidebar/index.vue
T

104 lines
2.8 KiB
Vue

<template>
<div :class="['sidebar-theme-wrapper', 'theme-dark']" :style="{ backgroundColor: variables.menuBackground }">
<el-scrollbar class="theme-dark" wrap-class="scrollbar-wrapper">
<el-menu
:default-active="activeMenu"
:collapse="isCollapse"
:background-color="variables.menuBackground"
:text-color="variables.menuColor"
:unique-opened="true"
:active-text-color="'#ffffff'"
:collapse-transition="false"
mode="vertical"
>
<sidebar-item
v-for="(route, index) in sidebarRouters"
:key="route.path + index"
:item="route"
:base-path="route.path"
/>
</el-menu>
</el-scrollbar>
<!-- 侧边栏底部折叠按钮 -->
<div class="sidebar-collapse-bar" @click="toggleSideBar" :title="isCollapse ? '展开菜单' : '收起菜单'">
<hamburger :is-active="sidebar.opened" class="collapse-hamburger" />
</div>
</div>
</template>
<script>
import { mapGetters, mapState } from "vuex"
import SidebarItem from "./SidebarItem"
import Hamburger from "@/components/Hamburger"
import variables from "@/assets/styles/variables.scss"
export default {
components: { SidebarItem, Hamburger },
computed: {
...mapState(["settings"]),
...mapGetters(["sidebarRouters", "sidebar"]),
activeMenu() {
const route = this.$route
const { meta, path } = route
// if set path, the sidebar will highlight the path you set
if (meta.activeMenu) {
return meta.activeMenu
}
return path
},
variables() {
return variables
},
isCollapse() {
return !this.sidebar.opened
}
},
methods: {
toggleSideBar() {
this.$store.dispatch('app/toggleSideBar')
}
}
}
</script>
<style scoped lang="scss">
.sidebar-theme-wrapper {
height: 100%;
display: flex;
flex-direction: column;
.el-scrollbar {
flex: 1;
min-height: 0;
}
}
.sidebar-collapse-bar {
flex-shrink: 0;
height: 48px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: rgba(255, 255, 255, 0.72);
border-top: 1px solid rgba(255, 255, 255, 0.10);
background: rgba(3, 49, 40, 0.18);
transition: background-color 160ms ease, color 160ms ease;
&:hover {
color: #ffffff;
background: rgba(255, 255, 255, 0.10);
}
.collapse-hamburger {
line-height: 48px;
font-size: 18px;
}
}
.sidebar-theme-wrapper.theme-light .sidebar-collapse-bar {
color: #909399;
}
</style>