From 9461ab0aa57f641459c6445bddfd6ce62446445b Mon Sep 17 00:00:00 2001 From: zyxucp <286513187@qq.com> Date: Sun, 22 Jun 2025 22:37:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Setting/ChatHistory/ChatHistory.razor | 376 ++++++++++++++---- 1 file changed, 301 insertions(+), 75 deletions(-) diff --git a/src/AntSK/Pages/Setting/ChatHistory/ChatHistory.razor b/src/AntSK/Pages/Setting/ChatHistory/ChatHistory.razor index 510f727..feaf140 100644 --- a/src/AntSK/Pages/Setting/ChatHistory/ChatHistory.razor +++ b/src/AntSK/Pages/Setting/ChatHistory/ChatHistory.razor @@ -1,4 +1,4 @@ -@namespace AntSK.Pages.Setting.AIModel +@namespace AntSK.Pages.Setting.ChatHistory @page "/setting/chathistory" @using AntSK.Services.Auth @inherits AuthComponentBase @@ -9,53 +9,260 @@ @using AntSK.Domain.Common.Map @attribute [Authorize(Roles = "AntSKAdmin")] - - - - - 聊天记录 - - - - - - - - - - - - - - - @((MarkupString)(context.Context)) - - - - - -
+
+ + + + + + + + + + ID + + + + + + 用户 + + + + + + 应用 + + + + + + 类型 + + + + + + 消息内容 + + + + + + 时间 + + + +
+ +
+
+ + @using System.Text.Json; @code { [Inject] IChats_Repositories _chats_Repositories { get; set; } - ChatsDto[] chatDtoList; - + ChatsDto[] chatDtoList = Array.Empty(); ITable table; + bool _loading = false; int _pageIndex = 1; int _pageSize = 10; int _total = 0; - string searchString; + string searchString = string.Empty; protected override async Task OnInitializedAsync() { @@ -64,58 +271,77 @@ public async Task OnChange(QueryModel queryModel) { + _loading = true; + StateHasChanged(); await InitData(); + _loading = false; + StateHasChanged(); } private async Task InitData() { - if (string.IsNullOrEmpty(searchString)) + try { - _total = _chats_Repositories.Count(p => true); - var chatList = _chats_Repositories.GetDB().Queryable((c, a) => new object[] { - SqlSugar.JoinType.Left,c.AppId==a.Id - }).Select((c, a) => new ChatsDto - { - Id = c.Id, - UserName = c.UserName, - AppId = c.AppId, - IsSend = c.IsSend, - SendReveice = c.IsSend ? "发送" : "接收", - Context = c.Context, - CreateTime = c.CreateTime, - AppName = a.Name - }).ToPageList(_pageIndex, _pageSize); - chatDtoList = chatList.ToArray(); - } - else - { - _total = _chats_Repositories.Count(p => p.UserName.Contains(searchString) || p.Context.Contains(searchString)); - var chatList = _chats_Repositories.GetDB().Queryable((c, a) => new object[] { - SqlSugar.JoinType.Left,c.AppId==a.Id - }).Select((c, a) => new ChatsDto + if (string.IsNullOrEmpty(searchString)) { - Id = c.Id, - UserName = c.UserName, - AppId = c.AppId, - IsSend = c.IsSend, - SendReveice = c.IsSend ? "发送" : "接收", - Context = c.Context, - CreateTime = c.CreateTime, - AppName = a.Name - }).Where(c => c.UserName.Contains(searchString) || c.Context.Contains(searchString)).ToPageList(_pageIndex, _pageSize); - chatDtoList = chatList.ToArray(); + _total = _chats_Repositories.Count(p => true); + var chatList = _chats_Repositories.GetDB().Queryable((c, a) => new object[] { + SqlSugar.JoinType.Left, c.AppId == a.Id + }).Select((c, a) => new ChatsDto + { + Id = c.Id, + UserName = c.UserName, + AppId = c.AppId, + IsSend = c.IsSend, + SendReveice = c.IsSend ? "发送" : "接收", + Context = c.Context, + CreateTime = c.CreateTime, + AppName = a.Name ?? "未知应用" + }).OrderByDescending(c => c.CreateTime).ToPageList(_pageIndex, _pageSize); + + chatDtoList = chatList.ToArray(); + } + else + { + _total = _chats_Repositories.Count(p => p.UserName.Contains(searchString) || p.Context.Contains(searchString)); + var chatList = _chats_Repositories.GetDB().Queryable((c, a) => new object[] { + SqlSugar.JoinType.Left, c.AppId == a.Id + }).Select((c, a) => new ChatsDto + { + Id = c.Id, + UserName = c.UserName, + AppId = c.AppId, + IsSend = c.IsSend, + SendReveice = c.IsSend ? "发送" : "接收", + Context = c.Context, + CreateTime = c.CreateTime, + AppName = a.Name ?? "未知应用" + }).Where(c => c.UserName.Contains(searchString) || c.Context.Contains(searchString)) + .OrderByDescending(c => c.CreateTime).ToPageList(_pageIndex, _pageSize); + + chatDtoList = chatList.ToArray(); + } + } + catch + { + // 处理异常,可以添加日志记录 + chatDtoList = Array.Empty(); } } private async Task Search(string searchKey) { + _pageIndex = 1; // 重置到第一页 + _loading = true; + StateHasChanged(); await InitData(); + _loading = false; + StateHasChanged(); } public class ChatsDto : Chats { - public string AppName { get; set; } - public string SendReveice { get; set; } + public string AppName { get; set; } = string.Empty; + public string SendReveice { get; set; } = string.Empty; } - -} +} \ No newline at end of file