| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- <!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;
- }
- :root {
- --question-gap: 6px;
- }
- body {
- font-family: "SimSun", "Songti SC", serif; /* 宋体,适合试卷 */
- line-height: 1.65;
- color: #000;
- background: #fff;
- font-size: 14px;
- }
- .page {
- max-width: 720px;
- margin: 0 auto;
- padding: 0 12px;
- }
- .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-grid {
- display: grid;
- grid-template-columns: auto 1fr;
- column-gap: 4px;
- row-gap: 6px;
- align-items: flex-start;
- }
- .question-lead {
- display: flex;
- gap: 4px;
- align-items: flex-start;
- font-weight: 600;
- font-size: 14px;
- line-height: 1.6;
- margin-top: 2px;
- }
- .question-lead.spacer { visibility: hidden; }
- .question-number { white-space: nowrap; margin-right: 2px; }
- .grading-boxes { gap: 4px; flex-wrap: wrap; align-items: center; }
- .grading-boxes span { vertical-align: middle; }
- .question-main { font-size: 14px; line-height: 1.65; font-family: inherit; display: block; }
- .question-score { margin-right: 6px; font-weight: 600; }
- .question-score-inline {
- display: block;
- font-size: 13px;
- color: #555;
- margin: 0 0 4px 0;
- white-space: nowrap;
- }
- .question-stem { display: inline-block; font-size: 14px; font-family: inherit; }
- .question-content { font-size: 14px; margin-bottom: 8px; line-height: 1.6; }
- .options { display: grid; row-gap: 8px; margin-top: 8px; }
- .options-grid-4 {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: 8px 12px;
- }
- .options-grid-2 {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 8px 20px;
- }
- .option {
- width: 100%;
- font-size: 14px;
- line-height: 1.6;
- word-wrap: break-word;
- display: flex;
- align-items: flex-start;
- }
- .option strong { margin-right: 4px; }
- .option-inline { display: inline-flex; align-items: baseline; margin-right: 20px; }
- .option-compact { font-size: 14px; line-height: 1.6; }
- .answer-meta {
- font-size: 12px;
- color: #2f2f2f;
- line-height: 1.75;
- margin-top: 4px;
- }
- .answer-line + .answer-line { margin-top: 4px; }
- .solution-step {
- align-items: center;
- gap: 6px;
- }
- .step-box { display: inline-block; }
- .step-label { white-space: nowrap; }
- .solution-heading { font-weight: 700; }
- .solution-content { display: inline-block; line-height: 1.75; }
- .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;
- }
- .answer-area {
- position: relative;
- margin-top: 12px;
- }
- .answer-area .answer-label {
- position: absolute;
- top: -10px;
- left: 10px;
- font-size: 10px;
- background: #fff;
- padding: 0 4px;
- color: #555;
- letter-spacing: 1px;
- }
- .answer-area.wavy {
- height: 28px;
- border-bottom: 1.5px dashed #555;
- background-image: repeating-linear-gradient(
- -45deg,
- rgba(0, 0, 0, 0.35),
- rgba(0, 0, 0, 0.35) 4px,
- transparent 4px,
- transparent 8px
- );
- background-size: 16px 16px;
- background-repeat: repeat-x;
- background-position: bottom;
- }
- .answer-area.boxy {
- min-height: 150px;
- border: 1.5px solid #444;
- border-radius: 6px;
- padding: 14px;
- }
- /* 让内嵌 SVG 按比例缩放展示 */
- svg, .math-render svg {
- max-width: 100%;
- height: auto;
- display: block;
- }
- .wavy-underline {
- display: inline-block;
- min-width: 80px;
- height: 22px;
- border-bottom: 1.2px dashed #444;
- vertical-align: middle;
- }
- .wavy-underline.short {
- min-width: 60px;
- }
- @media print {
- .no-print {
- display: none;
- }
- body {
- -webkit-print-color-adjust: exact;
- }
- }
- </style>
- </head>
- <body>
- <div class="seal-line">
- 装 订 线 内 不 要 答 题
- </div>
- <div class="page">
- <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>
- @include('components.exam.paper-body', ['questions' => $questions])
- {{-- 参考答案(仅在开启时显示) --}}
- @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>
- </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>
- <!-- 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>
|