bump: 迁移到.net 8
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
@page "/editor"
|
||||
@using Katheryne.Exceptions
|
||||
@using Katheryne.Abstractions
|
||||
@using Frontend.Services
|
||||
@inject NavigationManager Navigation
|
||||
@inject IChatRobotFactory RobotFactory
|
||||
@inject GrammarStorageService GrammarStorage
|
||||
|
||||
<Layout>
|
||||
<Content>
|
||||
<div class="editor-zone">
|
||||
<div class="control-zone">
|
||||
<Space Size="@("0")">
|
||||
<SpaceItem>
|
||||
<Tooltip Placement="@Placement.Bottom"
|
||||
Title="退出语法编辑器">
|
||||
<Button Type="@ButtonType.Text" OnClick="@QuitButtonClicked">
|
||||
退出
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</SpaceItem>
|
||||
|
||||
<SpaceItem>
|
||||
<Tooltip Placement="@Placement.Bottom"
|
||||
Title="编译文法并保存在浏览器缓存中">
|
||||
<Button Type="@ButtonType.Text" @onclick="@CompileGrammarClicked">
|
||||
编译
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</SpaceItem>
|
||||
|
||||
<SpaceItem>
|
||||
<Tooltip Placement="@Placement.Bottom"
|
||||
Title="清除浏览器缓存中的文法">
|
||||
<Button Type="@ButtonType.Text" @onclick="@ClearGrammarClicked">
|
||||
清除
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</SpaceItem>
|
||||
|
||||
<SpaceItem>
|
||||
<Button Type="@ButtonType.Text" @onclick="HelpButtonClicked">
|
||||
帮助
|
||||
</Button>
|
||||
</SpaceItem>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<StandaloneCodeEditor Id="code-editor" @ref="@_editor"
|
||||
ConstructionOptions="GetEditorConstructionOptions"/>
|
||||
|
||||
<div class="logging-zone">
|
||||
<AntList TItem="@string" DataSource="@_logs" Split="@false" @ref="@_logList">
|
||||
<ListItem Style="padding: 0 0 0">
|
||||
<p class="logging-item">@context</p>
|
||||
</ListItem>
|
||||
</AntList>
|
||||
</div>
|
||||
</div>
|
||||
</Content>
|
||||
</Layout>
|
||||
|
||||
<GrammarHelp @ref="@_grammarHelp"/>
|
||||
|
||||
@code {
|
||||
private StandaloneCodeEditor _editor = null!;
|
||||
private AntList<string> _logList = null!;
|
||||
private GrammarHelp _grammarHelp = null!;
|
||||
|
||||
private readonly List<string> _logs = new();
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
Log("编辑器加载完成");
|
||||
if (await GrammarStorage.RestoreGrammar())
|
||||
{
|
||||
await _editor.SetValue(RobotFactory.GrammarText);
|
||||
Log("从浏览器中恢复成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("尚未设置语法");
|
||||
}
|
||||
}
|
||||
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
private StandaloneEditorConstructionOptions GetEditorConstructionOptions(StandaloneCodeEditor editor)
|
||||
{
|
||||
return new StandaloneEditorConstructionOptions
|
||||
{
|
||||
Language = "yaml",
|
||||
Value = !string.IsNullOrEmpty(RobotFactory.GrammarText) ? RobotFactory.GrammarText : string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
private async Task CompileGrammarClicked()
|
||||
{
|
||||
string grammarText = await _editor.GetValue();
|
||||
|
||||
try
|
||||
{
|
||||
Log("编译文法...");
|
||||
RobotFactory.SetGrammar(grammarText);
|
||||
Log("编译成功!");
|
||||
await GrammarStorage.StoreGrammar();
|
||||
}
|
||||
catch (GrammarException e)
|
||||
{
|
||||
Log($"编译文法遇到错误:{e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void QuitButtonClicked()
|
||||
{
|
||||
Navigation.NavigateTo("/", replace: true);
|
||||
}
|
||||
|
||||
private async Task ClearGrammarClicked()
|
||||
{
|
||||
await GrammarStorage.RemoveGrammar();
|
||||
Log("清除浏览器中的语法成功");
|
||||
}
|
||||
|
||||
private void HelpButtonClicked()
|
||||
{
|
||||
_grammarHelp.Show();
|
||||
}
|
||||
|
||||
private void Log(string message)
|
||||
{
|
||||
_logs.Add($"{DateTime.Now:HH:mm:ss} {message}");
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
.editor-zone {
|
||||
height: calc(100vh - 64px);
|
||||
}
|
||||
|
||||
.control-zone {
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.logging-zone {
|
||||
height: 15%;
|
||||
overflow-y: auto;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.logging-item {
|
||||
margin: 0 0 0;
|
||||
}
|
@@ -1,119 +0,0 @@
|
||||
@page "/"
|
||||
@using Frontend.Models
|
||||
@using Frontend.Services
|
||||
@using Katheryne
|
||||
@using Katheryne.Abstractions
|
||||
@inject IChatRobotFactory ChatRobotFactory
|
||||
@inject GrammarStorageService GrammarStorage
|
||||
@inject DefaultChatRobot DefaultRobot
|
||||
|
||||
|
||||
<Layout>
|
||||
<Sider Width="200">
|
||||
<div class="chat-control-zone">
|
||||
<div>
|
||||
<Button Type="@ButtonType.Primary" Size="large" @onclick="@CreateChatClicked">
|
||||
新建对话
|
||||
</Button>
|
||||
|
||||
<div class="chat-list">
|
||||
<AntList TItem="@Chat" DataSource="@_chatDictionary.Values"
|
||||
Split="@false">
|
||||
<ListItem OnClick="@(() => ChangeChatClicked(context.Guid))">
|
||||
<ListItemMeta>
|
||||
<TitleTemplate>
|
||||
@if (context.Selected)
|
||||
{
|
||||
<div class="selected-chat-name">
|
||||
<p style="margin: 5px">@context.Title</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="chat-name">
|
||||
<p style="margin: 5px">@context.Title</p>
|
||||
</div>
|
||||
}
|
||||
</TitleTemplate>
|
||||
</ListItemMeta>
|
||||
</ListItem>
|
||||
</AntList>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Sider>
|
||||
|
||||
<Content>
|
||||
<ChatZone Messages="@GetChatMessages()" Robot="@GetChatRobot()"/>
|
||||
</Content>
|
||||
</Layout>
|
||||
|
||||
@code {
|
||||
private readonly Dictionary<Guid, Chat> _chatDictionary = new();
|
||||
|
||||
private Guid _currentGuid;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await GrammarStorage.RestoreGrammar();
|
||||
|
||||
Chat chat = GetInitChat();
|
||||
_chatDictionary.Add(chat.Guid, chat);
|
||||
_currentGuid = chat.Guid;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
private void CreateChatClicked()
|
||||
{
|
||||
Chat chat = GetInitChat();
|
||||
|
||||
_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;
|
||||
}
|
||||
|
||||
private Chat GetInitChat()
|
||||
{
|
||||
var chat = new Chat
|
||||
{
|
||||
Title = $"对话:{_chatDictionary.Count + 1}",
|
||||
Robot = ChatRobotFactory.GetRobot()
|
||||
};
|
||||
|
||||
foreach (string answer in chat.Robot.OnChatStart())
|
||||
{
|
||||
chat.Messages.Add(new ChatMessage
|
||||
{
|
||||
Sender = chat.Robot.RobotName,
|
||||
Left = true,
|
||||
Text = answer
|
||||
});
|
||||
}
|
||||
chat.Selected = true;
|
||||
|
||||
return chat;
|
||||
}
|
||||
|
||||
private List<ChatMessage> GetChatMessages()
|
||||
{
|
||||
return _chatDictionary.TryGetValue(_currentGuid, out Chat? chat) ? chat.Messages : new List<ChatMessage>();
|
||||
}
|
||||
|
||||
private IChatRobot GetChatRobot()
|
||||
{
|
||||
return _chatDictionary.TryGetValue(_currentGuid, out Chat? chat) ? chat.Robot : DefaultRobot;
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
.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;
|
||||
margin-top: 40px;
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
@page "/"
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@namespace Frontend.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<base href="~/"/>
|
||||
<link href="css/site.css" rel="stylesheet"/>
|
||||
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" />
|
||||
<link href="Frontend.styles.css" rel="stylesheet">
|
||||
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered"/>
|
||||
</head>
|
||||
<body>
|
||||
<component type="typeof(App)" render-mode="ServerPrerendered"/>
|
||||
|
||||
<div id="blazor-error-ui">
|
||||
<environment include="Staging,Production">
|
||||
An error has occurred. This application may no longer respond until reloaded.
|
||||
</environment>
|
||||
<environment include="Development">
|
||||
An unhandled exception has occurred. See browser dev tools for details.
|
||||
</environment>
|
||||
<a href="" class="reload">Reload</a>
|
||||
<a class="dismiss">🗙</a>
|
||||
</div>
|
||||
|
||||
<script src="_content/AntDesign/js/ant-design-blazor.js"></script>
|
||||
<script src="_content/BlazorMonaco/jsInterop.js"></script>
|
||||
<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/loader.js"></script>
|
||||
<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.js"></script>
|
||||
<script src="_framework/blazor.server.js"></script>
|
||||
<script src="js/helper.js"></script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user