exam-paper.blade.php 21 KB

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