133 lines
4.2 KiB
Plaintext
133 lines
4.2 KiB
Plaintext
@page "/exam/create"
|
|
@using TechHelper.Client.Services
|
|
@using Blazored.TextEditor
|
|
@using Entities.DTO
|
|
@using TechHelper.Client.Exam
|
|
@inject ILogger<Home> Logger
|
|
@inject ISnackbar Snackbar;
|
|
@using Microsoft.AspNetCore.Components
|
|
@using System.Globalization;
|
|
@using TechHelper.Client.Pages.Editor
|
|
|
|
<MudPaper Elevation="5" Class="d-flex overflow-hidden flex-grow-1" Style="overflow:hidden; position:relative;height:100%">
|
|
<MudDrawerContainer Class="mud-height-full flex-grow-1" Style="height:100%">
|
|
<MudDrawer @bind-Open="@_open" Elevation="0" Variant="@DrawerVariant.Persistent" Color="Color.Primary" Anchor="Anchor.End" OverlayAutoClose="true">
|
|
<MudDrawerHeader>
|
|
<MudText Typo="Typo.h6"> 配置 </MudText>
|
|
</MudDrawerHeader>
|
|
|
|
<MudStack Class="overflow-auto">
|
|
<ParseRoleConfig />
|
|
<MudButton Color="Color.Success"> ParseExam </MudButton>
|
|
</MudStack>
|
|
</MudDrawer>
|
|
<MudStack Row="true" Class="flex-grow-1" Style="height:100%">
|
|
<ExamView Class="overflow-auto" ParsedExam="ExamContent"></ExamView>
|
|
|
|
<MudPaper Class="ma-2">
|
|
<MudPaper Elevation="0" Style="height:calc(100% - 80px)">
|
|
<BlazoredTextEditor @ref="@_textEditor">
|
|
<ToolbarContent>
|
|
<select class="ql-header">
|
|
<option selected=""></option>
|
|
<option value="1"></option>
|
|
<option value="2"></option>
|
|
<option value="3"></option>
|
|
<option value="4"></option>
|
|
<option value="5"></option>
|
|
</select>
|
|
<span class="ql-formats">
|
|
<button class="ql-bold"></button>
|
|
<button class="ql-italic"></button>
|
|
<button class="ql-underline"></button>
|
|
<button class="ql-strike"></button>
|
|
</span>
|
|
<span class="ql-formats">
|
|
<select class="ql-color"></select>
|
|
<select class="ql-background"></select>
|
|
</span>
|
|
<span class="ql-formats">
|
|
<button class="ql-list" value="ordered"></button>
|
|
<button class="ql-list" value="bullet"></button>
|
|
</span>
|
|
<span class="ql-formats">
|
|
<button class="ql-link"></button>
|
|
</span>
|
|
</ToolbarContent>
|
|
<EditorContent>
|
|
</EditorContent>
|
|
</BlazoredTextEditor>
|
|
</MudPaper>
|
|
</MudPaper>
|
|
|
|
<MudButtonGroup Vertical="true" Color="Color.Primary" Variant="Variant.Filled">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Settings" OnClick="@ToggleDrawer" Color="Color.Secondary" />
|
|
<MudIconButton Icon="@Icons.Material.Filled.TransitEnterexit" OnClick="@ParseExam" Color="Color.Secondary" />
|
|
<MudIconButton Icon="@Icons.Material.Filled.Save" OnClick="@ToggleDrawer" Color="Color.Secondary" />
|
|
<MudIconButton Icon="@Icons.Material.Filled.Publish" OnClick="@Publish" Color="Color.Secondary" />
|
|
</MudButtonGroup>
|
|
</MudStack>
|
|
</MudDrawerContainer>
|
|
</MudPaper>
|
|
|
|
@code {
|
|
|
|
[CascadingParameter]
|
|
private Task<AuthenticationState> authenticationStateTask { get; set; }
|
|
|
|
private bool _open = false;
|
|
|
|
private void ToggleDrawer()
|
|
{
|
|
_open = !_open;
|
|
}
|
|
private BlazoredTextEditor _textEditor = new BlazoredTextEditor();
|
|
private ExamPaper _parsedExam = new ExamPaper();
|
|
private AssignmentDto ExamContent = new AssignmentDto();
|
|
|
|
private ExamParserConfig _examParserConfig { get; set; } = new ExamParserConfig();
|
|
|
|
private async Task ParseExam()
|
|
{
|
|
|
|
var plainText = await _textEditor.GetText();
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(plainText))
|
|
{
|
|
try
|
|
{
|
|
var exampar = new ExamParser(_examParserConfig);
|
|
_parsedExam = exampar.ParseExamPaper(plainText);
|
|
Snackbar.Add("试卷解析成功。", Severity.Success);
|
|
Snackbar.Add($"{_parsedExam.Errors}。", Severity.Success);
|
|
ExamContent = _parsedExam.ConvertToExamDTO();
|
|
// ExamContent.SeqIndex();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error parsing exam paper: {ex.Message}");
|
|
Console.WriteLine($"Stack Trace: {ex.StackTrace}");
|
|
|
|
Snackbar.Add($"解析试卷时发生错误:{ex.Message}", Severity.Error);
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Snackbar.Add("试卷文本为空,无法解析。", Severity.Warning);
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
|
|
[Inject]
|
|
public IExamService examService { get; set; }
|
|
|
|
|
|
public async Task Publish()
|
|
{
|
|
var apiRespon = await examService.SaveParsedExam(ExamContent);
|
|
Snackbar.Add(apiRespon.Message);
|
|
}
|
|
|
|
} |