CleanExamDto
This commit is contained in:
@@ -40,7 +40,7 @@ namespace TechHelper.Client.Exam
|
||||
|
||||
public static class ExamStructExtensions
|
||||
{
|
||||
public static ExamStruct GetStruct(this ExamDto dto)
|
||||
public static ExamStruct GetStruct(this AssignmentDto dto)
|
||||
{
|
||||
if (dto == null)
|
||||
{
|
||||
@@ -49,7 +49,7 @@ namespace TechHelper.Client.Exam
|
||||
|
||||
var examStruct = new ExamStruct
|
||||
{
|
||||
Title = dto.AssignmentTitle
|
||||
Title = dto.Title
|
||||
};
|
||||
|
||||
GetSeqRecursive(dto.ExamStruct, null, examStruct.Questions);
|
||||
@@ -64,7 +64,7 @@ namespace TechHelper.Client.Exam
|
||||
/// <param name="parentSequence">当前题目组的父级序号(例如:"1", "2.1")。如果为空,则表示顶级题目组。</param>
|
||||
/// <param name="allQuestions">用于收集所有生成题目项的列表。</param>
|
||||
private static void GetSeqRecursive(
|
||||
QuestionGroupDto currentGroup,
|
||||
AssignmentQuestionDto currentGroup,
|
||||
string? parentSequence,
|
||||
List<ExamStruct.QuestionItem> allQuestions)
|
||||
{
|
||||
@@ -72,18 +72,7 @@ namespace TechHelper.Client.Exam
|
||||
? $"{parentSequence}.{currentGroup.Index}"
|
||||
: currentGroup.Index.ToString();
|
||||
|
||||
foreach (var subQuestion in currentGroup.SubQuestions)
|
||||
{
|
||||
string fullSequence = $"{currentGroupSequence}.{subQuestion.Index}";
|
||||
allQuestions.Add(new ExamStruct.QuestionItem
|
||||
{
|
||||
Sequence = fullSequence,
|
||||
QuestionText = subQuestion.Stem ?? string.Empty,
|
||||
Score = subQuestion.Score
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var subGroup in currentGroup.SubQuestionGroups)
|
||||
foreach (var subGroup in currentGroup.ChildrenAssignmentQuestion)
|
||||
{
|
||||
GetSeqRecursive(subGroup, currentGroupSequence, allQuestions);
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
@page "/exam/check/{ExamID}"
|
||||
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mb-4">试卷批改预览: @ExamDto.AssignmentTitle</MudText>
|
||||
<MudText Typo="Typo.h4" Class="mb-4">试卷批改预览: @Assignment.Title</MudText>
|
||||
<MudDivider Class="my-4" />
|
||||
|
||||
@if (_isLoading)
|
||||
@@ -74,36 +74,36 @@ else
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string ExamId { get; set; } // 从路由获取的试卷ID
|
||||
public string ExamId { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IExamService ExamService { get; set; } // 注入试卷服务
|
||||
public IExamService ExamService { get; set; }
|
||||
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; set; } // 注入 Snackbar 用于消息提示
|
||||
private ISnackbar Snackbar { get; set; }
|
||||
|
||||
[Inject]
|
||||
private NavigationManager Navigation { get; set; } // 注入导航管理器
|
||||
private NavigationManager Navigation { get; set; }
|
||||
|
||||
private MudTable<QuestionRowData> _table = new(); // MudTable 实例引用
|
||||
private ExamDto ExamDto { get; set; } = new ExamDto(); // 原始试卷数据
|
||||
private ExamStruct _examStruct = new ExamStruct(); // 处理后的试卷结构,包含带序号的题目
|
||||
private MudTable<QuestionRowData> _table = new();
|
||||
private AssignmentDto Assignment { get; set; } = new AssignmentDto();
|
||||
private ExamStruct _examStruct = new ExamStruct();
|
||||
|
||||
private List<Student> _students = new List<Student>(); // 临时生成的学生列表
|
||||
private List<QuestionRowData> _questionsForTable = new List<QuestionRowData>(); // 用于 MudTable 的数据源
|
||||
private List<Student> _students = new List<Student>();
|
||||
private List<QuestionRowData> _questionsForTable = new List<QuestionRowData>();
|
||||
|
||||
private bool _isLoading = true;
|
||||
|
||||
private bool _isLoading = true; // 加载状态
|
||||
|
||||
// 在组件初始化时加载数据
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_isLoading = true;
|
||||
await LoadExamData();
|
||||
GenerateTemporaryStudentsAndAnswers(); // 生成学生和初始作答数据
|
||||
GenerateTemporaryStudentsAndAnswers();
|
||||
_isLoading = false;
|
||||
}
|
||||
|
||||
// 加载试卷数据的方法
|
||||
|
||||
private async Task LoadExamData()
|
||||
{
|
||||
if (Guid.TryParse(ExamId, out Guid parsedExamId))
|
||||
@@ -113,13 +113,13 @@ else
|
||||
var result = await ExamService.GetExam(parsedExamId);
|
||||
if (result.Status)
|
||||
{
|
||||
ExamDto = result.Result as ExamDto ?? new ExamDto();
|
||||
_examStruct = ExamDto.GetStruct(); // 将 ExamDto 转换为 ExamStruct
|
||||
Assignment = result.Result as AssignmentDto ?? new AssignmentDto();
|
||||
_examStruct = Assignment.GetStruct();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar?.Add($"获取试卷失败: {result.Message}", Severity.Error);
|
||||
Navigation.NavigateTo("/exam/manager"); // 导航回管理页
|
||||
Navigation.NavigateTo("/exam/manager");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Reference in New Issue
Block a user