| | |
| | | .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) |
| | |
| | | { |
| | | 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>>() |
| | | }) |