refactor(layout): 侧边栏宽度使用 CSS 变量

- 将侧边栏宽度从 SASS 变量改为 CSS 变量
- 更新相关样式文件,使用新的 CSS 变量
- 在 Sidebar 组件中动态设置侧边栏宽度
- 删除了不再使用的 $sideBarWidth SASS变量
This commit is contained in:
du.meimei
2025-05-07 18:29:15 +08:00
parent 185c8f12f5
commit dc1758288a
6 changed files with 35 additions and 16 deletions

View File

@@ -78,6 +78,7 @@ $--message-info-border: #cecece; // 信息消息框的边框色
--color-primary-label: #70778d; // 主题色的标签颜色 --color-primary-label: #70778d; // 主题色的标签颜色
--color-primary-desc-text-drank: #999; // 主题色的深色描述文本颜色 --color-primary-desc-text-drank: #999; // 主题色的深色描述文本颜色
--ep-color-bg: #fff !important; // 全局背景色 --ep-color-bg: #fff !important; // 全局背景色
--sidebar-width: 270px;
} }
// 描述文本样式 // 描述文本样式

View File

@@ -2,7 +2,8 @@
.main-container { .main-container {
min-height: 100%; min-height: 100%;
transition: margin-left 0.28s; transition: margin-left 0.28s;
margin-left: $sideBarWidth; margin-left: var(--sidebar-width);
//$sideBarWidth
position: relative; position: relative;
} }
@@ -79,7 +80,7 @@
& .nest-menu .el-submenu > .el-submenu__title, & .nest-menu .el-submenu > .el-submenu__title,
& .el-submenu .el-menu-item { & .el-submenu .el-menu-item {
min-width: $sideBarWidth !important; min-width: var(--sidebar-width) !important;
background-color: $subMenuBg !important; background-color: $subMenuBg !important;
&:hover { &:hover {
@@ -142,7 +143,7 @@
} }
.el-menu--collapse .el-menu .el-submenu { .el-menu--collapse .el-menu .el-submenu {
min-width: $sideBarWidth !important; min-width: var(--sidebar-width) !important;
} }
// mobile responsive // mobile responsive
@@ -153,14 +154,14 @@
.sidebar-container { .sidebar-container {
transition: transform 0.28s; transition: transform 0.28s;
width: $sideBarWidth !important; width: var(--sidebar-width) !important;
} }
&.hideSidebar { &.hideSidebar {
.sidebar-container { .sidebar-container {
pointer-events: none; pointer-events: none;
transition-duration: 0.3s; transition-duration: 0.3s;
transform: translate3d(-$sideBarWidth, 0, 0); transform: translate3d(var(--sidebar-width), 0, 0);
} }
} }
} }

View File

@@ -14,11 +14,14 @@ $gray: #b1b1b1 !default;
$black: #000 !default; $black: #000 !default;
// 宽度列表 // 宽度列表
$width-list: 5 8 10 20 30 40 50 60 65 70 80 86 100 110 120 140 150 155 160 180 192 200 220 260 280 299 300 315 325 350 400 440 445 450 550 700 1340; $width-list: 5 8 10 20 30 40 50 60 65 70 80 86 100 110 120 140 150 155 160 180
192 200 220 260 280 299 300 315 325 350 400 440 445 450 550 700 1340;
// 内外边距列表 // 内外边距列表
$distance-list: 0 1 2 5 6 8 9 10 12 15 20 25 30 35 40 45 50 60 80 86 90 100 120 140; $distance-list: 0 1 2 5 6 8 9 10 12 15 20 25 30 35 40 45 50 60 80 86 90 100 120
$distance-class-list: m, mv, mh, mt, ml, mr, mb, p, pv, ph, pt, pl, pr, pb, top, left, right, bottom; 140;
$distance-class-list: m, mv, mh, mt, ml, mr, mb, p, pv, ph, pt, pl, pr, pb, top,
left, right, bottom;
//圆角弧度 //圆角弧度
$radius: 1 2 3 4 5 6 7 8 9 10 12 13 14 15 18 20 50 100; $radius: 1 2 3 4 5 6 7 8 9 10 12 13 14 15 18 20 50 100;
@@ -37,8 +40,6 @@ $menuHover: #263445;
$subMenuBg: #1f2d3d; $subMenuBg: #1f2d3d;
$subMenuHover: #001528; $subMenuHover: #001528;
$sideBarWidth: 270px;
// the :export directive is the magic sauce for webpack // the :export directive is the magic sauce for webpack
// https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass // https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass
:export { :export {
@@ -49,5 +50,4 @@ $sideBarWidth: 270px;
menuHover: $menuHover; menuHover: $menuHover;
subMenuBg: $subMenuBg; subMenuBg: $subMenuBg;
subMenuHover: $subMenuHover; subMenuHover: $subMenuHover;
sideBarWidth: $sideBarWidth;
} }

View File

@@ -36,7 +36,7 @@
</div> </div>
</div> </div>
<!-- Right side - Submenu --> <!-- Right side - Submenu -->
<div class="submenu-container" v-if="currentSubmenu.length"> <div class="submenu-container" v-if="currentSubmenu.length > 1">
<!-- <div class="submenu-header">--> <!-- <div class="submenu-header">-->
<!-- <span>{{ currentParentTitle }}</span>--> <!-- <span>{{ currentParentTitle }}</span>-->
<!-- </div>--> <!-- </div>-->
@@ -156,9 +156,20 @@ export default {
this.activeParent = route.url this.activeParent = route.url
// this.$store.dispatch('app/toggleSideBar') // this.$store.dispatch('app/toggleSideBar')
// If this parent has children, don't navigate // If this parent has children, don't navigate
if (route.children && route.children.length > 1) {
document.documentElement.style.setProperty(
'--sidebar-width',
270 + 'px'
)
} else {
document.documentElement.style.setProperty(
'--sidebar-width',
110 + 'px'
)
}
if (route.children && route.children.length > 0) { if (route.children && route.children.length > 0) {
// Optionally navigate to the first child // Optionally navigate to the first child
// this.navigateTo(route.children[0].url) this.navigateTo(route.children[0].url)
} else { } else {
// If no children, navigate to the parent route // If no children, navigate to the parent route
this.navigateTo(route.url) this.navigateTo(route.url)

View File

@@ -1,6 +1,10 @@
<template> <template>
<div :class="classObj" class="app-wrapper"> <div :class="classObj" class="app-wrapper">
<div v-if="device === 'mobile' && sidebar.opened" class="drawer-bg" @click="handleClickOutside" /> <div
v-if="device === 'mobile' && sidebar.opened"
class="drawer-bg"
@click="handleClickOutside"
/>
<sidebar class="sidebar-container" /> <sidebar class="sidebar-container" />
<div class="main-container"> <div class="main-container">
<div :class="{ 'fixed-header': fixedHeader }"> <div :class="{ 'fixed-header': fixedHeader }">
@@ -85,7 +89,8 @@ export default {
top: 0; top: 0;
right: 0; right: 0;
z-index: 9; z-index: 9;
width: calc(100% - #{$sideBarWidth}); //width: calc(100% - #{$sideBarWidth});
width: calc(100% - var(--sidebar-width));
transition: width 0.28s; transition: width 0.28s;
} }

View File

@@ -89,7 +89,8 @@ export default {
top: 0; top: 0;
right: 0; right: 0;
z-index: 9; z-index: 9;
width: calc(100% - #{$sideBarWidth}); //width: calc(100% - #{$sideBarWidth});
width: calc(100% - var(--sidebar-width));
transition: width 0.28s; transition: width 0.28s;
} }