grading-scan-sheet.blade.php 5.3 KB

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