diff --git a/src/AntSK.Domain/AntSK.Domain.csproj b/src/AntSK.Domain/AntSK.Domain.csproj index b55a519..203d27e 100644 --- a/src/AntSK.Domain/AntSK.Domain.csproj +++ b/src/AntSK.Domain/AntSK.Domain.csproj @@ -11,6 +11,7 @@ + diff --git a/src/AntSK/Pages/ChatPage/Components/ChatView.razor.cs b/src/AntSK/Pages/ChatPage/Components/ChatView.razor.cs index 0db3350..be3acad 100644 --- a/src/AntSK/Pages/ChatPage/Components/ChatView.razor.cs +++ b/src/AntSK/Pages/ChatPage/Components/ChatView.razor.cs @@ -4,10 +4,12 @@ using AntSK.Domain.Domain.Model; using AntSK.Domain.Domain.Model.Dto; using AntSK.Domain.Repositories; using AntSK.Domain.Utils; +using Blazored.LocalStorage; using Markdig; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using Microsoft.SemanticKernel.ChatCompletion; +using Newtonsoft.Json; namespace AntSK.Pages.ChatPage.Components { @@ -29,6 +31,7 @@ namespace AntSK.Pages.ChatPage.Components [Inject] IConfirmService _confirmService { get; set; } [Inject] IChatService _chatService { get; set; } [Inject] IJSRuntime _JSRuntime { get; set; } + [Inject] ILocalStorageService _localStorage { get; set; } protected List MessageList = []; protected string? _messageInput; @@ -44,15 +47,20 @@ namespace AntSK.Pages.ChatPage.Components protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - await LoadApp(); + await LoadData(); + var msgs = await _localStorage.GetItemAsync>("msgs"); + if (msgs != null && msgs.Count > 0) + { + MessageList = msgs; + } } protected override async Task OnParametersSetAsync() { - await LoadApp(); + await LoadData(); } - private async Task LoadApp() + private async Task LoadData() { app =await _apps_Repositories.GetFirstAsync(p => p.Id == AppId); } @@ -67,6 +75,7 @@ namespace AntSK.Pages.ChatPage.Components if (result == ConfirmResult.Yes) { MessageList.Clear(); + await _localStorage.SetItemAsync>("msgs", MessageList); _ = Message.Info("清理成功"); } } @@ -99,6 +108,8 @@ namespace AntSK.Pages.ChatPage.Components await SendAsync(_messageInput,filePath); _messageInput = ""; Sendding = false; + + await _localStorage.SetItemAsync>("msgs", MessageList); } catch (System.Exception ex) { diff --git a/src/AntSK/Program.cs b/src/AntSK/Program.cs index c760a15..c20ea5a 100644 --- a/src/AntSK/Program.cs +++ b/src/AntSK/Program.cs @@ -9,6 +9,7 @@ using AntSK.Domain.Repositories; using AntSK.Domain.Utils; using AntSK.plugins.Functions; using AntSK.Services.Auth; +using Blazored.LocalStorage; using LLama.Native; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; @@ -48,6 +49,8 @@ builder.Services.AddServicesFromAssemblies("AntSK.Domain"); builder.Services.AddSingleton(sp => new FunctionService(sp, [typeof(AntSK.App).Assembly])); builder.Services.AddScoped(); builder.Services.AddAntSKSwagger(); +builder.Services.AddBlazoredLocalStorage(config => + config.JsonSerializerOptions.WriteIndented = true); //Mapper builder.Services.AddMapper(); //后台队列任务