refact: 重构回Server
This commit is contained in:
parent
8e9df3fc52
commit
014fb2a44d
|
@ -1,18 +1,15 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<RunAOTCompilation>true</RunAOTCompilation>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AntDesign" Version="0.15.5" />
|
<PackageReference Include="AntDesign" Version="0.15.5" />
|
||||||
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
|
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
|
||||||
<PackageReference Include="BlazorMonaco" Version="3.1.0" />
|
<PackageReference Include="BlazorMonaco" Version="3.1.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.11" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.11" PrivateAssets="all" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -84,6 +84,25 @@
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
private StandaloneEditorConstructionOptions GetEditorConstructionOptions(StandaloneCodeEditor editor)
|
||||||
{
|
{
|
||||||
return new StandaloneEditorConstructionOptions
|
return new StandaloneEditorConstructionOptions
|
||||||
|
|
|
@ -53,13 +53,17 @@
|
||||||
|
|
||||||
private Guid _currentGuid;
|
private Guid _currentGuid;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
if (firstRender)
|
||||||
{
|
{
|
||||||
await GrammarStorage.RestoreGrammar();
|
await GrammarStorage.RestoreGrammar();
|
||||||
|
|
||||||
Chat chat = GetInitChat();
|
Chat chat = GetInitChat();
|
||||||
_chatDictionary.Add(chat.Guid, chat);
|
_chatDictionary.Add(chat.Guid, chat);
|
||||||
_currentGuid = chat.Guid;
|
_currentGuid = chat.Guid;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
37
Frontend/Pages/_Host.cshtml
Normal file
37
Frontend/Pages/_Host.cshtml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
@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>
|
|
@ -1,21 +1,22 @@
|
||||||
using Blazored.LocalStorage;
|
using Blazored.LocalStorage;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
|
||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
||||||
using Katheryne;
|
using Katheryne;
|
||||||
using Frontend;
|
|
||||||
using Frontend.Services;
|
using Frontend.Services;
|
||||||
|
|
||||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||||
builder.RootComponents.Add<App>("#app");
|
|
||||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
builder.Services.AddRazorPages();
|
||||||
|
builder.Services.AddServerSideBlazor();
|
||||||
|
|
||||||
builder.Services.AddAntDesign();
|
builder.Services.AddAntDesign();
|
||||||
builder.Services.AddBlazoredLocalStorage();
|
builder.Services.AddBlazoredLocalStorage();
|
||||||
|
|
||||||
builder.Logging.SetMinimumLevel(LogLevel.Debug);
|
|
||||||
|
|
||||||
builder.Services.AddKatheryne();
|
builder.Services.AddKatheryne();
|
||||||
builder.Services.AddScoped<GrammarStorageService>();
|
builder.Services.AddScoped<GrammarStorageService>();
|
||||||
|
|
||||||
WebAssemblyHost app = builder.Build();
|
WebApplication app = builder.Build();
|
||||||
|
|
||||||
|
app.UseStaticFiles();
|
||||||
|
app.UseRouting();
|
||||||
|
app.MapBlazorHub();
|
||||||
|
app.MapFallbackToPage("/_Host");
|
||||||
|
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
|
@ -2,7 +2,6 @@
|
||||||
@using System.Net.Http.Json
|
@using System.Net.Http.Json
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
@using Microsoft.AspNetCore.Components.Web
|
@using Microsoft.AspNetCore.Components.Web
|
||||||
@using Microsoft.AspNetCore.Components.WebAssembly.Http
|
|
||||||
@using Microsoft.JSInterop
|
@using Microsoft.JSInterop
|
||||||
@using AntDesign
|
@using AntDesign
|
||||||
@using BlazorMonaco
|
@using BlazorMonaco
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>凯瑟琳</title>
|
|
||||||
<base href="/" />
|
|
||||||
<link href="css/site.css" rel="stylesheet" />
|
|
||||||
<link href="Frontend.styles.css" rel="stylesheet" />
|
|
||||||
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div id="app">
|
|
||||||
<div style="position:absolute; top:30vh; width:100%; text-align:center">
|
|
||||||
<h1>凯瑟琳</h1>
|
|
||||||
<div style="display:flex; gap:10px; justify-content:center; align-items:center">
|
|
||||||
提瓦特有着他自己的法则。。。
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="blazor-error-ui">
|
|
||||||
An unhandled error has occurred.
|
|
||||||
<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.webassembly.js"></script>
|
|
||||||
<script src="js/helper.js"></script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user