grading-scan-sheet.blade.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. @php
  2. $boxCounter = app(\App\Support\GradingMarkBoxCounter::class);
  3. // 按当前试卷真实题目动态生成判题卡条目(题量与方框数)
  4. $scanSheetItems = [];
  5. $countBlanks = fn($text): int => $boxCounter->countFillBlanks($text);
  6. $countAnswerBoxes = fn($stem = '', $solution = ''): int => $boxCounter->countAnswerMarkBoxes($stem, $solution);
  7. foreach (($questions['choice'] ?? []) as $q) {
  8. $scanSheetItems[] = ['no' => (int) ($q->question_number ?? 0), 'box_count' => 1];
  9. }
  10. foreach (($questions['fill'] ?? []) as $q) {
  11. $stemText = (string) ($q->question_text ?? '');
  12. if ($stemText === '') {
  13. // 兼容旧链路:部分历史对象仅有 content 字段
  14. $stemText = (string) ($q->content ?? '');
  15. }
  16. $scanSheetItems[] = [
  17. 'no' => (int) ($q->question_number ?? 0),
  18. 'box_count' => $countBlanks($stemText),
  19. ];
  20. }
  21. foreach (($questions['answer'] ?? []) as $q) {
  22. $stemText = (string) ($q->question_text ?? '');
  23. if ($stemText === '') {
  24. // 兼容旧链路:部分历史对象仅有 content 字段
  25. $stemText = (string) ($q->content ?? '');
  26. }
  27. $scanSheetItems[] = [
  28. 'no' => (int) ($q->question_number ?? 0),
  29. 'box_count' => $countAnswerBoxes($stemText, $q->solution ?? ''),
  30. ];
  31. }
  32. usort($scanSheetItems, static function ($a, $b) {
  33. return ($a['no'] <=> $b['no']);
  34. });
  35. $scanSheetItems = array_values(array_filter($scanSheetItems, static function ($item) {
  36. return (int) ($item['no'] ?? 0) > 0;
  37. }));
  38. $assembleTypeLabel = $pdfMeta['assemble_type_label'] ?? null;
  39. $showAssembleType = !empty($assembleTypeLabel) && $assembleTypeLabel !== '未知类型';
  40. $scanPaperCode = (string) ($pdfMeta['paper_id_num'] ?? $pdfMeta['exam_code'] ?? '');
  41. if ($scanPaperCode === '' && !empty($paper->paper_id)) {
  42. $scanPaperCode = preg_replace('/^paper_/', '', (string) $paper->paper_id) ?: (string) $paper->paper_id;
  43. }
  44. $totalItems = count($scanSheetItems);
  45. $leftCount = (int) ceil($totalItems / 2);
  46. $leftItems = array_slice($scanSheetItems, 0, $leftCount);
  47. $rightItems = array_slice($scanSheetItems, $leftCount);
  48. @endphp
  49. <div class="page scan-sheet-page" style="page-break-before: always; break-before: page; width:100%; max-width:100%; margin:0 auto; padding:0 8px; box-sizing:border-box;">
  50. <div class="scan-sheet-header" style="text-align:center;margin-bottom:1.5rem;border-bottom:2px solid #000;padding-bottom:1rem;">
  51. <div style="font-size:22px;font-weight:bold;">判题卡</div>
  52. @if($scanPaperCode !== '')
  53. <div class="scan-sheet-paper-code" style="margin-top:6px;font-size:18px;font-weight:700;letter-spacing:0.4px;">{{ $scanPaperCode }}</div>
  54. @endif
  55. <div style="display:flex;justify-content:space-between;font-size:14px;margin-top:8px;">
  56. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  57. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  58. @if($showAssembleType)
  59. <span>类型:{{ $assembleTypeLabel }}</span>
  60. @endif
  61. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  62. <span>得分:________</span>
  63. </div>
  64. </div>
  65. <div class="scan-sheet-hint" style="font-size:14px;color:#444;margin-bottom:14px;line-height:1.5;">提示:请根据答案和解析进行批改,在回答正确的 □ 内划 / ,在回答错误的 □ 内打 X 或置空</div>
  66. <div class="scan-sheet-two-cols" style="display:flex;align-items:flex-start;gap:18px;">
  67. <div class="scan-sheet-col" style="flex:1 1 0;display:grid;row-gap:12px;">
  68. @foreach($leftItems as $item)
  69. @php
  70. $questionNo = (int) ($item['no'] ?? 0);
  71. $boxCount = max(1, (int) ($item['box_count'] ?? 1));
  72. @endphp
  73. <div class="scan-sheet-item" style="display:flex;align-items:center;min-height:24px;">
  74. <span class="scan-sheet-no" style="font-weight:700;font-size:14px;line-height:1.2;white-space:nowrap;margin-right:2px;">题目 {{ $questionNo }}.</span>
  75. <span class="scan-sheet-marks" style="display:inline-flex;align-items:center;gap:0;">
  76. @for($i = 0; $i < $boxCount; $i++)
  77. <span class="scan-grade-box" style="display:inline-block;width:21px;height:21px;border:1px solid #333;box-sizing:border-box;background:#fff;vertical-align:middle;margin-right:16px;"></span>
  78. @endfor
  79. </span>
  80. </div>
  81. @endforeach
  82. </div>
  83. <div class="scan-sheet-col" style="flex:1 1 0;display:grid;row-gap:12px;">
  84. @foreach($rightItems as $item)
  85. @php
  86. $questionNo = (int) ($item['no'] ?? 0);
  87. $boxCount = max(1, (int) ($item['box_count'] ?? 1));
  88. @endphp
  89. <div class="scan-sheet-item" style="display:flex;align-items:center;min-height:24px;">
  90. <span class="scan-sheet-no" style="font-weight:700;font-size:14px;line-height:1.2;white-space:nowrap;margin-right:2px;">题目 {{ $questionNo }}.</span>
  91. <span class="scan-sheet-marks" style="display:inline-flex;align-items:center;gap:0;">
  92. @for($i = 0; $i < $boxCount; $i++)
  93. <span class="scan-grade-box" style="display:inline-block;width:21px;height:21px;border:1px solid #333;box-sizing:border-box;background:#fff;vertical-align:middle;margin-right:16px;"></span>
  94. @endfor
  95. </span>
  96. </div>
  97. @endforeach
  98. </div>
  99. </div>
  100. @if($totalItems === 0)
  101. <div class="scan-sheet-empty" style="color:#888;font-size:13px;margin-top:6px;">暂无可渲染题目</div>
  102. @endif
  103. </div>