diff --git a/backend/IM_API/Configs/MapperConfig.cs b/backend/IM_API/Configs/MapperConfig.cs index 0ec907d..01d9263 100644 --- a/backend/IM_API/Configs/MapperConfig.cs +++ b/backend/IM_API/Configs/MapperConfig.cs @@ -26,7 +26,9 @@ namespace IM_API.Configs .ForMember(dest => dest.IsDeleted,opt => opt.MapFrom(src => 0)) ; //好友信息模型转换 - CreateMap(); + CreateMap() + .ForMember(dest => dest.UserInfo, opt => opt.MapFrom(src => src.FriendNavigation)) + ; //好友请求通过后新增好友关系 CreateMap() .ForMember(dest => dest.UserId , opt => opt.MapFrom(src => src.RequestUser)) diff --git a/backend/IM_API/Dtos/FriendDto.cs b/backend/IM_API/Dtos/FriendDto.cs index 1a12449..55ed3c7 100644 --- a/backend/IM_API/Dtos/FriendDto.cs +++ b/backend/IM_API/Dtos/FriendDto.cs @@ -18,6 +18,7 @@ namespace IM_API.Dtos public string RemarkName { get; init; } = string.Empty; public string? Avatar { get; init; } + public UserInfoDto UserInfo { get; init; } } public record FriendRequestHandleDto diff --git a/backend/IM_API/Services/FriendService.cs b/backend/IM_API/Services/FriendService.cs index e5ef1f1..206f699 100644 --- a/backend/IM_API/Services/FriendService.cs +++ b/backend/IM_API/Services/FriendService.cs @@ -63,7 +63,7 @@ namespace IM_API.Services public async Task> GetFriendListAsync(int userId, int page, int limit, bool desc) { - var query = _context.Friends.Where(x => x.UserId == userId && x.Status == (sbyte)FriendStatus.Added); + var query = _context.Friends.Include(u => u.FriendNavigation).Where(x => x.UserId == userId && x.Status == (sbyte)FriendStatus.Added); if (desc) { query = query.OrderByDescending(x => x.UserId); diff --git a/frontend/web/src/views/contact/ContactList.vue b/frontend/web/src/views/contact/ContactList.vue index 231d4c5..0e7f2df 100644 --- a/frontend/web/src/views/contact/ContactList.vue +++ b/frontend/web/src/views/contact/ContactList.vue @@ -87,6 +87,7 @@ import { ref, computed, onMounted } from 'vue' import { friendService } from '@/services/friend' + const searchQuery = ref('') const activeContactId = ref(null) @@ -123,8 +124,12 @@ const loadContactList = async (page = 1,limit = 100) => { contacts1.value = res.data; } + + onMounted(async () => { await loadContactList(); + const contacts = await friendService.getFriendList(); + console.log(contacts) })