装    订    线    内    不    要    答    题
数学智能测试卷
{{ $paper->paper_name ?? '未命名试卷' }}
老师:{{ $teacher['name'] ?? '________' }} 年级:{{ $student['grade'] ?? '________' }} 姓名:{{ $student['name'] ?? '________' }} 得分:________
一、选择题 @if(count($questions['choice']) > 0) @php $choiceTotal = array_sum(array_map(fn($q) => $q->score ?? 5, $questions['choice'])); @endphp (本大题共 {{ count($questions['choice']) }} 小题,共 {{ $choiceTotal }} 分) @else (本大题共 0 小题,共 0 分) @endif
@if(count($questions['choice']) > 0) @foreach($questions['choice'] as $index => $q) @php $questionNumber = $index + 1; // 选择题从1开始编号 // 清理和预处理题干内容:移除题号前缀 $cleanContent = preg_replace('/^\d+[\.\、]\s*/', '', $q->content); $cleanContent = trim($cleanContent); // 优先使用控制器传递的选项 $options = $q->options ?? []; // 如果没有从控制器获取到选项,尝试从内容提取 if (empty($options)) { // 支持多种选项格式:A. / A、/ A:/ A. $pattern = '/([A-D])[\.、:.:]\s*(.+?)(?=\s*[A-D][\.、:.:]|$)/su'; if (preg_match_all($pattern, $cleanContent, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $optionText = trim($match[2]); if (!empty($optionText)) { $options[] = $optionText; } } } } // 提取纯题干(选项前的部分) $stemLine = $cleanContent; if (!empty($options)) { // 找到第一个选项标记的位置 if (preg_match('/^(.+?)(?=[A-D][\.、:.:])/su', $cleanContent, $stemMatch)) { $stemLine = trim($stemMatch[1]); } } // 移除题干末尾可能的括号 $stemLine = preg_replace('/()\s*$/', '', $stemLine); $stemLine = trim($stemLine); @endphp
{{ $questionNumber }}. ({{ $q->score ?? 5 }}分) @math($stemLine)
@if(!empty($options)) @php // 确保有4个选项(A、B、C、D) $standardOptions = ['A', 'B', 'C', 'D']; $displayOptions = []; foreach ($standardOptions as $idx => $letter) { if (isset($options[$idx]) && !empty($options[$idx])) { $displayOptions[$letter] = $options[$idx]; } else { // 补充缺失的选项 $displayOptions[$letter] = '(待补充选项' . $letter . ')'; } } // 计算选项长度,决定布局 $maxOptionLength = 0; $totalOptionLength = 0; foreach ($displayOptions as $letter => $option) { $text = strip_tags($option); $length = mb_strlen($text); $maxOptionLength = max($maxOptionLength, $length); $totalOptionLength += $length; } // 三种布局选择: // 1. 一行4列:极短选项(单个选项≤10字符) // 2. 一行2列:短选项(单个选项≤25字符) // 3. 垂直布局:长选项(单个选项>25字符) if ($maxOptionLength <= 10) { $layoutType = 'inline-4'; $maxOptionLength = 12; // 给一点余量 } elseif ($maxOptionLength <= 25) { $layoutType = 'grid-2'; $maxOptionLength = 30; // 给一点余量 } else { $layoutType = 'vertical'; } @endphp @if($layoutType === 'inline-4') {{-- 极短选项:一行4列布局 --}}
@foreach($displayOptions as $letter => $option) {{ $letter }}. @math($option) @endforeach
@elseif($layoutType === 'grid-2') {{-- 短选项:一行2列布局 --}}
@foreach($displayOptions as $letter => $option)
{{ $letter }}. @math($option)
@endforeach
@else {{-- 长选项:垂直布局 --}}
@foreach($displayOptions as $letter => $option)
{{ $letter }}. @math($option)
@endforeach
@endif @else {{-- 如果没有任何选项,显示占位符 --}}
A. (待补充选项A)
B. (待补充选项B)
C. (待补充选项C)
D. (待补充选项D)
@endif
@endforeach @else
该题型正在生成中或暂无题目,请稍后刷新页面查看
@endif
二、填空题 @if(count($questions['fill']) > 0) @php $fillTotal = array_sum(array_map(fn($q) => $q->score ?? 5, $questions['fill'])); @endphp (本大题共 {{ count($questions['fill']) }} 小题,共 {{ $fillTotal }} 分) @else (本大题共 0 小题,共 0 分) @endif
@if(count($questions['fill']) > 0) @foreach($questions['fill'] as $index => $q) @php $questionNumber = count($questions['choice']) + $index + 1; // 填空题接着选择题编号 @endphp
{{ $questionNumber }}. ({{ $q->score ?? 5 }}分) @math(str_replace('__________', '', $q->content))
@endforeach @else
该题型正在生成中或暂无题目,请稍后刷新页面查看
@endif
三、解答题 @if(count($questions['answer']) > 0) (本大题共 {{ count($questions['answer']) }} 小题,共 {{ array_sum(array_column($questions['answer'], 'score')) }} 分。解答应写出文字说明、证明过程或演算步骤) @else (本大题共 0 小题,共 0 分) @endif
@if(count($questions['answer']) > 0) @foreach($questions['answer'] as $index => $q) @php $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1; // 解答题接着前面所有题型编号 @endphp
{{ $questionNumber }}. ({{ $q->score ?? 10 }}分) @math($q->content)
@endforeach @else
该题型正在生成中或暂无题目,请稍后刷新页面查看
@endif @php $totalChoiceScore = array_sum(array_map(fn($q) => $q->score ?? 5, $questions['choice'])); $totalFillScore = array_sum(array_map(fn($q) => $q->score ?? 5, $questions['fill'])); $totalAnswerScore = array_sum(array_map(fn($q) => $q->score ?? 10, $questions['answer'])); $grandTotal = $totalChoiceScore + $totalFillScore + $totalAnswerScore; @endphp
试卷总分:{{ $grandTotal }} 分 (选择题 {{ $totalChoiceScore }} 分 + 填空题 {{ $totalFillScore }} 分 + 解答题 {{ $totalAnswerScore }} 分)
{{-- 参考答案(仅在开启时显示) --}} @if($includeAnswer)
参考答案
{{ $paper->paper_name ?? '未命名试卷' }}
{{-- 选择题答案 --}} @if(count($questions['choice']) > 0)
一、选择题
@foreach($questions['choice'] as $index => $q)
{{ $index + 1 }}. @if(!empty($q->answer)) @php // 提取答案中的选项字母 $answerText = $q->answer; $letter = ''; if (preg_match('/([A-D])/i', $answerText, $match)) { $letter = strtoupper($match[1]); } elseif (preg_match('/答案[::]\s*([A-D])/i', $answerText, $match)) { $letter = strtoupper($match[1]); } echo $letter ?: '(待补充)'; @endphp @else (待补充) @endif
@endforeach
@endif {{-- 填空题答案 --}} @if(count($questions['fill']) > 0)
二、填空题
@foreach($questions['fill'] as $index => $q)
{{ count($questions['choice']) + $index + 1 }}. @if(!empty($q->answer)) @math($q->answer) @else (待补充) @endif
@endforeach
@endif {{-- 解答题答案 --}} @if(count($questions['answer']) > 0)
三、解答题
@foreach($questions['answer'] as $index => $q) @php $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1; @endphp
{{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
@if(!empty($q->answer))
@math($q->answer)
@else
(答案待补充或请参考标准答案)
@endif @if(!empty($q->solution))
解析: @math($q->solution)
@endif
@endforeach
@endif
@endif