exam-paper.blade.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. @include('pdf.partials.paper-body-core-styles')
  102. .grading-boxes { gap: 4px; flex-wrap: wrap; align-items: center; }
  103. .grading-boxes span { vertical-align: middle; }
  104. .question-main { font-size: 14px; line-height: 1.65; font-family: inherit; display: block; }
  105. .question-score { margin-right: 6px; font-weight: 600; }
  106. .question-score-inline {
  107. display: block;
  108. font-size: 13px;
  109. color: #555;
  110. margin: 0 0 2px 0;
  111. white-space: nowrap;
  112. }
  113. /* 题目内容:防止孤行 */
  114. .question-stem {
  115. display: block;
  116. font-size: 14px;
  117. font-family: inherit;
  118. orphans: 3;
  119. widows: 3;
  120. }
  121. .question-content {
  122. font-size: 14px;
  123. margin-bottom: 8px;
  124. line-height: 1.6;
  125. orphans: 3;
  126. widows: 3;
  127. }
  128. .question-main {
  129. orphans: 3;
  130. widows: 3;
  131. }
  132. .parallel {
  133. font-family: "NotoSansMonoCJKjp", monospace;
  134. letter-spacing: 1px;
  135. }
  136. /* 选项容器:不分页 */
  137. .options {
  138. display: grid;
  139. row-gap: 8px;
  140. margin-top: 8px;
  141. page-break-inside: avoid;
  142. break-inside: avoid;
  143. }
  144. .options-grid-4 {
  145. display: grid;
  146. grid-template-columns: repeat(4, 1fr);
  147. gap: 8px 12px;
  148. page-break-inside: avoid;
  149. break-inside: avoid;
  150. }
  151. .options-grid-2 {
  152. display: grid;
  153. grid-template-columns: 1fr 1fr;
  154. gap: 8px 20px;
  155. page-break-inside: avoid;
  156. break-inside: avoid;
  157. }
  158. .options-grid-1 {
  159. display: grid;
  160. grid-template-columns: 1fr;
  161. gap: 8px;
  162. page-break-inside: avoid;
  163. break-inside: avoid;
  164. }
  165. /* 单个选项:不分页 */
  166. .option {
  167. width: 100%;
  168. font-size: 13.2px;
  169. line-height: 1.6;
  170. word-wrap: break-word;
  171. display: flex;
  172. align-items: baseline;
  173. page-break-inside: avoid;
  174. break-inside: avoid;
  175. }
  176. .option strong { margin-right: 4px; flex: 0 0 auto; line-height: 1.6; }
  177. .option-value { display: inline; }
  178. .option-short { white-space: nowrap; }
  179. .option-long { white-space: normal; word-break: break-word; }
  180. .option-inline { display: inline-flex; align-items: baseline; margin-right: 20px; }
  181. .option-compact { line-height: inherit; }
  182. .option p, .option div { margin: 0; display: inline; }
  183. .option .katex {
  184. font-size: 1em !important;
  185. vertical-align: 0;
  186. }
  187. /* 仅提升分式可读性(不放大整行选项) */
  188. .option .katex .mfrac {
  189. font-size: 1em !important;
  190. }
  191. /* 选项里的分子分母保持可读且不挤压横线 */
  192. .option .katex .mfrac .mtight {
  193. font-size: 1em !important;
  194. }
  195. /* 分数线稍加粗 */
  196. .option .katex .frac-line {
  197. border-bottom-width: 0.055em !important;
  198. }
  199. /* 自动化实测后的分式微调:分母下移、分子上移,避免贴线 */
  200. .option .katex .mfrac .vlist > span:nth-child(1) {
  201. transform: translateY(0.24em) !important;
  202. }
  203. .option .katex .mfrac .vlist > span:nth-child(3) {
  204. transform: translateY(-0.16em) !important;
  205. }
  206. .option .katex-display {
  207. display: inline;
  208. margin: 0 !important;
  209. vertical-align: baseline;
  210. }
  211. /* 答案元信息:不分页 */
  212. .answer-meta {
  213. font-size: 12px;
  214. color: #2f2f2f;
  215. line-height: 1.75;
  216. margin-top: 4px;
  217. page-break-inside: avoid;
  218. break-inside: avoid;
  219. }
  220. .answer-line + .answer-line { margin-top: 4px; }
  221. .solution-step {
  222. align-items: center;
  223. gap: 6px;
  224. }
  225. .step-box { display: inline-block; }
  226. .step-label { white-space: nowrap; }
  227. .solution-heading { font-weight: 700; }
  228. .solution-content { display: inline-block; line-height: 1.75; }
  229. /* 解析区域:不分页 */
  230. .solution-section {
  231. margin-top: 8px;
  232. padding: 6px 8px;
  233. page-break-inside: avoid;
  234. break-inside: avoid;
  235. }
  236. .solution-section strong {
  237. font-size: 13px;
  238. }
  239. .solution-parsed {
  240. margin-top: 6px;
  241. line-height: 1.8;
  242. }
  243. .fill-line {
  244. display: inline-block;
  245. border-bottom: 1px solid #000;
  246. width: 100px;
  247. text-align: center;
  248. }
  249. .answer-space {
  250. height: 150px; /* 解答题留白 */
  251. border: 1px dashed #eee;
  252. margin-top: 10px;
  253. }
  254. /* 答案区域:不分页 */
  255. .answer-area {
  256. position: relative;
  257. margin-top: 12px;
  258. page-break-inside: avoid;
  259. break-inside: avoid;
  260. }
  261. .answer-area .answer-label {
  262. position: absolute;
  263. top: -10px;
  264. left: 10px;
  265. font-size: 10px;
  266. background: #fff;
  267. padding: 0 4px;
  268. color: #555;
  269. letter-spacing: 1px;
  270. }
  271. .answer-area.wavy {
  272. height: 28px;
  273. border-bottom: 1.5px dashed #555;
  274. background-image: repeating-linear-gradient(
  275. -45deg,
  276. rgba(0, 0, 0, 0.35),
  277. rgba(0, 0, 0, 0.35) 4px,
  278. transparent 4px,
  279. transparent 8px
  280. );
  281. background-size: 16px 16px;
  282. background-repeat: repeat-x;
  283. background-position: bottom;
  284. }
  285. .answer-area.boxy {
  286. min-height: 150px;
  287. border: 1.5px solid #444;
  288. border-radius: 6px;
  289. padding: 14px;
  290. }
  291. /* 让内嵌 SVG 按比例缩放展示 */
  292. svg, .math-render svg {
  293. max-width: 100%;
  294. height: auto;
  295. display: block;
  296. /* 确保SVG中的文字和图形元素正确对齐 */
  297. shape-rendering: geometricPrecision;
  298. text-rendering: geometricPrecision;
  299. }
  300. /* 优化SVG中文字标签的显示 */
  301. svg text {
  302. font-family: "Noto Serif", "Noto Serif CJK SC", "Noto Sans CJK SC", "Noto Sans", "STSongti-SC", "PingFang SC", "Songti SC", serif !important;
  303. font-size: 13px !important;
  304. font-weight: bold;
  305. font-style: normal;
  306. dominant-baseline: middle;
  307. text-anchor: middle;
  308. alignment-baseline: central;
  309. /* 确保文字在点的正中央 */
  310. paint-order: stroke fill;
  311. stroke: none;
  312. fill: #000;
  313. }
  314. /* SVG中点标签的精确对齐 */
  315. svg text.label-point {
  316. font-size: 14px;
  317. font-weight: bold;
  318. dx: 0;
  319. dy: 0;
  320. }
  321. /* 确保SVG中的圆形和线条正确渲染 */
  322. svg circle, svg line, svg polygon, svg polyline {
  323. shape-rendering: geometricPrecision;
  324. }
  325. .wavy-underline {
  326. display: inline-block;
  327. min-width: 80px;
  328. height: 22px;
  329. border-bottom: 1.2px dashed #444;
  330. vertical-align: middle;
  331. }
  332. .wavy-underline.short {
  333. min-width: 60px;
  334. }
  335. @include('pdf.partials.paper-exam-shared-image-styles')
  336. @media print {
  337. .no-print {
  338. display: none;
  339. }
  340. body {
  341. -webkit-print-color-adjust: exact;
  342. }
  343. }
  344. .question-stem .katex,
  345. .question-main .katex,
  346. .question-content .katex {
  347. font-size: 1em !important;
  348. /* 避免题干/解析中的行内公式整体下沉 */
  349. vertical-align: 0;
  350. }
  351. .question-stem .katex-display,
  352. .question-main .katex-display,
  353. .question-content .katex-display {
  354. margin: 0.35em 0 !important;
  355. }
  356. </style>
  357. </head>
  358. <body>
  359. <div class="seal-line">
  360. 装&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;题
  361. </div>
  362. <div class="page">
  363. <div class="header">
  364. <div class="school-name">数学智能练习题</div>
  365. <div class="paper-title">{{ $examCode }}</div>
  366. <div class="info-row">
  367. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  368. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  369. @if(!empty($pdfMeta['assemble_type_label']) && $pdfMeta['assemble_type_label'] !== '未知类型')
  370. <span>类型:{{ $pdfMeta['assemble_type_label'] }}</span>
  371. @endif
  372. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  373. <span>得分:________</span>
  374. </div>
  375. </div>
  376. @include('components.exam.paper-body', ['questions' => $questions])
  377. {{-- 参考答案(仅在开启时显示) --}}
  378. @if($includeAnswer)
  379. <div style="page-break-before: always; margin-top: 40px;">
  380. <div style="text-align: center; font-size: 22px; font-weight: bold; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px;">
  381. 参考答案
  382. </div>
  383. <div style="font-size: 14px; margin-bottom: 20px; text-align: center; color: #666;">
  384. {{ $paper->paper_name ?? '未命名试卷' }}
  385. </div>
  386. {{-- 选择题答案 --}}
  387. @if(count($questions['choice']) > 0)
  388. <div style="margin-bottom: 20px;">
  389. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">一、选择题</div>
  390. <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 14px;">
  391. @foreach($questions['choice'] as $index => $q)
  392. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  393. <span style="font-weight: bold;">{{ $index + 1 }}.</span>
  394. @if(!empty($q->answer))
  395. <span style="margin-left: 8px; font-weight: bold; color: #d32f2f;">
  396. @php
  397. // 提取答案中的选项字母
  398. $answerText = $q->answer;
  399. $letter = '';
  400. if (preg_match('/([A-D])/i', $answerText, $match)) {
  401. $letter = strtoupper($match[1]);
  402. } elseif (preg_match('/答案[::]\s*([A-D])/i', $answerText, $match)) {
  403. $letter = strtoupper($match[1]);
  404. }
  405. echo $letter ?: '(待补充)';
  406. @endphp
  407. </span>
  408. @else
  409. <span style="margin-left: 8px; color: #999; font-style: italic;">(待补充)</span>
  410. @endif
  411. </div>
  412. @endforeach
  413. </div>
  414. </div>
  415. </div>
  416. @endif
  417. {{-- 填空题答案 --}}
  418. @if(count($questions['fill']) > 0)
  419. <div style="margin-bottom: 20px;">
  420. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">二、填空题</div>
  421. <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 14px;">
  422. @foreach($questions['fill'] as $index => $q)
  423. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  424. <span style="font-weight: bold;">{{ count($questions['choice']) + $index + 1 }}.</span>
  425. <span style="margin-left: 8px;">
  426. @if(!empty($q->answer))
  427. @math($q->answer)
  428. @else
  429. <span style="color: #999; font-style: italic;">(待补充)</span>
  430. @endif
  431. </span>
  432. </div>
  433. @endforeach
  434. </div>
  435. </div>
  436. @endif
  437. {{-- 解答题答案 --}}
  438. @if(count($questions['answer']) > 0)
  439. <div style="margin-bottom: 20px;">
  440. <div style="font-weight: bold; font-size: 16px; margin-bottom: 15px;">三、解答题</div>
  441. <div style="space-y: 15px;">
  442. @foreach($questions['answer'] as $index => $q)
  443. @php
  444. $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1;
  445. @endphp
  446. <div style="margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 4px; border-left: 4px solid #4163ff;">
  447. <div style="font-weight: bold; font-size: 15px; margin-bottom: 10px;">
  448. {{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
  449. </div>
  450. @if(!empty($q->answer))
  451. <div style="font-size: 14px; line-height: 1.8;">
  452. @math($q->answer)
  453. </div>
  454. @else
  455. <div style="font-size: 14px; color: #999; font-style: italic;">
  456. (答案待补充或请参考标准答案)
  457. </div>
  458. @endif
  459. @if(!empty($q->solution))
  460. <div style="margin-top: 10px; font-size: 13px; color: #666; padding-top: 10px; border-top: 1px dashed #ddd;">
  461. <strong>解析:</strong> @math($q->solution)
  462. </div>
  463. @endif
  464. </div>
  465. @endforeach
  466. </div>
  467. </div>
  468. @endif
  469. </div>
  470. @endif
  471. <!-- KaTeX JavaScript 库 -->
  472. <script src="/js/katex.min.js"></script>
  473. <script src="/js/auto-render.min.js"></script>
  474. <script>
  475. document.addEventListener('DOMContentLoaded', function() {
  476. console.log('试卷公式渲染器启动');
  477. // 配置 KaTeX 自动渲染
  478. function renderMath() {
  479. try {
  480. renderMathInElement(document.body, {
  481. delimiters: [
  482. {left: '$$', right: '$$', display: true},
  483. {left: '$', right: '$', display: false},
  484. {left: '\\(', right: '\\)', display: false},
  485. {left: '\\[', right: '\\]', display: true}
  486. ],
  487. throwOnError: false,
  488. strict: false,
  489. trust: true,
  490. macros: {
  491. "\\f": "#1f(#2)"
  492. }
  493. });
  494. console.log('数学公式渲染完成');
  495. } catch (e) {
  496. console.warn('公式渲染警告:', e);
  497. }
  498. }
  499. // 页面加载后渲染
  500. renderMath();
  501. // 如果页面是动态加载的,等待一段时间后再次渲染
  502. setTimeout(renderMath, 500);
  503. setTimeout(renderMath, 1000);
  504. // 添加到全局,必要时手动调用
  505. window.renderExamMath = renderMath;
  506. });
  507. </script>
  508. </body>
  509. </html>