From 3658728acd59be3d6da4f7b3be14184452985fdc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= <2178503051@qq.com>
Date: Sat, 27 Jun 2026 13:12:33 +0800
Subject: [PATCH] =?UTF-8?q?feat(menu):=20=E6=96=B0=E5=A2=9E=E8=8F=9C?=
=?UTF-8?q?=E5=8D=95=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F=E9=85=8D?=
=?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
1. 新增菜单样式表单字段,支持传入JSON格式自定义菜单样式
2. 改造侧边栏组件,实现菜单样式的动态绑定与渲染
3. 添加路由元信息style字段的解析与调试日志
4. 修复侧边栏菜单默认样式冲突问题
---
klp-ui/src/assets/styles/sidebar.scss | 3 ++-
klp-ui/src/layout/components/Sidebar/Item.vue | 25 ++++++++++++++++-
.../layout/components/Sidebar/SidebarItem.vue | 27 +++++++++++++++----
klp-ui/src/layout/components/SubNav.vue | 16 +++++++++--
klp-ui/src/store/modules/permission.js | 12 +++++++++
klp-ui/src/views/system/menu/index.vue | 11 ++++++++
6 files changed, 85 insertions(+), 9 deletions(-)
diff --git a/klp-ui/src/assets/styles/sidebar.scss b/klp-ui/src/assets/styles/sidebar.scss
index b7d564e68..b8d69cbee 100644
--- a/klp-ui/src/assets/styles/sidebar.scss
+++ b/klp-ui/src/assets/styles/sidebar.scss
@@ -91,7 +91,7 @@
.el-menu-item,
.el-submenu__title {
// 明确默认状态样式(关键修复)
- background: transparent !important;
+ background: transparent;
box-shadow: none !important;
position: relative;
@@ -318,4 +318,5 @@
font-size: 12px;
}
+
// 叶子页面无标识
\ No newline at end of file
diff --git a/klp-ui/src/layout/components/Sidebar/Item.vue b/klp-ui/src/layout/components/Sidebar/Item.vue
index acf39df6c..23c3ca452 100644
--- a/klp-ui/src/layout/components/Sidebar/Item.vue
+++ b/klp-ui/src/layout/components/Sidebar/Item.vue
@@ -18,6 +18,11 @@ export default {
},
render(h, context) {
const { icon, title, hasChildren } = context.props
+ // 函数式组件中 :style 绑定不会进 props,需要从 context.data.style 读取
+ const customStyle = context.data.style || {}
+ if (Object.keys(customStyle).length > 0) {
+ console.log('[Item] ✅ 收到 style:', customStyle, '| title:', title)
+ }
const vnodes = []
if (icon) {
@@ -40,7 +45,25 @@ export default {
)
}
- return vnodes
+ return (
+
+ )
}
}
+
+
diff --git a/klp-ui/src/layout/components/Sidebar/SidebarItem.vue b/klp-ui/src/layout/components/Sidebar/SidebarItem.vue
index 6c5d4021e..60d39e8b9 100644
--- a/klp-ui/src/layout/components/Sidebar/SidebarItem.vue
+++ b/klp-ui/src/layout/components/Sidebar/SidebarItem.vue
@@ -4,14 +4,14 @@
-
+
-
+
@@ -20,14 +20,14 @@
-
+
-
+
-
+
-
+
{{ item._title }}
@@ -34,6 +34,7 @@
:to="item._fullPath"
class="sub-nav__item"
:class="{ 'is-active': isActive(item) }"
+ :style="item._style"
>
{{ item._title }}
@@ -160,7 +161,18 @@ export default {
_ownPath: ownPath,
_fullPath: routeFullPath,
_title: title,
- _hasChildren: hasChildren
+ _hasChildren: hasChildren,
+ _style: (() => {
+ const s = c.meta && c.meta.style
+ if (s) {
+ try {
+ return JSON.parse(s)
+ } catch (e) {
+ return {}
+ }
+ }
+ return {}
+ })()
}
if (hasChildren) {
item._children = this.buildItems(c.children, ownPath)
diff --git a/klp-ui/src/store/modules/permission.js b/klp-ui/src/store/modules/permission.js
index 5d11f93ae..512229fbc 100644
--- a/klp-ui/src/store/modules/permission.js
+++ b/klp-ui/src/store/modules/permission.js
@@ -44,6 +44,18 @@ const permission = {
return new Promise(resolve => {
// 向后端请求路由数据
getRouters().then(res => {
+ // 调试:检查后端路由数据
+ const logMetaStyle = (arr, depth = 0) => {
+ arr.forEach(item => {
+ const title = (item.meta && item.meta.title) || item.name || ''
+ const styleVal = item.meta && item.meta.style
+ console.log('[permission] depth=' + depth, title, 'meta.style=', styleVal)
+ if (item.children) logMetaStyle(item.children, depth + 1)
+ })
+ }
+ console.log('[permission] === getRouters 原始数据 ===')
+ logMetaStyle(res.data)
+ console.log('[permission] === getRouters 数据结束 ===')
const sdata = JSON.parse(JSON.stringify(res.data))
const rdata = JSON.parse(JSON.stringify(res.data))
const sidebarRoutes = filterAsyncRouter(sdata)
diff --git a/klp-ui/src/views/system/menu/index.vue b/klp-ui/src/views/system/menu/index.vue
index 6c2fe9395..825f71f4c 100644
--- a/klp-ui/src/views/system/menu/index.vue
+++ b/klp-ui/src/views/system/menu/index.vue
@@ -231,6 +231,17 @@
+
+
+
+
+
+
+
+ 菜单样式
+
+
+