exam-paper.blade.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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: 13.2px;
  203. line-height: 1.6;
  204. word-wrap: break-word;
  205. display: flex;
  206. align-items: baseline;
  207. page-break-inside: avoid;
  208. break-inside: avoid;
  209. }
  210. .option strong { margin-right: 4px; flex: 0 0 auto; line-height: 1.6; }
  211. .option-inline { display: inline-flex; align-items: baseline; margin-right: 20px; }
  212. .option-compact { line-height: inherit; }
  213. .option p, .option div { margin: 0; display: inline; }
  214. .option .katex {
  215. font-size: 1em !important;
  216. vertical-align: 0;
  217. }
  218. /* 仅提升分式可读性(不放大整行选项) */
  219. .option .katex .mfrac {
  220. font-size: 1em !important;
  221. }
  222. /* 选项里的分子分母保持可读且不挤压横线 */
  223. .option .katex .mfrac .mtight {
  224. font-size: 1em !important;
  225. }
  226. /* 分数线稍加粗 */
  227. .option .katex .frac-line {
  228. border-bottom-width: 0.055em !important;
  229. }
  230. /* 自动化实测后的分式微调:分母下移、分子上移,避免贴线 */
  231. .option .katex .mfrac .vlist > span:nth-child(1) {
  232. transform: translateY(0.24em) !important;
  233. }
  234. .option .katex .mfrac .vlist > span:nth-child(3) {
  235. transform: translateY(-0.16em) !important;
  236. }
  237. .option .katex-display {
  238. display: inline;
  239. margin: 0 !important;
  240. vertical-align: baseline;
  241. }
  242. /* 答案元信息:不分页 */
  243. .answer-meta {
  244. font-size: 12px;
  245. color: #2f2f2f;
  246. line-height: 1.75;
  247. margin-top: 4px;
  248. page-break-inside: avoid;
  249. break-inside: avoid;
  250. }
  251. .answer-line + .answer-line { margin-top: 4px; }
  252. .solution-step {
  253. align-items: center;
  254. gap: 6px;
  255. }
  256. .step-box { display: inline-block; }
  257. .step-label { white-space: nowrap; }
  258. .solution-heading { font-weight: 700; }
  259. .solution-content { display: inline-block; line-height: 1.75; }
  260. /* 解析区域:不分页 */
  261. .solution-section {
  262. margin-top: 8px;
  263. padding: 6px 8px;
  264. page-break-inside: avoid;
  265. break-inside: avoid;
  266. }
  267. .solution-section strong {
  268. font-size: 13px;
  269. }
  270. .solution-parsed {
  271. margin-top: 6px;
  272. line-height: 1.8;
  273. }
  274. .fill-line {
  275. display: inline-block;
  276. border-bottom: 1px solid #000;
  277. width: 100px;
  278. text-align: center;
  279. }
  280. .answer-space {
  281. height: 150px; /* 解答题留白 */
  282. border: 1px dashed #eee;
  283. margin-top: 10px;
  284. }
  285. /* 答案区域:不分页 */
  286. .answer-area {
  287. position: relative;
  288. margin-top: 12px;
  289. page-break-inside: avoid;
  290. break-inside: avoid;
  291. }
  292. .answer-area .answer-label {
  293. position: absolute;
  294. top: -10px;
  295. left: 10px;
  296. font-size: 10px;
  297. background: #fff;
  298. padding: 0 4px;
  299. color: #555;
  300. letter-spacing: 1px;
  301. }
  302. .answer-area.wavy {
  303. height: 28px;
  304. border-bottom: 1.5px dashed #555;
  305. background-image: repeating-linear-gradient(
  306. -45deg,
  307. rgba(0, 0, 0, 0.35),
  308. rgba(0, 0, 0, 0.35) 4px,
  309. transparent 4px,
  310. transparent 8px
  311. );
  312. background-size: 16px 16px;
  313. background-repeat: repeat-x;
  314. background-position: bottom;
  315. }
  316. .answer-area.boxy {
  317. min-height: 150px;
  318. border: 1.5px solid #444;
  319. border-radius: 6px;
  320. padding: 14px;
  321. }
  322. /* 让内嵌 SVG 按比例缩放展示 */
  323. svg, .math-render svg {
  324. max-width: 100%;
  325. height: auto;
  326. display: block;
  327. /* 确保SVG中的文字和图形元素正确对齐 */
  328. shape-rendering: geometricPrecision;
  329. text-rendering: geometricPrecision;
  330. }
  331. /* 优化SVG中文字标签的显示 */
  332. svg text {
  333. font-family: "Noto Serif", "Noto Serif CJK SC", "Noto Sans CJK SC", "Noto Sans", "STSongti-SC", "PingFang SC", "Songti SC", serif !important;
  334. font-size: 13px !important;
  335. font-weight: bold;
  336. font-style: normal;
  337. dominant-baseline: middle;
  338. text-anchor: middle;
  339. alignment-baseline: central;
  340. /* 确保文字在点的正中央 */
  341. paint-order: stroke fill;
  342. stroke: none;
  343. fill: #000;
  344. }
  345. /* SVG中点标签的精确对齐 */
  346. svg text.label-point {
  347. font-size: 14px;
  348. font-weight: bold;
  349. dx: 0;
  350. dy: 0;
  351. }
  352. /* 确保SVG中的圆形和线条正确渲染 */
  353. svg circle, svg line, svg polygon, svg polyline {
  354. shape-rendering: geometricPrecision;
  355. }
  356. .wavy-underline {
  357. display: inline-block;
  358. min-width: 80px;
  359. height: 22px;
  360. border-bottom: 1.2px dashed #444;
  361. vertical-align: middle;
  362. }
  363. .wavy-underline.short {
  364. min-width: 60px;
  365. }
  366. /* PDF图片容器:防止图片跨页分割 - 增强版 */
  367. .pdf-figure {
  368. break-inside: avoid;
  369. page-break-inside: avoid;
  370. -webkit-column-break-inside: avoid;
  371. break-before: avoid;
  372. break-after: avoid;
  373. page-break-before: avoid;
  374. page-break-after: avoid;
  375. margin: 8px 0;
  376. display: block;
  377. /* 确保图片不会在页面底部被截断 */
  378. min-height: 30px;
  379. /* 限制独立图块尺寸,避免图片压过题干 */
  380. max-height: 82mm;
  381. }
  382. .pdf-figure img {
  383. max-width: min(84%, 420px);
  384. max-height: 82mm;
  385. width: auto;
  386. height: auto;
  387. display: block;
  388. margin: 0 auto;
  389. object-fit: contain;
  390. box-sizing: border-box;
  391. -webkit-print-color-adjust: exact;
  392. print-color-adjust: exact;
  393. image-rendering: -webkit-optimize-contrast;
  394. }
  395. /* 题干中的图片样式(向后兼容) */
  396. .question-stem img,
  397. .question-main img,
  398. .question-content img,
  399. .answer-meta img,
  400. .answer-line img,
  401. .solution-content img,
  402. .solution-section img,
  403. .solution-parsed img {
  404. display: block;
  405. max-width: 220px;
  406. max-height: 60mm;
  407. width: auto;
  408. height: auto;
  409. margin: 6px auto;
  410. box-sizing: border-box;
  411. object-fit: contain;
  412. -webkit-print-color-adjust: exact;
  413. print-color-adjust: exact;
  414. image-rendering: -webkit-optimize-contrast;
  415. }
  416. /* 选项中的图片样式 - 防止超出容器 */
  417. .option img {
  418. max-width: 100%;
  419. height: auto;
  420. vertical-align: middle;
  421. }
  422. @media print {
  423. .no-print {
  424. display: none;
  425. }
  426. body {
  427. -webkit-print-color-adjust: exact;
  428. }
  429. }
  430. .question-stem .katex,
  431. .question-main .katex,
  432. .question-content .katex {
  433. font-size: 1em !important;
  434. /* 避免题干/解析中的行内公式整体下沉 */
  435. vertical-align: 0;
  436. }
  437. .question-stem .katex-display,
  438. .question-main .katex-display,
  439. .question-content .katex-display {
  440. margin: 0.35em 0 !important;
  441. }
  442. </style>
  443. </head>
  444. <body>
  445. <div class="seal-line">
  446. 装&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;题
  447. </div>
  448. <div class="page">
  449. <div class="header">
  450. <div class="school-name">数学智能测试卷</div>
  451. <div class="paper-title">{{ $examCode }}</div>
  452. <div class="info-row">
  453. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  454. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  455. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  456. <span>得分:________</span>
  457. </div>
  458. </div>
  459. @include('components.exam.paper-body', ['questions' => $questions])
  460. {{-- 参考答案(仅在开启时显示) --}}
  461. @if($includeAnswer)
  462. <div style="page-break-before: always; margin-top: 40px;">
  463. <div style="text-align: center; font-size: 22px; font-weight: bold; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px;">
  464. 参考答案
  465. </div>
  466. <div style="font-size: 14px; margin-bottom: 20px; text-align: center; color: #666;">
  467. {{ $paper->paper_name ?? '未命名试卷' }}
  468. </div>
  469. {{-- 选择题答案 --}}
  470. @if(count($questions['choice']) > 0)
  471. <div style="margin-bottom: 20px;">
  472. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">一、选择题</div>
  473. <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 14px;">
  474. @foreach($questions['choice'] as $index => $q)
  475. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  476. <span style="font-weight: bold;">{{ $index + 1 }}.</span>
  477. @if(!empty($q->answer))
  478. <span style="margin-left: 8px; font-weight: bold; color: #d32f2f;">
  479. @php
  480. // 提取答案中的选项字母
  481. $answerText = $q->answer;
  482. $letter = '';
  483. if (preg_match('/([A-D])/i', $answerText, $match)) {
  484. $letter = strtoupper($match[1]);
  485. } elseif (preg_match('/答案[::]\s*([A-D])/i', $answerText, $match)) {
  486. $letter = strtoupper($match[1]);
  487. }
  488. echo $letter ?: '(待补充)';
  489. @endphp
  490. </span>
  491. @else
  492. <span style="margin-left: 8px; color: #999; font-style: italic;">(待补充)</span>
  493. @endif
  494. </div>
  495. @endforeach
  496. </div>
  497. </div>
  498. </div>
  499. @endif
  500. {{-- 填空题答案 --}}
  501. @if(count($questions['fill']) > 0)
  502. <div style="margin-bottom: 20px;">
  503. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">二、填空题</div>
  504. <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 14px;">
  505. @foreach($questions['fill'] as $index => $q)
  506. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  507. <span style="font-weight: bold;">{{ count($questions['choice']) + $index + 1 }}.</span>
  508. <span style="margin-left: 8px;">
  509. @if(!empty($q->answer))
  510. @math($q->answer)
  511. @else
  512. <span style="color: #999; font-style: italic;">(待补充)</span>
  513. @endif
  514. </span>
  515. </div>
  516. @endforeach
  517. </div>
  518. </div>
  519. @endif
  520. {{-- 解答题答案 --}}
  521. @if(count($questions['answer']) > 0)
  522. <div style="margin-bottom: 20px;">
  523. <div style="font-weight: bold; font-size: 16px; margin-bottom: 15px;">三、解答题</div>
  524. <div style="space-y: 15px;">
  525. @foreach($questions['answer'] as $index => $q)
  526. @php
  527. $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1;
  528. @endphp
  529. <div style="margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 4px; border-left: 4px solid #4163ff;">
  530. <div style="font-weight: bold; font-size: 15px; margin-bottom: 10px;">
  531. {{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
  532. </div>
  533. @if(!empty($q->answer))
  534. <div style="font-size: 14px; line-height: 1.8;">
  535. @math($q->answer)
  536. </div>
  537. @else
  538. <div style="font-size: 14px; color: #999; font-style: italic;">
  539. (答案待补充或请参考标准答案)
  540. </div>
  541. @endif
  542. @if(!empty($q->solution))
  543. <div style="margin-top: 10px; font-size: 13px; color: #666; padding-top: 10px; border-top: 1px dashed #ddd;">
  544. <strong>解析:</strong> @math($q->solution)
  545. </div>
  546. @endif
  547. </div>
  548. @endforeach
  549. </div>
  550. </div>
  551. @endif
  552. </div>
  553. @endif
  554. <!-- KaTeX JavaScript 库 -->
  555. <script src="/js/katex.min.js"></script>
  556. <script src="/js/auto-render.min.js"></script>
  557. <script>
  558. document.addEventListener('DOMContentLoaded', function() {
  559. console.log('试卷公式渲染器启动');
  560. // 配置 KaTeX 自动渲染
  561. function renderMath() {
  562. try {
  563. renderMathInElement(document.body, {
  564. delimiters: [
  565. {left: '$$', right: '$$', display: true},
  566. {left: '$', right: '$', display: false},
  567. {left: '\\(', right: '\\)', display: false},
  568. {left: '\\[', right: '\\]', display: true}
  569. ],
  570. throwOnError: false,
  571. strict: false,
  572. trust: true,
  573. macros: {
  574. "\\f": "#1f(#2)"
  575. }
  576. });
  577. console.log('数学公式渲染完成');
  578. } catch (e) {
  579. console.warn('公式渲染警告:', e);
  580. }
  581. }
  582. // 页面加载后渲染
  583. renderMath();
  584. // 如果页面是动态加载的,等待一段时间后再次渲染
  585. setTimeout(renderMath, 500);
  586. setTimeout(renderMath, 1000);
  587. // 添加到全局,必要时手动调用
  588. window.renderExamMath = renderMath;
  589. });
  590. </script>
  591. </body>
  592. </html>