142 lines
3.4 KiB
Vue
142 lines
3.4 KiB
Vue
<template>
|
|
<div :class="{ 'has-logo': showLogo }" class="sidebar-container">
|
|
<logo v-if="showLogo" :collapse="isCollapse" />
|
|
<el-scrollbar wrap-class="scrollbar-wrapper">
|
|
<el-menu
|
|
:default-active="activeMenu"
|
|
:collapse="isCollapse"
|
|
:background-color="getMenuBackground"
|
|
:text-color="getMenuTextColor"
|
|
:unique-opened="true"
|
|
:active-text-color="theme"
|
|
:collapse-transition="false"
|
|
mode="vertical"
|
|
:class="sideTheme"
|
|
>
|
|
<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-version">
|
|
构建版本: {{ commitId }}<br/>
|
|
<div>构建时间: {{ formatTime(buildTime) }}</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import Logo from './Logo'
|
|
import SidebarItem from './SidebarItem'
|
|
import variables from '@/assets/styles/variables.module.scss'
|
|
import useAppStore from '@/store/modules/app'
|
|
import useSettingsStore from '@/store/modules/settings'
|
|
import usePermissionStore from '@/store/modules/permission'
|
|
|
|
const buildTime = __BUILD_TIME__
|
|
const commitId = __COMMIT_ID__
|
|
const formatTime = (time) => {
|
|
return new Intl.DateTimeFormat('zh-CN', {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
hour12: false,
|
|
timeZone: 'Asia/Shanghai'
|
|
}).format(new Date(time))
|
|
}
|
|
|
|
|
|
const route = useRoute()
|
|
const appStore = useAppStore()
|
|
const settingsStore = useSettingsStore()
|
|
const permissionStore = usePermissionStore()
|
|
|
|
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)
|
|
|
|
// 获取菜单背景色
|
|
const getMenuBackground = computed(() => {
|
|
if (settingsStore.isDark) {
|
|
return 'var(--sidebar-bg)'
|
|
}
|
|
return sideTheme.value === 'theme-dark' ? variables.menuBg : variables.menuLightBg
|
|
})
|
|
|
|
// 获取菜单文字颜色
|
|
const getMenuTextColor = computed(() => {
|
|
if (settingsStore.isDark) {
|
|
return 'var(--sidebar-text)'
|
|
}
|
|
return sideTheme.value === 'theme-dark' ? variables.menuText : variables.menuLightText
|
|
})
|
|
|
|
const activeMenu = computed(() => {
|
|
const { meta, path } = route
|
|
if (meta.activeMenu) {
|
|
return meta.activeMenu
|
|
}
|
|
return path
|
|
})
|
|
</script>
|
|
|
|
<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);
|
|
}
|
|
}
|
|
}
|
|
.sidebar-container {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
}
|
|
|
|
.menu-wrapper {
|
|
flex: 1;
|
|
}
|
|
|
|
.sidebar-version {
|
|
padding: 10px;
|
|
font-size: 12px;
|
|
color: #999;
|
|
text-align: left;
|
|
border-top: 1px solid #eee;
|
|
}
|
|
|
|
</style>
|