From 6a2068e8d11ac0340bd9be72d88bd465193ce09b Mon Sep 17 00:00:00 2001 From: jackfiled Date: Wed, 11 Oct 2023 11:54:28 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=96=B0=E5=BB=BA=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E5=92=8C=E5=88=87=E6=8D=A2=E5=AF=B9=E8=AF=9D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/Models/Chat.cs | 12 +++ Frontend/Pages/Index.razor | 91 ++++++++++++++++++- Frontend/Pages/Index.razor.css | 27 ++++++ Frontend/Properties/launchSettings.json | 2 +- .../Shared/{Chat.razor => ChatZone.razor} | 23 +---- .../{Chat.razor.css => ChatZone.razor.css} | 0 Frontend/Shared/MainLayout.razor | 2 +- 7 files changed, 132 insertions(+), 25 deletions(-) create mode 100644 Frontend/Models/Chat.cs rename Frontend/Shared/{Chat.razor => ChatZone.razor} (77%) rename Frontend/Shared/{Chat.razor.css => ChatZone.razor.css} (100%) diff --git a/Frontend/Models/Chat.cs b/Frontend/Models/Chat.cs new file mode 100644 index 0000000..155da10 --- /dev/null +++ b/Frontend/Models/Chat.cs @@ -0,0 +1,12 @@ +namespace Frontend.Models; + +public class Chat +{ + public Guid Guid { get; } = Guid.NewGuid(); + + public string Title { get; set; } = string.Empty; + + public bool Selected { get; set; } + + public List Messages { get; } = new(); +} \ No newline at end of file diff --git a/Frontend/Pages/Index.razor b/Frontend/Pages/Index.razor index ea216ab..c735b7b 100644 --- a/Frontend/Pages/Index.razor +++ b/Frontend/Pages/Index.razor @@ -1,16 +1,97 @@ @page "/" +@using Frontend.Models - - + +
+
+ + +
+ + + + + @if (@context.Selected) + { +
+

@context.Title

+
+ } + else + { +
+

@context.Title

+
+ } +
+
+
+
+
+
+
- + - +
@code { - + private readonly Dictionary _chatDictionary = new(); + + private Guid _currentGuid; + + protected override void OnInitialized() + { + var chat = new Chat + { + Title = $"对话:{_chatDictionary.Count + 1}" + }; + + chat.Messages.Add(new ChatMessage + { + Sender = "凯瑟琳", + Left = true, + Text = "向着星辰和深渊!欢迎来到冒险家协会。" + }); + chat.Selected = true; + + _chatDictionary.Add(chat.Guid, chat); + _currentGuid = chat.Guid; + } + + private void CreateChatClicked() + { + var chat = new Chat + { + Title = $"对话:{_chatDictionary.Count + 1}" + }; + + chat.Messages.Add(new ChatMessage + { + Sender = "凯瑟琳", + Left = true, + Text = "向着星辰和深渊!欢迎来到冒险家协会。" + }); + + _chatDictionary.Add(chat.Guid, chat); + + // 切换到新建的对话 + _chatDictionary[_currentGuid].Selected = false; + _currentGuid = chat.Guid; + _chatDictionary[_currentGuid].Selected = true; + } + + private void ChangeChatClicked(Guid guid) + { + _chatDictionary[_currentGuid].Selected = false; + _currentGuid = guid; + _chatDictionary[_currentGuid].Selected = true; + } } \ No newline at end of file diff --git a/Frontend/Pages/Index.razor.css b/Frontend/Pages/Index.razor.css index e69de29..60503d9 100644 --- a/Frontend/Pages/Index.razor.css +++ b/Frontend/Pages/Index.razor.css @@ -0,0 +1,27 @@ +.chat-control-zone { + margin-top: 20px; + display: flex; + justify-content: center; +} + +.selected-chat-name { + display: flex; + justify-content: center; + margin: 5px 5px 5px; + padding: 5px 0 5px; + border-radius: 5px; + background-color: #bcc9e2; +} + +.chat-name { + display: flex; + justify-content: center; + margin: 5px 5px 5px; + padding: 5px 0 5px; + border-radius: 5px; + background-color: #5d92e4; +} + +.chat-list { + overflow-y: auto; +} \ No newline at end of file diff --git a/Frontend/Properties/launchSettings.json b/Frontend/Properties/launchSettings.json index d518eef..bc94732 100644 --- a/Frontend/Properties/launchSettings.json +++ b/Frontend/Properties/launchSettings.json @@ -10,7 +10,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": false, - "applicationUrl": "http://localhost:5136", + "applicationUrl": "http://localhost:5163", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Frontend/Shared/Chat.razor b/Frontend/Shared/ChatZone.razor similarity index 77% rename from Frontend/Shared/Chat.razor rename to Frontend/Shared/ChatZone.razor index bbb62bf..5d3035c 100644 --- a/Frontend/Shared/Chat.razor +++ b/Frontend/Shared/ChatZone.razor @@ -2,7 +2,7 @@
- + @if (context.Left) { @@ -46,21 +46,8 @@ { private string MessageSending { get; set; } = string.Empty; - private readonly List _messages = new() - { - new ChatMessage - { - Sender = "凯瑟琳", - Text = "向着星辰和深渊!", - Left = true - }, - new ChatMessage - { - Sender = "凯瑟琳", - Text = "欢迎来到冒险家协会。", - Left = true - } - }; + [Parameter] + public List Messages { get; set; } = null!; private void SendMessageClicked() { @@ -69,7 +56,7 @@ return; } - _messages.Add(new ChatMessage + Messages.Add(new ChatMessage { Left = false, Sender = "旅行者", @@ -78,7 +65,7 @@ MessageSending = string.Empty; - _messages.Add(new ChatMessage + Messages.Add(new ChatMessage { Left = true, Sender = "凯瑟琳", diff --git a/Frontend/Shared/Chat.razor.css b/Frontend/Shared/ChatZone.razor.css similarity index 100% rename from Frontend/Shared/Chat.razor.css rename to Frontend/Shared/ChatZone.razor.css diff --git a/Frontend/Shared/MainLayout.razor b/Frontend/Shared/MainLayout.razor index e64f2ad..44f3ae0 100644 --- a/Frontend/Shared/MainLayout.razor +++ b/Frontend/Shared/MainLayout.razor @@ -6,7 +6,7 @@

- 自律型可重编程客服机器人 + 试作自律型可重编程客服机器人