From 4950d547503c7c1d5d0ff6487e6768937170ddf7 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期一, 04 八月 2025 17:29:00 +0800 Subject: [PATCH] feat:角色授权 --- FlexJobApi.User.Application/Menus/Queries/GetMenuQueryHandler.cs | 31 ++++++++++++++++++++++++------- 1 files changed, 24 insertions(+), 7 deletions(-) diff --git a/FlexJobApi.User.Application/Menus/Queries/GetMenuQueryHandler.cs b/FlexJobApi.User.Application/Menus/Queries/GetMenuQueryHandler.cs index 2f422db..6763485 100644 --- a/FlexJobApi.User.Application/Menus/Queries/GetMenuQueryHandler.cs +++ b/FlexJobApi.User.Application/Menus/Queries/GetMenuQueryHandler.cs @@ -30,6 +30,11 @@ .ProjectToType<GetMenuQueryResult>() .FirstOrDefaultAsync(cancellationToken); if (model == null) throw Oops.Oh(EnumErrorCodeType.s404, "璇ヨ彍鍗�"); + var roleMenuIds = + request.RoleId.HasValue + ? rep.Change<RoleMenu>().Where(it => it.RoleId == request.RoleId).DistinctSelect(it => it.MenuId) + : []; + model.IsChecked = roleMenuIds.Contains(model.Id); var items = await rep.AsQueryable().AsNoTracking() .Where(it => it.ParentId == model.Id) .Where(it => it.Type == EnumMenuType.Button || it.Type == EnumMenuType.Field) @@ -40,16 +45,28 @@ { Group = it.Key, ButtonLocations = it - .Where(it => it.Type == EnumMenuType.Button) - .GroupBy(it => it.Location ?? "default") - .Select(it => new GetMenuQueryResultButtonLocation - { - Location = it.Key, - Buttons = it.ToList().Adapt<List<GetMenuQueryResultButton>>() + .Where(l => l.Type == EnumMenuType.Button) + .GroupBy(l => l.Location ?? "default") + .Select(l => new GetMenuQueryResultButtonLocation + { + Location = l.Key, + Buttons = l + .Select(b => + { + b.IsChecked = roleMenuIds.Contains(b.Id); + return b; + }) + .ToList() + .Adapt<List<GetMenuQueryResultButton>>() }) .ToList(), Fields = it - .Where(it => it.Type == EnumMenuType.Field) + .Where(f => f.Type == EnumMenuType.Field) + .Select(f => + { + f.IsChecked = roleMenuIds.Contains(f.Id); + return f; + }) .ToList() .Adapt<List<GetMenuQueryResultField>>() }) -- Gitblit v1.9.1