186 lines
5.5 KiB
Plaintext
186 lines
5.5 KiB
Plaintext
@page "/exam/create"
|
|
@using AutoMapper
|
|
@using Entities.Contracts
|
|
@using Newtonsoft.Json
|
|
@using TechHelper.Client.Pages.Common
|
|
@using TechHelper.Client.Pages.Exam.ExamView
|
|
@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
|
|
@inject IDialogService DialogService
|
|
|
|
<MudPaper Elevation="5" Class="d-flex overflow-hidden flex-grow-1 pa-1 rounded-xl " Style="overflow:hidden; position:relative;height:100%">
|
|
|
|
|
|
<MudStack Class="flex-grow-1 h-100">
|
|
|
|
<MudPaper Class="rounded-xl ma-1 pa-2" Style="background-color:#fefefefe">
|
|
<MudButton Variant="Variant.Filled" Color="Color.Secondary" Class="rounded-xl" Size="Size.Small" OnClick="OpenEditor">文本编辑器</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Secondary" Class="rounded-xl" Size="Size.Small" OnClick="ParseExam">载入</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Secondary" Class="rounded-xl" Size="Size.Small" OnClick="OpenPublish">发布</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Secondary" Class="rounded-xl" Size="Size.Small" OnClick="OpenPublish">指派</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Secondary" Class="rounded-xl" Size="Size.Small" OnClick="OpenTest">Test</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Secondary" Class="rounded-xl" Size="Size.Small" OnClick="HandleGlobalInfo">GlobalExamInfo</MudButton>
|
|
</MudPaper>
|
|
|
|
|
|
<ExamView Class="overflow-auto ma-1 pa-2 rounded-xl" ClickedStruct="HandleClickedStruct" ParsedExam="ExamContent"></ExamView>
|
|
|
|
<MudPaper MaxWidth="300">
|
|
|
|
@if (_parsedExam.Errors.Any())
|
|
{
|
|
foreach (var item in _parsedExam.Errors)
|
|
{
|
|
<MudText> @item.Message </MudText>
|
|
}
|
|
}
|
|
</MudPaper>
|
|
</MudStack>
|
|
|
|
</MudPaper>
|
|
|
|
@code {
|
|
|
|
[CascadingParameter]
|
|
private Task<AuthenticationState> authenticationStateTask { get; set; }
|
|
|
|
private ExamQuestionDto selectedAssignmentQuestion = new ExamQuestionDto();
|
|
|
|
private BlazoredTextEditor _textEditor = new BlazoredTextEditor();
|
|
private ExamEx _parsedExam = new ExamEx();
|
|
private ExamDto ExamContent = new ExamDto();
|
|
|
|
private ExamParserConfig _examParserConfig { get; set; } = new ExamParserConfig();
|
|
private string EditorText = "";
|
|
|
|
[Inject]
|
|
private ILocalStorageService LocalStorageService { get; set; }
|
|
|
|
[Inject]
|
|
public IMapper Mapper { get; set; }
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
private async void OpenEditor()
|
|
{
|
|
var parameters = new DialogParameters<TextEditorDialog> { { x => x.TextEditor, _textEditor } };
|
|
parameters.Add("EditorText", EditorText);
|
|
|
|
var dialog = await DialogService.ShowAsync<TextEditorDialog>("TextEditor", parameters);
|
|
var result = await dialog.Result;
|
|
if (!result.Canceled)
|
|
{
|
|
_textEditor = result.Data as BlazoredTextEditor ?? new BlazoredTextEditor();
|
|
await ParseExam();
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
private async void OpenPublish()
|
|
{
|
|
var parameters = new DialogParameters<PublishExamDialog> { { x => x.Exam, ExamContent } };
|
|
|
|
var dialog = await DialogService.ShowAsync<PublishExamDialog>("PublishExam", parameters);
|
|
var result = await dialog.Result;
|
|
if (!result.Canceled)
|
|
{
|
|
await Publish();
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async void HandleClickedStruct(ExamQuestionDto dto)
|
|
{
|
|
var parameters = new DialogParameters<QuestionCardDialog> { { x => x.Questions, dto } };
|
|
|
|
var dialog = await DialogService.ShowAsync<QuestionCardDialog>("Edit_Question", parameters);
|
|
var result = await dialog.Result;
|
|
if (!result.Canceled)
|
|
{
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
|
|
[Inject]
|
|
public ICommonService commonService { get; set; }
|
|
|
|
private async Task ParseExam()
|
|
{
|
|
|
|
var plainText = await _textEditor.GetText();
|
|
EditorText = plainText;
|
|
|
|
if (!string.IsNullOrWhiteSpace(plainText))
|
|
{
|
|
try
|
|
{
|
|
var exampar = new ExamParser(_examParserConfig, commonService);
|
|
_parsedExam = exampar.ParseExamPaper(plainText);
|
|
Snackbar.Add("试卷解析成功。", Severity.Success);
|
|
Snackbar.Add($"{_parsedExam.Errors}。", Severity.Success);
|
|
StateHasChanged();
|
|
ExamContent = Mapper.Map<ExamDto>(_parsedExam);
|
|
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);
|
|
}
|
|
public async Task OpenTest()
|
|
{
|
|
Dictionary<string, (Color, string)> Note = new Dictionary<string, (Color, string)> { { "Hello", (Color.Surface, "World") }, { "My", (Color.Surface, "App") }, };
|
|
var json = JsonConvert.SerializeObject(Note);
|
|
|
|
|
|
|
|
Console.WriteLine(json);
|
|
var res = JsonConvert.DeserializeObject<Dictionary<string, (Color, string)>>(json);
|
|
|
|
}
|
|
|
|
private async void HandleGlobalInfo()
|
|
{
|
|
|
|
var parameters = new DialogParameters<ExamGlobalInfoDialog> { { x => x.Assignment, ExamContent } };
|
|
|
|
var dialog = await DialogService.ShowAsync<ExamGlobalInfoDialog>("Exam_GlobalInfo", parameters);
|
|
var result = await dialog.Result;
|
|
if (!result.Canceled)
|
|
{
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
}
|