装    订    线    内    不    要    答    题
数学智能测试卷
{{ $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))
@foreach($options as $optIndex => $option)
{{ chr(65 + $optIndex) }}. @math($option)
@endforeach
@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 }} 分)