装 订 线 内 不 要 答 题
一、选择题
@if(count($questions['choice']) > 0)
(本大题共 {{ count($questions['choice']) }} 小题,每小题 {{ $questions['choice'][0]->score ?? 5 }} 分,共 {{ count($questions['choice']) * ($questions['choice'][0]->score ?? 5) }} 分)
@else
(本大题共 0 小题,共 0 分)
@endif
@if(count($questions['choice']) > 0)
@foreach($questions['choice'] as $index => $q)
@php
$questionNumber = $index + 1; // 选择题从1开始编号
@endphp
@php
// 清理和预处理题干内容:移除题号前缀
$cleanContent = preg_replace('/^\d+\.\s*/', '', $q->content);
$cleanContent = trim($cleanContent);
// 检查题干是否包含选项(以换行符分隔)
$contentLines = explode("\n", $cleanContent);
$stemLine = $contentLines[0] ?? $cleanContent;
$stemLine = trim($stemLine);
// 检测是否包含A. B. C. D.格式的选项(在同一行或换行)
$hasOptionsInline = preg_match('/[A-D]\.\s*.{1,50}[A-D]\.\s*.{1,50}[A-D]\.\s*/', $cleanContent);
$hasOptionsMultiLine = count($contentLines) > 1 && preg_match('/^[A-D]\.\s+/', $contentLines[1] ?? '');
$options = [];
if ($hasOptionsInline) {
// 从同一行提取选项
if (preg_match_all('/([A-D])\.\s*([^A-D]*?)(?=\s*[A-D]\.|$)/s', $cleanContent, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$optionText = trim($match[2]);
if (!empty($optionText)) {
$options[] = $optionText;
}
}
}
// 提取纯题干(选项前的部分)
$stemLine = preg_replace('/[A-D]\.\s*.+?(?=[A-D]\.|$)/s', '', $cleanContent);
$stemLine = trim($stemLine);
} elseif ($hasOptionsMultiLine) {
// 从多行提取选项
foreach (array_slice($contentLines, 1) as $line) {
if (preg_match('/^([A-D])\.\s+(.+)$/', trim($line), $matches)) {
$options[] = trim($matches[2]);
}
}
}
@endphp
{{ $questionNumber }}
.
@math($stemLine)
@if(!empty($options))
@foreach($options as $optIndex => $option)
{{ chr(65 + $optIndex) }}. {{ $option }}
@endforeach
@endif
@endforeach
@else
@endif
二、填空题
@if(count($questions['fill']) > 0)
(本大题共 {{ count($questions['fill']) }} 小题,每小题 {{ $questions['fill'][0]->score ?? 5 }} 分,共 {{ count($questions['fill']) * ($questions['fill'][0]->score ?? 5) }} 分)
@else
(本大题共 0 小题,共 0 分)
@endif
@if(count($questions['fill']) > 0)
@foreach($questions['fill'] as $index => $q)
@php
$questionNumber = count($questions['choice']) + $index + 1; // 填空题接着选择题编号
@endphp
{{ $questionNumber }}
.
@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}}分) @math($q->content)
@endforeach
@else
@endif