question-check-scan-sheet.blade.php 5.4 KB

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