@php
// 生成13位识别码:试卷以1开头 + 12位paper_id数字部分
$rawPaperId = $paper->paper_id ?? 'unknown';
// 从 paper_id 提取12位数字部分(格式: paper_xxxxxxxxxxxx)
if (preg_match('/paper_(\d{12})/', $rawPaperId, $matches)) {
$paperIdNum = $matches[1];
} else {
// 兼容旧格式,取数字部分或生成哈希
$paperIdNum = preg_replace('/[^0-9]/', '', $rawPaperId);
$paperIdNum = str_pad(substr($paperIdNum, 0, 12), 12, '0', STR_PAD_LEFT);
}
$examCode = '1' . $paperIdNum; // 试卷识别码:1 + 12位数字
@endphp
@include('components.exam.paper-body', ['questions' => $questions])
{{-- 参考答案(仅在开启时显示) --}}
@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