diff --git a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs
index 2026c4a..fb1ed13 100644
--- a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs
+++ b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs
@@ -54,18 +54,30 @@ namespace ZR.Admin.WebApi.Controllers.System
return SUCCESS(sysMenuService.GetMenuByMenuId(menuId), "yyyy-MM-dd HH:mm:ss");
}
- ///
- /// 获取菜单下拉树列表(分配角色所需菜单)
- ///
- ///
- [HttpGet("treeSelect")]
- public IActionResult TreeSelect()
- {
- long userId = HttpContext.GetUId();
- var list = sysMenuService.SelectMenuList(new MenuQueryDto(), userId).FindAll(f => f.visible == "0");
- var treeMenus = sysMenuService.BuildMenuTreeSelect(list);
+ /////
+ ///// 获取菜单下拉树列表(分配角色所需菜单)
+ /////
+ /////
+ //[HttpGet("treeSelect")]
+ //public IActionResult TreeSelect()
+ //{
+ // long userId = HttpContext.GetUId();
+ // var list = sysMenuService.SelectMenuList(new MenuQueryDto(), userId).FindAll(f => f.visible == "0");
+ // var treeMenus = sysMenuService.BuildMenuTreeSelect(list);
- return SUCCESS(treeMenus);
+ // return SUCCESS(treeMenus);
+ //}
+
+ ///
+ /// 根据菜单编号获取菜单列表,菜单管理首次进入
+ ///
+ ///
+ ///
+ [HttpGet("list/{menuId}")]
+ [ActionPermissionFilter(Permission = "system:menu:query")]
+ public IActionResult GetMenuList(int menuId = 0)
+ {
+ return SUCCESS(sysMenuService.GetMenusByMenuId(menuId), "yyyy-MM-dd HH:mm:ss");
}
///
diff --git a/ZR.Admin.WebApi/Hubs/OnlineUsers.cs b/ZR.Admin.WebApi/Hubs/OnlineUsers.cs
index 0e1657d..a6292e0 100644
--- a/ZR.Admin.WebApi/Hubs/OnlineUsers.cs
+++ b/ZR.Admin.WebApi/Hubs/OnlineUsers.cs
@@ -18,7 +18,7 @@ namespace ZR.Model
public DateTime LoginTime { get; set; }
public string UserIP { get; set; }
- public OnlineUsers(string clientid, string name, long? userid, string? userip)
+ public OnlineUsers(string clientid, string name, long? userid, string userip)
{
ConnnectionId = clientid;
Name = name;
diff --git a/ZR.Model/System/Dto/MenuDto.cs b/ZR.Model/System/Dto/MenuDto.cs
index 6791259..1b7752f 100644
--- a/ZR.Model/System/Dto/MenuDto.cs
+++ b/ZR.Model/System/Dto/MenuDto.cs
@@ -80,6 +80,7 @@ namespace ZR.Model.System.Dto
public string Visible { get; set; }
public string Status { get; set; }
public string MenuTypeIds { get; set; } = string.Empty;
+ public int? ParentId { get; set; }
public string[] MenuTypeIdArr
{
get
diff --git a/ZR.Model/System/SysMenu.cs b/ZR.Model/System/SysMenu.cs
index 1a61890..61d0c4f 100644
--- a/ZR.Model/System/SysMenu.cs
+++ b/ZR.Model/System/SysMenu.cs
@@ -21,12 +21,6 @@ namespace ZR.Model.System
///
public string MenuName { get; set; }
- ///
- /// 父菜单名称
- ///
- [SqlSugar.SugarColumn(IsIgnore = true)]
- public string parentName { get; set; }
-
///
/// 父菜单ID
///
@@ -90,5 +84,21 @@ namespace ZR.Model.System
///
[SugarColumn(IsIgnore = true)]
public List children { get; set; } = new List();
+ ///
+ /// 子菜单个数
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public int SubNum { get; set; }
+ ///
+ /// 是否包含子节点,前端用
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public bool HasChildren
+ {
+ get
+ {
+ return SubNum > 0 || children.Count > 0;
+ }
+ }
}
}
diff --git a/ZR.Repository/System/SysMenuRepository.cs b/ZR.Repository/System/SysMenuRepository.cs
index 1da6ef4..4ab4478 100644
--- a/ZR.Repository/System/SysMenuRepository.cs
+++ b/ZR.Repository/System/SysMenuRepository.cs
@@ -24,7 +24,7 @@ namespace ZR.Repository.System
.WhereIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName))
.WhereIF(!string.IsNullOrEmpty(menu.Visible), it => it.visible == menu.Visible)
.WhereIF(!string.IsNullOrEmpty(menu.Status), it => it.status == menu.Status)
-
+ .WhereIF(!string.IsNullOrEmpty(menu.MenuTypeIds), it => menu.MenuTypeIdArr.Contains(it.menuType))
.OrderBy(it => new { it.parentId, it.orderNum })
.ToTree(it => it.children, it => it.parentId, 0);
}
@@ -32,19 +32,20 @@ namespace ZR.Repository.System
///
/// 根据用户查询系统菜单列表(菜单管理)
///
- ///
+ ///
/// 用户角色集合
///
- public List SelectTreeMenuListByUserId(MenuQueryDto sysMenu, List roles)
+ public List SelectTreeMenuListByRoles(MenuQueryDto menu, List roles)
{
var roleMenus = Context.Queryable()
.Where(r => roles.Contains(r.Role_id));
return Context.Queryable()
.InnerJoin(roleMenus, (c, j) => c.MenuId == j.Menu_id)
- .WhereIF(!string.IsNullOrEmpty(sysMenu.MenuName), (c, j) => c.MenuName.Contains(sysMenu.MenuName))
- .WhereIF(!string.IsNullOrEmpty(sysMenu.Visible), (c, j) => c.visible == sysMenu.Visible)
- .WhereIF(!string.IsNullOrEmpty(sysMenu.Status), (c, j) => c.status == sysMenu.Status)
+ .WhereIF(!string.IsNullOrEmpty(menu.MenuName), (c, j) => c.MenuName.Contains(menu.MenuName))
+ .WhereIF(!string.IsNullOrEmpty(menu.Visible), (c, j) => c.visible == menu.Visible)
+ .WhereIF(!string.IsNullOrEmpty(menu.Status), (c, j) => c.status == menu.Status)
+ .WhereIF(!string.IsNullOrEmpty(menu.MenuTypeIds), c => menu.MenuTypeIdArr.Contains(c.menuType))
.OrderBy((c, j) => new { c.parentId, c.orderNum })
.Select(c => c)
.ToTree(it => it.children, it => it.parentId, 0);
@@ -60,6 +61,7 @@ namespace ZR.Repository.System
.WhereIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName))
.WhereIF(!string.IsNullOrEmpty(menu.Visible), it => it.visible == menu.Visible)
.WhereIF(!string.IsNullOrEmpty(menu.Status), it => it.status == menu.Status)
+ .WhereIF(menu.ParentId != null, it => it.parentId == menu.ParentId)
.OrderBy(it => new { it.parentId, it.orderNum })
.ToList();
}
@@ -87,35 +89,22 @@ namespace ZR.Repository.System
#region 左侧菜单树
- ///
- /// 管理员获取左侧菜单树
- ///
- ///
- public List SelectMenuTreeAll()
- {
- var menuTypes = new string[] { "M", "C" };
-
- return Context.Queryable()
- .Where(f => f.status == "0" && menuTypes.Contains(f.menuType))
- .OrderBy(it => new { it.parentId, it.orderNum }).ToList();
- }
-
- ///
- /// 根据用户角色获取左侧菜单树
- ///
- ///
- ///
- public List SelectMenuTreeByRoleIds(List roleIds)
- {
- var menuTypes = new string[] { "M", "C" };
- return Context.Queryable()
- .Where((menu) =>
- menuTypes.Contains(menu.menuType)
- && menu.status == "0"
- && SqlFunc.Subqueryable().Where(s => roleIds.Contains(s.Role_id) && s.Menu_id == menu.MenuId).Any())
- .OrderBy((menu) => new { menu.parentId, menu.orderNum })
- .Select((menu) => menu).ToList();
- }
+ /////
+ ///// 根据用户角色获取左侧菜单树
+ /////
+ /////
+ /////
+ //public List SelectMenuTreeByRoleIds(List roleIds)
+ //{
+ // var menuTypes = new string[] { "M", "C" };
+ // return Context.Queryable()
+ // .Where((menu) =>
+ // menuTypes.Contains(menu.menuType)
+ // && menu.status == "0"
+ // && SqlFunc.Subqueryable().Where(s => roleIds.Contains(s.Role_id) && s.Menu_id == menu.MenuId).Any())
+ // .OrderBy((menu) => new { menu.parentId, menu.orderNum })
+ // .Select((menu) => menu).ToList();
+ //}
#endregion
diff --git a/ZR.Service/System/IService/ISysMenuService.cs b/ZR.Service/System/IService/ISysMenuService.cs
index f702066..c0294ea 100644
--- a/ZR.Service/System/IService/ISysMenuService.cs
+++ b/ZR.Service/System/IService/ISysMenuService.cs
@@ -14,6 +14,7 @@ namespace ZR.Service.System.IService
List SelectTreeMenuList(MenuQueryDto menu, long userId);
SysMenu GetMenuByMenuId(int menuId);
+ List GetMenusByMenuId(int menuId);
int AddMenu(SysMenu menu);
int EditMenu(SysMenu menu);
diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs
index 2414cb1..e823ba4 100644
--- a/ZR.Service/System/SysMenuService.cs
+++ b/ZR.Service/System/SysMenuService.cs
@@ -42,7 +42,7 @@ namespace ZR.Service
else
{
var userRoles = SysRoleService.SelectUserRoles(userId);
- menuList = MenuRepository.SelectTreeMenuListByUserId(menu, userRoles);
+ menuList = MenuRepository.SelectTreeMenuListByRoles(menu, userRoles);
}
return menuList;
}
@@ -76,6 +76,21 @@ namespace ZR.Service
return MenuRepository.SelectMenuById(menuId);
}
+ ///
+ /// 根据菜单id获取菜单列表
+ ///
+ ///
+ ///
+ public List GetMenusByMenuId(int menuId)
+ {
+ var list = MenuRepository.GetList(f => f.parentId == menuId).OrderBy(f => f.orderNum).ToList();
+ Context.ThenMapper(list, item =>
+ {
+ item.SubNum = Context.Queryable().SetContext(x => x.parentId, () => item.MenuId, item).Count();
+ });
+ return list;
+ }
+
///
/// 添加菜单
///
@@ -155,17 +170,19 @@ namespace ZR.Service
///
public List SelectMenuTreeByUserId(long userId)
{
- List menus;
+ MenuQueryDto dto = new() { Status = "0", MenuTypeIds = "M,C" };
+ //List menus;
if (SysRoleService.IsAdmin(userId))
{
- menus = MenuRepository.SelectMenuTreeAll();
+ return MenuRepository.SelectTreeMenuList(dto);
}
else
{
List roleIds = SysRoleService.SelectUserRoles(userId);
- menus = MenuRepository.SelectMenuTreeByRoleIds(roleIds);
+ //menus = MenuRepository.SelectMenuTreeByRoleIds(roleIds);
+ return MenuRepository.SelectTreeMenuListByRoles(dto, roleIds);
}
- return GetChildPerms(menus, 0);
+ //return GetChildPerms(menus, 0);
}
///
@@ -206,25 +223,25 @@ namespace ZR.Service
#region 方法
- ///
- /// 根据父节点的ID获取所有子节点
- ///
- /// 分类表
- /// 传入的父节点ID
- ///
- public List GetChildPerms(List list, int parentId)
- {
- List returnList = new List();
- var data = list.FindAll(f => f.parentId == parentId);
+ /////
+ ///// 根据父节点的ID获取所有子节点
+ /////
+ ///// 分类表
+ ///// 传入的父节点ID
+ /////
+ //public List GetChildPerms(List list, int parentId)
+ //{
+ // List returnList = new List();
+ // var data = list.FindAll(f => f.parentId == parentId);
- foreach (var item in data)
- {
- RecursionFn(list, item);
+ // foreach (var item in data)
+ // {
+ // RecursionFn(list, item);
- returnList.Add(item);
- }
- return returnList;
- }
+ // returnList.Add(item);
+ // }
+ // return returnList;
+ //}
///
/// 递归列表