exam-paper.blade.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>{{ $pdfMeta['exam_pdf_title'] ?? ($paper->paper_name ?? '试卷预览') }}</title>
  6. <link rel="stylesheet" href="/css/katex/katex.min.css">
  7. @php
  8. $examCode = $pdfMeta['exam_code'] ?? ($paper->paper_id ?? 'unknown');
  9. $studentName = $pdfMeta['student_name'] ?? ($student['name'] ?? ($paper->student_id ?? '________'));
  10. $paperHeaderTitle = $pdfMeta['header_title'] ?? ($studentName . '|' . $examCode . '|未知类型');
  11. // 生成时间(格式:2026年01月30日 15:04:05)
  12. $generateDateTime = now()->format('Y年m月d日 H:i:s');
  13. @endphp
  14. <style>
  15. @page {
  16. size: A4;
  17. margin: 2.2cm 2cm 2.3cm 2cm;
  18. @top-left {
  19. content: "知了数学·{{ $generateDateTime }}";
  20. font-size: 13px;
  21. color: #666;
  22. }
  23. @top-center {
  24. content: "{{ $studentName }}";
  25. font-size: 13px;
  26. color: #666;
  27. }
  28. @top-right {
  29. content: "{{ $examCode }}";
  30. font-size: 19px;
  31. font-weight: 600;
  32. font-family: "Noto Sans", "Liberation Sans", "Nimbus Sans", sans-serif;
  33. letter-spacing: 0;
  34. padding-right: 3mm;
  35. padding-top: 1.8mm;
  36. color: #222;
  37. }
  38. @bottom-left {
  39. content: "{{ $paperHeaderTitle }}";
  40. font-size: 11px;
  41. color: #666;
  42. }
  43. @bottom-right {
  44. content: counter(page) "/" counter(pages);
  45. font-size: 13px;
  46. color: #666;
  47. }
  48. }
  49. :root {
  50. --question-gap: 6px;
  51. }
  52. body {
  53. font-family: "Noto Serif", "Noto Serif CJK SC", "Noto Sans CJK SC", "Noto Sans", "STSongti-SC", "PingFang SC", "Songti SC", serif;
  54. line-height: 1.65;
  55. color: #000;
  56. background: #fff;
  57. font-size: 14px;
  58. }
  59. .page {
  60. max-width: 720px;
  61. margin: 0 auto;
  62. padding: 0 12px;
  63. }
  64. .header {
  65. text-align: center;
  66. margin-bottom: 2rem;
  67. border-bottom: 2px solid #000;
  68. padding-bottom: 1rem;
  69. }
  70. .school-name {
  71. font-size: 24px;
  72. font-weight: bold;
  73. margin-bottom: 10px;
  74. }
  75. .paper-title {
  76. font-size: 20px;
  77. font-weight: bold;
  78. margin-bottom: 15px;
  79. }
  80. .info-row {
  81. display: flex;
  82. justify-content: space-between;
  83. font-size: 14px;
  84. margin-bottom: 5px;
  85. }
  86. .seal-line {
  87. position: absolute;
  88. left: -1.5cm;
  89. top: 0;
  90. bottom: 0;
  91. width: 1cm;
  92. border-right: 1px dashed #999;
  93. writing-mode: vertical-rl;
  94. text-align: center;
  95. font-size: 12px;
  96. color: #666;
  97. display: flex;
  98. align-items: center;
  99. justify-content: center;
  100. }
  101. /* 大题标题:不与后面内容分开 */
  102. .section-title {
  103. font-size: 16px;
  104. font-weight: bold;
  105. margin-top: 20px;
  106. margin-bottom: 10px;
  107. page-break-after: avoid;
  108. break-after: avoid;
  109. }
  110. /* 题目整体:不分页 */
  111. .question {
  112. margin-bottom: 15px;
  113. page-break-inside: avoid;
  114. break-inside: avoid;
  115. -webkit-column-break-inside: avoid;
  116. }
  117. /* 题目网格:不分页 */
  118. .question-grid {
  119. display: grid;
  120. grid-template-columns: auto 1fr;
  121. column-gap: 4px;
  122. row-gap: 6px;
  123. align-items: flex-start;
  124. page-break-inside: avoid;
  125. break-inside: avoid;
  126. }
  127. .question-lead {
  128. display: flex;
  129. gap: 4px;
  130. align-items: flex-start;
  131. font-weight: 600;
  132. font-size: 14px;
  133. line-height: 1.65;
  134. margin-top: 1px;
  135. }
  136. .question-lead.spacer { visibility: hidden; }
  137. .question-number { white-space: nowrap; margin-right: 2px; }
  138. .grading-boxes { gap: 4px; flex-wrap: wrap; align-items: center; }
  139. .grading-boxes span { vertical-align: middle; }
  140. .question-main { font-size: 14px; line-height: 1.65; font-family: inherit; display: block; }
  141. .question-score { margin-right: 6px; font-weight: 600; }
  142. .question-score-inline {
  143. display: block;
  144. font-size: 13px;
  145. color: #555;
  146. margin: 0 0 2px 0;
  147. white-space: nowrap;
  148. }
  149. /* 题目内容:防止孤行 */
  150. .question-stem {
  151. display: block;
  152. font-size: 14px;
  153. font-family: inherit;
  154. orphans: 3;
  155. widows: 3;
  156. }
  157. .question-content {
  158. font-size: 14px;
  159. margin-bottom: 8px;
  160. line-height: 1.6;
  161. orphans: 3;
  162. widows: 3;
  163. }
  164. .question-main {
  165. orphans: 3;
  166. widows: 3;
  167. }
  168. /* 选项容器:不分页 */
  169. .options {
  170. display: grid;
  171. row-gap: 8px;
  172. margin-top: 8px;
  173. page-break-inside: avoid;
  174. break-inside: avoid;
  175. }
  176. .options-grid-4 {
  177. display: grid;
  178. grid-template-columns: repeat(4, 1fr);
  179. gap: 8px 12px;
  180. page-break-inside: avoid;
  181. break-inside: avoid;
  182. }
  183. .options-grid-2 {
  184. display: grid;
  185. grid-template-columns: 1fr 1fr;
  186. gap: 8px 20px;
  187. page-break-inside: avoid;
  188. break-inside: avoid;
  189. }
  190. .options-grid-1 {
  191. display: grid;
  192. grid-template-columns: 1fr;
  193. gap: 8px;
  194. page-break-inside: avoid;
  195. break-inside: avoid;
  196. }
  197. /* 单个选项:不分页 */
  198. .option {
  199. width: 100%;
  200. font-size: 13.2px;
  201. line-height: 1.6;
  202. word-wrap: break-word;
  203. display: flex;
  204. align-items: baseline;
  205. page-break-inside: avoid;
  206. break-inside: avoid;
  207. }
  208. .option strong { margin-right: 4px; flex: 0 0 auto; line-height: 1.6; }
  209. .option-value { display: inline; }
  210. .option-short { white-space: nowrap; }
  211. .option-long { white-space: normal; word-break: break-word; }
  212. .option-inline { display: inline-flex; align-items: baseline; margin-right: 20px; }
  213. .option-compact { line-height: inherit; }
  214. .option p, .option div { margin: 0; display: inline; }
  215. .option .katex {
  216. font-size: 1em !important;
  217. vertical-align: 0;
  218. }
  219. /* 仅提升分式可读性(不放大整行选项) */
  220. .option .katex .mfrac {
  221. font-size: 1em !important;
  222. }
  223. /* 选项里的分子分母保持可读且不挤压横线 */
  224. .option .katex .mfrac .mtight {
  225. font-size: 1em !important;
  226. }
  227. /* 分数线稍加粗 */
  228. .option .katex .frac-line {
  229. border-bottom-width: 0.055em !important;
  230. }
  231. /* 自动化实测后的分式微调:分母下移、分子上移,避免贴线 */
  232. .option .katex .mfrac .vlist > span:nth-child(1) {
  233. transform: translateY(0.24em) !important;
  234. }
  235. .option .katex .mfrac .vlist > span:nth-child(3) {
  236. transform: translateY(-0.16em) !important;
  237. }
  238. .option .katex-display {
  239. display: inline;
  240. margin: 0 !important;
  241. vertical-align: baseline;
  242. }
  243. /* 答案元信息:不分页 */
  244. .answer-meta {
  245. font-size: 12px;
  246. color: #2f2f2f;
  247. line-height: 1.75;
  248. margin-top: 4px;
  249. page-break-inside: avoid;
  250. break-inside: avoid;
  251. }
  252. .answer-line + .answer-line { margin-top: 4px; }
  253. .solution-step {
  254. align-items: center;
  255. gap: 6px;
  256. }
  257. .step-box { display: inline-block; }
  258. .step-label { white-space: nowrap; }
  259. .solution-heading { font-weight: 700; }
  260. .solution-content { display: inline-block; line-height: 1.75; }
  261. /* 解析区域:不分页 */
  262. .solution-section {
  263. margin-top: 8px;
  264. padding: 6px 8px;
  265. page-break-inside: avoid;
  266. break-inside: avoid;
  267. }
  268. .solution-section strong {
  269. font-size: 13px;
  270. }
  271. .solution-parsed {
  272. margin-top: 6px;
  273. line-height: 1.8;
  274. }
  275. .fill-line {
  276. display: inline-block;
  277. border-bottom: 1px solid #000;
  278. width: 100px;
  279. text-align: center;
  280. }
  281. .answer-space {
  282. height: 150px; /* 解答题留白 */
  283. border: 1px dashed #eee;
  284. margin-top: 10px;
  285. }
  286. /* 答案区域:不分页 */
  287. .answer-area {
  288. position: relative;
  289. margin-top: 12px;
  290. page-break-inside: avoid;
  291. break-inside: avoid;
  292. }
  293. .answer-area .answer-label {
  294. position: absolute;
  295. top: -10px;
  296. left: 10px;
  297. font-size: 10px;
  298. background: #fff;
  299. padding: 0 4px;
  300. color: #555;
  301. letter-spacing: 1px;
  302. }
  303. .answer-area.wavy {
  304. height: 28px;
  305. border-bottom: 1.5px dashed #555;
  306. background-image: repeating-linear-gradient(
  307. -45deg,
  308. rgba(0, 0, 0, 0.35),
  309. rgba(0, 0, 0, 0.35) 4px,
  310. transparent 4px,
  311. transparent 8px
  312. );
  313. background-size: 16px 16px;
  314. background-repeat: repeat-x;
  315. background-position: bottom;
  316. }
  317. .answer-area.boxy {
  318. min-height: 150px;
  319. border: 1.5px solid #444;
  320. border-radius: 6px;
  321. padding: 14px;
  322. }
  323. /* 让内嵌 SVG 按比例缩放展示 */
  324. svg, .math-render svg {
  325. max-width: 100%;
  326. height: auto;
  327. display: block;
  328. /* 确保SVG中的文字和图形元素正确对齐 */
  329. shape-rendering: geometricPrecision;
  330. text-rendering: geometricPrecision;
  331. }
  332. /* 优化SVG中文字标签的显示 */
  333. svg text {
  334. font-family: "Noto Serif", "Noto Serif CJK SC", "Noto Sans CJK SC", "Noto Sans", "STSongti-SC", "PingFang SC", "Songti SC", serif !important;
  335. font-size: 13px !important;
  336. font-weight: bold;
  337. font-style: normal;
  338. dominant-baseline: middle;
  339. text-anchor: middle;
  340. alignment-baseline: central;
  341. /* 确保文字在点的正中央 */
  342. paint-order: stroke fill;
  343. stroke: none;
  344. fill: #000;
  345. }
  346. /* SVG中点标签的精确对齐 */
  347. svg text.label-point {
  348. font-size: 14px;
  349. font-weight: bold;
  350. dx: 0;
  351. dy: 0;
  352. }
  353. /* 确保SVG中的圆形和线条正确渲染 */
  354. svg circle, svg line, svg polygon, svg polyline {
  355. shape-rendering: geometricPrecision;
  356. }
  357. .wavy-underline {
  358. display: inline-block;
  359. min-width: 80px;
  360. height: 22px;
  361. border-bottom: 1.2px dashed #444;
  362. vertical-align: middle;
  363. }
  364. .wavy-underline.short {
  365. min-width: 60px;
  366. }
  367. /* PDF图片容器:防止图片跨页分割 - 增强版 */
  368. .pdf-figure {
  369. break-inside: avoid;
  370. page-break-inside: avoid;
  371. -webkit-column-break-inside: avoid;
  372. break-before: avoid;
  373. break-after: avoid;
  374. page-break-before: avoid;
  375. page-break-after: avoid;
  376. margin: 8px 0;
  377. display: block;
  378. /* 确保图片不会在页面底部被截断 */
  379. min-height: 30px;
  380. /* 限制独立图块尺寸,避免图片压过题干 */
  381. max-height: 82mm;
  382. }
  383. .pdf-figure img {
  384. max-width: min(84%, 420px);
  385. max-height: 82mm;
  386. width: auto;
  387. height: auto;
  388. display: block;
  389. margin: 0 auto;
  390. object-fit: contain;
  391. box-sizing: border-box;
  392. -webkit-print-color-adjust: exact;
  393. print-color-adjust: exact;
  394. image-rendering: -webkit-optimize-contrast;
  395. }
  396. /* 题干中的图片样式(向后兼容) */
  397. .question-stem img,
  398. .question-main img,
  399. .question-content img,
  400. .answer-meta img,
  401. .answer-line img,
  402. .solution-content img,
  403. .solution-section img,
  404. .solution-parsed img {
  405. display: block;
  406. max-width: 220px;
  407. max-height: 60mm;
  408. width: auto;
  409. height: auto;
  410. margin: 6px auto;
  411. box-sizing: border-box;
  412. object-fit: contain;
  413. -webkit-print-color-adjust: exact;
  414. print-color-adjust: exact;
  415. image-rendering: -webkit-optimize-contrast;
  416. }
  417. /* 选项中的图片样式 - 防止超出容器 */
  418. .option img {
  419. max-width: 100%;
  420. height: auto;
  421. vertical-align: middle;
  422. }
  423. @media print {
  424. .no-print {
  425. display: none;
  426. }
  427. body {
  428. -webkit-print-color-adjust: exact;
  429. }
  430. }
  431. .question-stem .katex,
  432. .question-main .katex,
  433. .question-content .katex {
  434. font-size: 1em !important;
  435. /* 避免题干/解析中的行内公式整体下沉 */
  436. vertical-align: 0;
  437. }
  438. .question-stem .katex-display,
  439. .question-main .katex-display,
  440. .question-content .katex-display {
  441. margin: 0.35em 0 !important;
  442. }
  443. </style>
  444. </head>
  445. <body>
  446. <div class="seal-line">
  447. 装&nbsp;&nbsp;&nbsp;&nbsp;订&nbsp;&nbsp;&nbsp;&nbsp;线&nbsp;&nbsp;&nbsp;&nbsp;内&nbsp;&nbsp;&nbsp;&nbsp;不&nbsp;&nbsp;&nbsp;&nbsp;要&nbsp;&nbsp;&nbsp;&nbsp;答&nbsp;&nbsp;&nbsp;&nbsp;题
  448. </div>
  449. <div class="page">
  450. <div class="header">
  451. <div class="school-name">数学智能练习题</div>
  452. <div class="paper-title">{{ $examCode }}</div>
  453. <div class="info-row">
  454. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  455. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  456. @if(!empty($pdfMeta['assemble_type_label']) && $pdfMeta['assemble_type_label'] !== '未知类型')
  457. <span>类型:{{ $pdfMeta['assemble_type_label'] }}</span>
  458. @endif
  459. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  460. <span>得分:________</span>
  461. </div>
  462. </div>
  463. @include('components.exam.paper-body', ['questions' => $questions])
  464. {{-- 参考答案(仅在开启时显示) --}}
  465. @if($includeAnswer)
  466. <div style="page-break-before: always; margin-top: 40px;">
  467. <div style="text-align: center; font-size: 22px; font-weight: bold; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px;">
  468. 参考答案
  469. </div>
  470. <div style="font-size: 14px; margin-bottom: 20px; text-align: center; color: #666;">
  471. {{ $paper->paper_name ?? '未命名试卷' }}
  472. </div>
  473. {{-- 选择题答案 --}}
  474. @if(count($questions['choice']) > 0)
  475. <div style="margin-bottom: 20px;">
  476. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">一、选择题</div>
  477. <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 14px;">
  478. @foreach($questions['choice'] as $index => $q)
  479. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  480. <span style="font-weight: bold;">{{ $index + 1 }}.</span>
  481. @if(!empty($q->answer))
  482. <span style="margin-left: 8px; font-weight: bold; color: #d32f2f;">
  483. @php
  484. // 提取答案中的选项字母
  485. $answerText = $q->answer;
  486. $letter = '';
  487. if (preg_match('/([A-D])/i', $answerText, $match)) {
  488. $letter = strtoupper($match[1]);
  489. } elseif (preg_match('/答案[::]\s*([A-D])/i', $answerText, $match)) {
  490. $letter = strtoupper($match[1]);
  491. }
  492. echo $letter ?: '(待补充)';
  493. @endphp
  494. </span>
  495. @else
  496. <span style="margin-left: 8px; color: #999; font-style: italic;">(待补充)</span>
  497. @endif
  498. </div>
  499. @endforeach
  500. </div>
  501. </div>
  502. </div>
  503. @endif
  504. {{-- 填空题答案 --}}
  505. @if(count($questions['fill']) > 0)
  506. <div style="margin-bottom: 20px;">
  507. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">二、填空题</div>
  508. <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 14px;">
  509. @foreach($questions['fill'] as $index => $q)
  510. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  511. <span style="font-weight: bold;">{{ count($questions['choice']) + $index + 1 }}.</span>
  512. <span style="margin-left: 8px;">
  513. @if(!empty($q->answer))
  514. @math($q->answer)
  515. @else
  516. <span style="color: #999; font-style: italic;">(待补充)</span>
  517. @endif
  518. </span>
  519. </div>
  520. @endforeach
  521. </div>
  522. </div>
  523. @endif
  524. {{-- 解答题答案 --}}
  525. @if(count($questions['answer']) > 0)
  526. <div style="margin-bottom: 20px;">
  527. <div style="font-weight: bold; font-size: 16px; margin-bottom: 15px;">三、解答题</div>
  528. <div style="space-y: 15px;">
  529. @foreach($questions['answer'] as $index => $q)
  530. @php
  531. $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1;
  532. @endphp
  533. <div style="margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 4px; border-left: 4px solid #4163ff;">
  534. <div style="font-weight: bold; font-size: 15px; margin-bottom: 10px;">
  535. {{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
  536. </div>
  537. @if(!empty($q->answer))
  538. <div style="font-size: 14px; line-height: 1.8;">
  539. @math($q->answer)
  540. </div>
  541. @else
  542. <div style="font-size: 14px; color: #999; font-style: italic;">
  543. (答案待补充或请参考标准答案)
  544. </div>
  545. @endif
  546. @if(!empty($q->solution))
  547. <div style="margin-top: 10px; font-size: 13px; color: #666; padding-top: 10px; border-top: 1px dashed #ddd;">
  548. <strong>解析:</strong> @math($q->solution)
  549. </div>
  550. @endif
  551. </div>
  552. @endforeach
  553. </div>
  554. </div>
  555. @endif
  556. </div>
  557. @endif
  558. <!-- KaTeX JavaScript 库 -->
  559. <script src="/js/katex.min.js"></script>
  560. <script src="/js/auto-render.min.js"></script>
  561. <script>
  562. document.addEventListener('DOMContentLoaded', function() {
  563. console.log('试卷公式渲染器启动');
  564. // 配置 KaTeX 自动渲染
  565. function renderMath() {
  566. try {
  567. renderMathInElement(document.body, {
  568. delimiters: [
  569. {left: '$$', right: '$$', display: true},
  570. {left: '$', right: '$', display: false},
  571. {left: '\\(', right: '\\)', display: false},
  572. {left: '\\[', right: '\\]', display: true}
  573. ],
  574. throwOnError: false,
  575. strict: false,
  576. trust: true,
  577. macros: {
  578. "\\f": "#1f(#2)"
  579. }
  580. });
  581. console.log('数学公式渲染完成');
  582. } catch (e) {
  583. console.warn('公式渲染警告:', e);
  584. }
  585. }
  586. // 页面加载后渲染
  587. renderMath();
  588. // 如果页面是动态加载的,等待一段时间后再次渲染
  589. setTimeout(renderMath, 500);
  590. setTimeout(renderMath, 1000);
  591. // 添加到全局,必要时手动调用
  592. window.renderExamMath = renderMath;
  593. });
  594. </script>
  595. </body>
  596. </html>