Skip to content

fix(menu): fix the visibility judgment logic for menu items#726

Merged
kanyxmo merged 1 commit into
masterfrom
fix-menu-visibility
Jun 11, 2026
Merged

fix(menu): fix the visibility judgment logic for menu items#726
kanyxmo merged 1 commit into
masterfrom
fix-menu-visibility

Conversation

@kanyxmo

@kanyxmo kanyxmo commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

发布说明

  • 新功能

    • 菜单项现在支持基于路由配置的可见性过滤,隐藏特定菜单项和子菜单。
  • 改进

    • 优化了菜单树的构建逻辑,确保菜单展开和收起行为更加准确。
    • 完善了菜单项的可见性判断机制。

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 11, 2026
@kanyxmo
kanyxmo merged commit ff9a92e into master Jun 11, 2026
3 of 5 checks passed
@kanyxmo
kanyxmo deleted the fix-menu-visibility branch June 11, 2026 07:22
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2acf5c22-c2ab-4921-a3af-b5e8099e288a

📥 Commits

Reviewing files that changed from the base of the PR and between d562142 and 9083330.

📒 Files selected for processing (2)
  • web/src/layouts/components/menu/index.tsx
  • web/src/layouts/components/menu/sub.tsx

📝 Walkthrough

功能概览

菜单组件新增基于路由 meta 的统一可见性过滤规则,在菜单初始化与子菜单展开时排除不可见项(type='B'、hidden=true 未 subForceShow、menu=false),并优化递归逻辑以支持深层级可见后代的发现。

变更详情

菜单可见性过滤与树构建

Layer / File(s) 概述
可见性判断规则定义与初始化过滤
web/src/layouts/components/menu/sub.tsx, web/src/layouts/components/menu/index.tsx
SubMenu 中新增 isVisibleMenuItem 函数用于判断子项可见性(排除 type='B'、hidden=true 且未 subForceShow、menu=false);Menu 中新增 isVisibleMenuItemhasVisibleChildren 辅助函数,在 initItems 初始化时过滤不可见项,并将子菜单展开判断从简单 children 存在性改为"是否存在可见子项"。
菜单树递归与深层可见后代探索
web/src/layouts/components/menu/index.tsx
递归调用参数添加空值兜底(children ?? []),并在叶子分支新增条件递归:当前节点无可见直接子项时,若 children 列表存在则继续递归向下,以纳入更深层级的可见后代(最终仍受可见性过滤约束)。
子菜单展开性判断更新
web/src/layouts/components/menu/sub.tsx
hasChildren 的返回逻辑从遍历统计 meta.menu/meta.hidden 改为直接检查子项中是否存在满足 isVisibleMenuItem 的项,统一与规则定义层的判断方式。

🎯 代码审查工作量评估

🎯 2 (简单) | ⏱️ ~12 分钟

变更主要为两个菜单组件的可见性过滤逻辑,核心规则清晰、实现一致,范围集中于菜单初始化与展开判断,无跨域复杂交互。

相关 PR

  • mineadmin/MineAdmin#443: 同样基于 route.meta.hidden 等条件调整菜单项的激活与可见决策。

  • mineadmin/MineAdmin#595: 直接修改 web/src/layouts/components/menu/sub.tsxhasChildren 逻辑,处理"全部隐藏子菜单导致父菜单不可点击"的场景。

  • mineadmin/MineAdmin#596: 也调整了 web/src/layouts/components/menu/sub.tsxindex.tsx 中的子菜单可见性与展开判断逻辑。

建议标签

bug, size:S

祝贺诗 🐰

菜单隐现各不同,
可见规则做过滤,
深层后代不遗漏,
展开逻辑更清晰,
小兔舞动庆此君! 🎉

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-menu-visibility

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frontend size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant