feat(admin): 实现动态路由菜单并修复rbac菜单树构建问题
- 修复rbac.py中菜单树构建逻辑,将`elif not menu.parentId`改为`else`,避免父菜单不存在时子菜单丢失 - 新增后端`/api/admin/system/routers`接口,作为动态路由菜单的API - 前端新增`getRouters` API并整合到用户信息加载流程 - 添加菜单扁平化工具函数,更新路由注册逻辑以支持嵌套路由 - 新增相关测试用例并更新API和集成文档
This commit is contained in:
1 parent
f087663b5b
commit
2c8c327de7
12 files changed
+108
-5
No files matched your search
@@ -38,7 +38,7 @@ def build_menu_tree(menus: Iterable[AdminMenu], visible_only: bool = True) -> li
|
||||
node = nodes[menu.id]
|
||||
if menu.parentId and menu.parentId in nodes:
|
||||
nodes[menu.parentId]["children"].append(node)
|
||||
elif not menu.parentId:
|
||||
else:
|
||||
roots.append(node)
|
||||
return roots
|
||||
|
||||
|
||||
@@ -111,6 +111,17 @@ def profile(
|
||||
}
|
||||
|
||||
|
||||
@router.get("/routers")
|
||||
def routers(
|
||||
user: AdminUser = Depends(require_admin),
|
||||
db: Session = Depends(get_db),
|
||||
store: AdminSessionStore = Depends(get_admin_session_store),
|
||||
):
|
||||
"""Return the authenticated user's visible menu tree for dynamic routing."""
|
||||
context = build_admin_permission_context(user, db, store)
|
||||
return {"code": 200, "msg": "success", "data": context["menus"]}
|
||||
|
||||
|
||||
@router.get("/users")
|
||||
def list_users(_user: AdminUser = Depends(require_permission("system:user:read")), db: Session = Depends(get_db)):
|
||||
users = list(db.scalars(select(AdminUser).order_by(AdminUser.createdAt.desc())).all())
|
||||
|
||||
Reference in new issue
Block a user