|
|
@@ -83,13 +83,36 @@
|
|
|
margin-left: 35px; /* 对齐题目内容 */
|
|
|
margin-top: 10px;
|
|
|
}
|
|
|
+ .options-grid-4 {
|
|
|
+ display: grid;
|
|
|
+ grid-template-columns: repeat(4, 1fr);
|
|
|
+ gap: 8px 12px;
|
|
|
+ margin-left: 35px;
|
|
|
+ margin-top: 10px;
|
|
|
+ }
|
|
|
+ .options-grid-2 {
|
|
|
+ display: grid;
|
|
|
+ grid-template-columns: 1fr 1fr;
|
|
|
+ gap: 8px 20px;
|
|
|
+ margin-left: 35px;
|
|
|
+ margin-top: 10px;
|
|
|
+ }
|
|
|
.option {
|
|
|
width: 100%;
|
|
|
font-size: 14px;
|
|
|
- margin-bottom: 8px;
|
|
|
- padding-left: 10px;
|
|
|
line-height: 1.5;
|
|
|
word-wrap: break-word;
|
|
|
+ display: flex;
|
|
|
+ align-items: flex-start;
|
|
|
+ }
|
|
|
+ .option-inline {
|
|
|
+ display: inline-flex;
|
|
|
+ align-items: baseline;
|
|
|
+ margin-right: 20px;
|
|
|
+ }
|
|
|
+ .option-compact {
|
|
|
+ font-size: 13px;
|
|
|
+ line-height: 1.4;
|
|
|
}
|
|
|
.fill-line {
|
|
|
display: inline-block;
|
|
|
@@ -186,12 +209,96 @@
|
|
|
</div>
|
|
|
|
|
|
@if(!empty($options))
|
|
|
- <div class="options">
|
|
|
- @foreach($options as $optIndex => $option)
|
|
|
- <div class="option">
|
|
|
- {{ chr(65 + $optIndex) }}. @math($option)
|
|
|
- </div>
|
|
|
- @endforeach
|
|
|
+ @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列布局 --}}
|
|
|
+ <div style="margin-left: 35px; margin-top: 10px;">
|
|
|
+ <span style="font-size: 14px;">
|
|
|
+ @foreach($displayOptions as $letter => $option)
|
|
|
+ <span class="option-inline option-compact">
|
|
|
+ <span style="font-weight: bold; margin-right: 4px;">{{ $letter }}.</span>
|
|
|
+ <span>@math($option)</span>
|
|
|
+ </span>
|
|
|
+ @endforeach
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ @elseif($layoutType === 'grid-2')
|
|
|
+ {{-- 短选项:一行2列布局 --}}
|
|
|
+ <div class="options-grid-2">
|
|
|
+ @foreach($displayOptions as $letter => $option)
|
|
|
+ <div class="option">
|
|
|
+ <span style="font-weight: bold; margin-right: 8px;">{{ $letter }}.</span>
|
|
|
+ <span>@math($option)</span>
|
|
|
+ </div>
|
|
|
+ @endforeach
|
|
|
+ </div>
|
|
|
+ @else
|
|
|
+ {{-- 长选项:垂直布局 --}}
|
|
|
+ <div class="options">
|
|
|
+ @foreach($displayOptions as $letter => $option)
|
|
|
+ <div class="option">
|
|
|
+ <span style="font-weight: bold; margin-right: 8px;">{{ $letter }}.</span>
|
|
|
+ <span>@math($option)</span>
|
|
|
+ </div>
|
|
|
+ @endforeach
|
|
|
+ </div>
|
|
|
+ @endif
|
|
|
+ @else
|
|
|
+ {{-- 如果没有任何选项,显示占位符 --}}
|
|
|
+ <div class="options-grid-2">
|
|
|
+ <div class="option" style="font-style: italic; color: #999;">
|
|
|
+ <span style="font-weight: bold; margin-right: 8px;">A.</span>
|
|
|
+ <span>(待补充选项A)</span>
|
|
|
+ </div>
|
|
|
+ <div class="option" style="font-style: italic; color: #999;">
|
|
|
+ <span style="font-weight: bold; margin-right: 8px;">B.</span>
|
|
|
+ <span>(待补充选项B)</span>
|
|
|
+ </div>
|
|
|
+ <div class="option" style="font-style: italic; color: #999;">
|
|
|
+ <span style="font-weight: bold; margin-right: 8px;">C.</span>
|
|
|
+ <span>(待补充选项C)</span>
|
|
|
+ </div>
|
|
|
+ <div class="option" style="font-style: italic; color: #999;">
|
|
|
+ <span style="font-weight: bold; margin-right: 8px;">D.</span>
|
|
|
+ <span>(待补充选项D)</span>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
@endif
|
|
|
</div>
|
|
|
@@ -278,6 +385,103 @@
|
|
|
(选择题 {{ $totalChoiceScore }} 分 + 填空题 {{ $totalFillScore }} 分 + 解答题 {{ $totalAnswerScore }} 分)
|
|
|
</div>
|
|
|
|
|
|
+ {{-- 参考答案(仅在开启时显示) --}}
|
|
|
+ @if($includeAnswer)
|
|
|
+ <div style="page-break-before: always; margin-top: 40px;">
|
|
|
+ <div style="text-align: center; font-size: 22px; font-weight: bold; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px;">
|
|
|
+ 参考答案
|
|
|
+ </div>
|
|
|
+ <div style="font-size: 14px; margin-bottom: 20px; text-align: center; color: #666;">
|
|
|
+ {{ $paper->paper_name ?? '未命名试卷' }}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {{-- 选择题答案 --}}
|
|
|
+ @if(count($questions['choice']) > 0)
|
|
|
+ <div style="margin-bottom: 20px;">
|
|
|
+ <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">一、选择题</div>
|
|
|
+ <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 14px;">
|
|
|
+ @foreach($questions['choice'] as $index => $q)
|
|
|
+ <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
|
|
|
+ <span style="font-weight: bold;">{{ $index + 1 }}.</span>
|
|
|
+ @if(!empty($q->answer))
|
|
|
+ <span style="margin-left: 8px; font-weight: bold; color: #d32f2f;">
|
|
|
+ @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
|
|
|
+ </span>
|
|
|
+ @else
|
|
|
+ <span style="margin-left: 8px; color: #999; font-style: italic;">(待补充)</span>
|
|
|
+ @endif
|
|
|
+ </div>
|
|
|
+ @endforeach
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ @endif
|
|
|
+
|
|
|
+ {{-- 填空题答案 --}}
|
|
|
+ @if(count($questions['fill']) > 0)
|
|
|
+ <div style="margin-bottom: 20px;">
|
|
|
+ <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">二、填空题</div>
|
|
|
+ <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 14px;">
|
|
|
+ @foreach($questions['fill'] as $index => $q)
|
|
|
+ <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
|
|
|
+ <span style="font-weight: bold;">{{ count($questions['choice']) + $index + 1 }}.</span>
|
|
|
+ <span style="margin-left: 8px;">
|
|
|
+ @if(!empty($q->answer))
|
|
|
+ @math($q->answer)
|
|
|
+ @else
|
|
|
+ <span style="color: #999; font-style: italic;">(待补充)</span>
|
|
|
+ @endif
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ @endforeach
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ @endif
|
|
|
+
|
|
|
+ {{-- 解答题答案 --}}
|
|
|
+ @if(count($questions['answer']) > 0)
|
|
|
+ <div style="margin-bottom: 20px;">
|
|
|
+ <div style="font-weight: bold; font-size: 16px; margin-bottom: 15px;">三、解答题</div>
|
|
|
+ <div style="space-y: 15px;">
|
|
|
+ @foreach($questions['answer'] as $index => $q)
|
|
|
+ @php
|
|
|
+ $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1;
|
|
|
+ @endphp
|
|
|
+ <div style="margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 4px; border-left: 4px solid #4163ff;">
|
|
|
+ <div style="font-weight: bold; font-size: 15px; margin-bottom: 10px;">
|
|
|
+ {{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
|
|
|
+ </div>
|
|
|
+ @if(!empty($q->answer))
|
|
|
+ <div style="font-size: 14px; line-height: 1.8;">
|
|
|
+ @math($q->answer)
|
|
|
+ </div>
|
|
|
+ @else
|
|
|
+ <div style="font-size: 14px; color: #999; font-style: italic;">
|
|
|
+ (答案待补充或请参考标准答案)
|
|
|
+ </div>
|
|
|
+ @endif
|
|
|
+ @if(!empty($q->solution))
|
|
|
+ <div style="margin-top: 10px; font-size: 13px; color: #666; padding-top: 10px; border-top: 1px dashed #ddd;">
|
|
|
+ <strong>解析:</strong> @math($q->solution)
|
|
|
+ </div>
|
|
|
+ @endif
|
|
|
+ </div>
|
|
|
+ @endforeach
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ @endif
|
|
|
+ </div>
|
|
|
+ @endif
|
|
|
+
|
|
|
<div class="no-print" style="position: fixed; bottom: 20px; right: 20px;">
|
|
|
<button onclick="window.print()" style="padding: 10px 20px; background: #4163ff; color: white; border: none; border-radius: 5px; cursor: pointer;">打印试卷</button>
|
|
|
</div>
|