| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <title>{{ $paper->paper_name ?? '试卷预览' }}</title>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
- <style>
- @page {
- size: A4;
- margin: 2cm;
- }
- body {
- font-family: "SimSun", "Songti SC", serif; /* 宋体,适合试卷 */
- line-height: 1.6;
- color: #000;
- background: #fff;
- }
- .header {
- text-align: center;
- margin-bottom: 2rem;
- border-bottom: 2px solid #000;
- padding-bottom: 1rem;
- }
- .school-name {
- font-size: 24px;
- font-weight: bold;
- margin-bottom: 10px;
- }
- .paper-title {
- font-size: 20px;
- font-weight: bold;
- margin-bottom: 15px;
- }
- .info-row {
- display: flex;
- justify-content: space-between;
- font-size: 14px;
- margin-bottom: 5px;
- }
- .seal-line {
- position: absolute;
- left: -1.5cm;
- top: 0;
- bottom: 0;
- width: 1cm;
- border-right: 1px dashed #999;
- writing-mode: vertical-rl;
- text-align: center;
- font-size: 12px;
- color: #666;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .section-title {
- font-size: 16px;
- font-weight: bold;
- margin-top: 20px;
- margin-bottom: 10px;
- }
- .question {
- margin-bottom: 15px;
- page-break-inside: avoid;
- }
- .question-content {
- font-size: 14px;
- margin-bottom: 8px;
- display: flex;
- align-items: baseline;
- }
- .omr-marker {
- display: inline-block;
- width: 20px;
- height: 20px;
- border: 1px solid #000;
- border-radius: 50%;
- margin-right: 10px;
- position: relative;
- top: 4px;
- }
- .options {
- display: block;
- 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;
- }
- .fill-line {
- display: inline-block;
- border-bottom: 1px solid #000;
- width: 100px;
- text-align: center;
- }
- .answer-space {
- height: 150px; /* 解答题留白 */
- border: 1px dashed #eee;
- margin-top: 10px;
- }
- @media print {
- .no-print {
- display: none;
- }
- body {
- -webkit-print-color-adjust: exact;
- }
- }
- </style>
- </head>
- <body>
- <div class="seal-line">
- 装 订 线 内 不 要 答 题
- </div>
- <div class="header">
- <div class="school-name">数学智能测试卷</div>
- <div class="paper-title">{{ $paper->paper_name ?? '未命名试卷' }}</div>
- <div class="info-row">
- <span>老师:{{ $teacher['name'] ?? '________' }}</span>
- <span>年级:{{ $student['grade'] ?? '________' }}</span>
- <span>姓名:{{ $student['name'] ?? '________' }}</span>
- <span>得分:________</span>
- </div>
- </div>
- <!-- 一、选择题 -->
- <div class="section-title">一、选择题
- @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
- </div>
- @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
- <div class="question">
- <div class="question-content">
- <span class="omr-marker"></span>
- <span class="font-bold" style="margin-right: 8px;">{{ $questionNumber }}.</span>
- <span style="margin-left: 4px;">({{ $q->score ?? 5 }}分) @math($stemLine)</span>
- </div>
- @if(!empty($options))
- <div class="options">
- @foreach($options as $optIndex => $option)
- <div class="option">
- {{ chr(65 + $optIndex) }}. @math($option)
- </div>
- @endforeach
- </div>
- @endif
- </div>
- @endforeach
- @else
- <div class="question">
- <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
- 该题型正在生成中或暂无题目,请稍后刷新页面查看
- </div>
- </div>
- @endif
- <!-- 二、填空题 -->
- <div class="section-title">二、填空题
- @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
- </div>
- @if(count($questions['fill']) > 0)
- @foreach($questions['fill'] as $index => $q)
- @php
- $questionNumber = count($questions['choice']) + $index + 1; // 填空题接着选择题编号
- @endphp
- <div class="question">
- <div class="question-content">
- <span class="omr-marker"></span>
- <span class="font-bold" style="margin-right: 8px;">{{ $questionNumber }}.</span>
- <span style="margin-left: 4px;">({{ $q->score ?? 5 }}分) @math(str_replace('__________', '<span class="fill-line"></span>', $q->content))</span>
- </div>
- </div>
- @endforeach
- @else
- <div class="question">
- <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
- 该题型正在生成中或暂无题目,请稍后刷新页面查看
- </div>
- </div>
- @endif
- <!-- 三、解答题 -->
- <div class="section-title">三、解答题
- @if(count($questions['answer']) > 0)
- (本大题共 {{ count($questions['answer']) }} 小题,共 {{ array_sum(array_column($questions['answer'], 'score')) }} 分。解答应写出文字说明、证明过程或演算步骤)
- @else
- (本大题共 0 小题,共 0 分)
- @endif
- </div>
- @if(count($questions['answer']) > 0)
- @foreach($questions['answer'] as $index => $q)
- @php
- $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1; // 解答题接着前面所有题型编号
- @endphp
- <div class="question">
- <div class="question-content">
- <span class="omr-marker"></span>
- <span class="font-bold" style="margin-right: 8px;">{{ $questionNumber }}.</span>
- <span style="margin-left: 4px;">({{ $q->score ?? 10 }}分) @math($q->content)</span>
- </div>
- <div class="answer-space"></div>
- </div>
- @endforeach
- @else
- <div class="question">
- <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
- 该题型正在生成中或暂无题目,请稍后刷新页面查看
- </div>
- </div>
- @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
- <div style="margin-top: 30px; padding: 15px; border-top: 2px solid #000; text-align: right; font-size: 14px;">
- <strong>试卷总分:{{ $grandTotal }} 分</strong>
- (选择题 {{ $totalChoiceScore }} 分 + 填空题 {{ $totalFillScore }} 分 + 解答题 {{ $totalAnswerScore }} 分)
- </div>
- <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>
- <!-- KaTeX JavaScript 库 -->
- <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
- <script>
- document.addEventListener('DOMContentLoaded', function() {
- console.log('试卷公式渲染器启动');
- // 配置 KaTeX 自动渲染
- function renderMath() {
- try {
- renderMathInElement(document.body, {
- delimiters: [
- {left: '$$', right: '$$', display: true},
- {left: '$', right: '$', display: false},
- {left: '\\(', right: '\\)', display: false},
- {left: '\\[', right: '\\]', display: true}
- ],
- throwOnError: false,
- strict: false,
- trust: true,
- macros: {
- "\\f": "#1f(#2)"
- }
- });
- console.log('数学公式渲染完成');
- } catch (e) {
- console.warn('公式渲染警告:', e);
- }
- }
- // 页面加载后渲染
- renderMath();
- // 如果页面是动态加载的,等待一段时间后再次渲染
- setTimeout(renderMath, 500);
- setTimeout(renderMath, 1000);
- // 添加到全局,必要时手动调用
- window.renderExamMath = renderMath;
- });
- </script>
- </body>
- </html>
|