结论
问题根因不是路由配置,而是SVG 本体写法不一致:attribute.svg写死了fill="#4D4D4D",无法跟随菜单激活态颜色;product.svg未写死填充色,可继承currentColor。
排查过程
- 确认渲染链路一致:两者都通过
meta.icon+ 同一菜单组件渲染。 - 对比 SVG 内容:
product.svg不锁色,attribute.svg锁死 fill。 - 核对主题机制:全局菜单颜色基于
currentColor,但被硬编码 fill 抵消。
如何验证
将attribute.svg的硬编码fill去掉或改为currentColor后,菜单激活态下两图标应呈现一致高亮色。
注意事项
只改 CSS、不改 SVG 的硬编码 fill,通常无效;图标仍会保持灰色,导致“文字高亮、图标不亮”的割裂感。
建议
建议统一项目 SVG 规范:图标默认不写死颜色,统一依赖currentColor与主题变量控制。
1. 现象描述
在左侧菜单中:
- 「产品列表」图标颜色能随选中态变化;
- 「属性管理」图标偏灰,不随选中态同步。
这会让用户感知到“同级菜单视觉不统一”。
2. 证据链(代码定位)
2.1 路由层:两者配置方式一致(排除路由原因)
src/router/index.ts:161meta: { title: "产品列表", icon: "product", keepAlive: true }src/router/index.ts:167meta: { title: "属性管理", icon: "attribute", keepAlive: true }
2.2 菜单渲染层:两者走同一 icon 渲染路径
src/layouts/components/Menu/components/MenuItemContent.vue:7v-else :class="\i-svg:${icon}`"`
说明:组件渲染逻辑并未对“产品列表/属性管理”做差异化处理。
2.3 SVG 资源层:颜色策略不一致(根因)
src/assets/icons/product.svg:1path未写死fill/stroke(可继承外部颜色)src/assets/icons/attribute.svg:1
多个path存在fill="#4D4D4D"(颜色被锁定)
2.4 样式与构建机制:本来支持 currentColor,但被硬编码覆盖
src/layouts/components/LayoutSidebarItem.vue:179src/layouts/components/LayoutSidebarItem.vue:184
对i-svg图标设置color: currentcolor !important;src/layouts/components/Menu/components/MenuItemContent.vue:38.menu-icon { color: currentcolor; }src/styles/common.scss:32到src/styles/common.scss:35.el-menu-item.is-active { color: var(--menu-active-text) !important; ... }uno.config.ts:68到uno.config.ts:71
仅在 SVG没有 fill时才注入fill="currentColor";已有 fill 则不覆盖。
3. 根因总结
图标颜色不一致,本质是SVG 是否“锁色”的差异。
product.svg:未锁色 → 可继承菜单激活色;attribute.svg:锁死#4D4D4D→ 无法随状态变色。
4. 修复建议(最小改动)
方案A(推荐)
将attribute.svg中所有硬编码fill="#4D4D4D"改为:
fill="currentColor",或- 直接移除 fill(让构建/样式注入)。
方案B(不推荐)
通过更强 CSS 覆盖硬编码 fill。
缺点:维护成本高、对多 path 和特殊图标兼容性差。