gaoluyang
5 天以前 c7566bba45e6f90594d36ec4b80ac4ff89f577ee
src/layout/components/Sidebar/index.vue
@@ -5,10 +5,10 @@
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color="getMenuBackground"
        :text-color="getMenuTextColor"
        :background-color="menuBackground"
        :text-color="menuTextColor"
        :active-text-color="activeTextColor"
        :unique-opened="true"
        :active-text-color="theme"
        :collapse-transition="false"
        mode="vertical"
        :class="sideTheme"
@@ -27,7 +27,6 @@
<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'
@@ -40,24 +39,13 @@
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
})
// 侧边栏配色统一由 CSS 变量提供(见 assets/styles/theme/tokens.scss 的 :root / html.dark),
// 暗色与浅色都走同一份声明,不再依赖 scss :export 的构建期快照。
const menuBackground = 'var(--sidebar-bg)'
const menuTextColor = 'var(--sidebar-text)'
const activeTextColor = 'var(--el-color-primary)'
const activeMenu = computed(() => {
  const { meta, path } = route
@@ -70,10 +58,10 @@
<style lang="scss" scoped>
.sidebar-container {
  background-color: v-bind(getMenuBackground);
  background-color: v-bind(menuBackground);
  
  .scrollbar-wrapper {
    background-color: v-bind(getMenuBackground);
    background-color: v-bind(menuBackground);
  }
  .el-menu {
@@ -83,21 +71,20 @@
    
    .el-menu-item, .el-sub-menu__title {
      &:hover {
        background-color: var(--menu-hover, rgba(0, 0, 0, 0.06)) !important;
        background-color: var(--menu-hover) !important;
      }
    }
    .el-menu-item {
      color: v-bind(getMenuTextColor);
      color: v-bind(menuTextColor);
      
      &.is-active {
        color: var(--menu-active-text, #409eff);
        background-color: var(--menu-hover, rgba(0, 0, 0, 0.06)) !important;
        color: var(--el-color-primary);
      }
    }
    .el-sub-menu__title {
      color: v-bind(getMenuTextColor);
      color: v-bind(menuTextColor);
    }
  }
}