exam-paper.blade.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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: "SimSun", "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.6;
  136. margin-top: 2px;
  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: "SimSun", "Times New Roman", serif !important;
  305. font-size: 12px;
  306. font-weight: bold;
  307. dominant-baseline: middle;
  308. text-anchor: middle;
  309. alignment-baseline: central;
  310. /* 确保文字在点的正中央 */
  311. paint-order: stroke fill;
  312. stroke: none;
  313. fill: #000;
  314. }
  315. /* SVG中点标签的精确对齐 */
  316. svg text.label-point {
  317. font-size: 14px;
  318. font-weight: bold;
  319. dx: 0;
  320. dy: 0;
  321. }
  322. /* 确保SVG中的圆形和线条正确渲染 */
  323. svg circle, svg line, svg polygon, svg polyline {
  324. shape-rendering: geometricPrecision;
  325. }
  326. .wavy-underline {
  327. display: inline-block;
  328. min-width: 80px;
  329. height: 22px;
  330. border-bottom: 1.2px dashed #444;
  331. vertical-align: middle;
  332. }
  333. .wavy-underline.short {
  334. min-width: 60px;
  335. }
  336. /* PDF图片容器:防止图片跨页分割 - 增强版 */
  337. .pdf-figure {
  338. break-inside: avoid;
  339. page-break-inside: avoid;
  340. -webkit-column-break-inside: avoid;
  341. break-before: avoid;
  342. break-after: avoid;
  343. page-break-before: avoid;
  344. page-break-after: avoid;
  345. margin: 8px 0;
  346. display: block;
  347. /* 确保图片不会在页面底部被截断 */
  348. min-height: 30px;
  349. /* 限制单张图片最大高度,防止过大图片跨页 */
  350. max-height: 180mm;
  351. }
  352. .pdf-figure img {
  353. max-width: 100%;
  354. height: auto;
  355. display: block;
  356. margin: 0 auto;
  357. object-fit: contain;
  358. box-sizing: border-box;
  359. }
  360. /* 题干中的图片样式(向后兼容) */
  361. .question-stem img,
  362. .question-main img,
  363. .question-content img {
  364. display: block;
  365. max-width: 100%;
  366. height: auto;
  367. margin: 12px auto;
  368. box-sizing: border-box;
  369. }
  370. /* 选项中的图片样式 - 防止超出容器 */
  371. .option img {
  372. max-width: 100%;
  373. height: auto;
  374. vertical-align: middle;
  375. }
  376. @media print {
  377. .no-print {
  378. display: none;
  379. }
  380. body {
  381. -webkit-print-color-adjust: exact;
  382. }
  383. }
  384. </style>
  385. </head>
  386. <body>
  387. <div class="seal-line">
  388. 装&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;题
  389. </div>
  390. <div class="page">
  391. <div class="header">
  392. <div class="school-name">数学智能测试卷</div>
  393. <div class="paper-title">{{ $examCode }}</div>
  394. <div class="info-row">
  395. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  396. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  397. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  398. <span>得分:________</span>
  399. </div>
  400. </div>
  401. @include('components.exam.paper-body', ['questions' => $questions])
  402. {{-- 参考答案(仅在开启时显示) --}}
  403. @if($includeAnswer)
  404. <div style="page-break-before: always; margin-top: 40px;">
  405. <div style="text-align: center; font-size: 22px; font-weight: bold; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px;">
  406. 参考答案
  407. </div>
  408. <div style="font-size: 14px; margin-bottom: 20px; text-align: center; color: #666;">
  409. {{ $paper->paper_name ?? '未命名试卷' }}
  410. </div>
  411. {{-- 选择题答案 --}}
  412. @if(count($questions['choice']) > 0)
  413. <div style="margin-bottom: 20px;">
  414. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">一、选择题</div>
  415. <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 14px;">
  416. @foreach($questions['choice'] as $index => $q)
  417. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  418. <span style="font-weight: bold;">{{ $index + 1 }}.</span>
  419. @if(!empty($q->answer))
  420. <span style="margin-left: 8px; font-weight: bold; color: #d32f2f;">
  421. @php
  422. // 提取答案中的选项字母
  423. $answerText = $q->answer;
  424. $letter = '';
  425. if (preg_match('/([A-D])/i', $answerText, $match)) {
  426. $letter = strtoupper($match[1]);
  427. } elseif (preg_match('/答案[::]\s*([A-D])/i', $answerText, $match)) {
  428. $letter = strtoupper($match[1]);
  429. }
  430. echo $letter ?: '(待补充)';
  431. @endphp
  432. </span>
  433. @else
  434. <span style="margin-left: 8px; color: #999; font-style: italic;">(待补充)</span>
  435. @endif
  436. </div>
  437. @endforeach
  438. </div>
  439. </div>
  440. </div>
  441. @endif
  442. {{-- 填空题答案 --}}
  443. @if(count($questions['fill']) > 0)
  444. <div style="margin-bottom: 20px;">
  445. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">二、填空题</div>
  446. <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 14px;">
  447. @foreach($questions['fill'] as $index => $q)
  448. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  449. <span style="font-weight: bold;">{{ count($questions['choice']) + $index + 1 }}.</span>
  450. <span style="margin-left: 8px;">
  451. @if(!empty($q->answer))
  452. @math($q->answer)
  453. @else
  454. <span style="color: #999; font-style: italic;">(待补充)</span>
  455. @endif
  456. </span>
  457. </div>
  458. @endforeach
  459. </div>
  460. </div>
  461. @endif
  462. {{-- 解答题答案 --}}
  463. @if(count($questions['answer']) > 0)
  464. <div style="margin-bottom: 20px;">
  465. <div style="font-weight: bold; font-size: 16px; margin-bottom: 15px;">三、解答题</div>
  466. <div style="space-y: 15px;">
  467. @foreach($questions['answer'] as $index => $q)
  468. @php
  469. $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1;
  470. @endphp
  471. <div style="margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 4px; border-left: 4px solid #4163ff;">
  472. <div style="font-weight: bold; font-size: 15px; margin-bottom: 10px;">
  473. {{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
  474. </div>
  475. @if(!empty($q->answer))
  476. <div style="font-size: 14px; line-height: 1.8;">
  477. @math($q->answer)
  478. </div>
  479. @else
  480. <div style="font-size: 14px; color: #999; font-style: italic;">
  481. (答案待补充或请参考标准答案)
  482. </div>
  483. @endif
  484. @if(!empty($q->solution))
  485. <div style="margin-top: 10px; font-size: 13px; color: #666; padding-top: 10px; border-top: 1px dashed #ddd;">
  486. <strong>解析:</strong> @math($q->solution)
  487. </div>
  488. @endif
  489. </div>
  490. @endforeach
  491. </div>
  492. </div>
  493. @endif
  494. </div>
  495. @endif
  496. <!-- KaTeX JavaScript 库 -->
  497. <script src="/js/katex.min.js"></script>
  498. <script src="/js/auto-render.min.js"></script>
  499. <script>
  500. document.addEventListener('DOMContentLoaded', function() {
  501. console.log('试卷公式渲染器启动');
  502. // 配置 KaTeX 自动渲染
  503. function renderMath() {
  504. try {
  505. renderMathInElement(document.body, {
  506. delimiters: [
  507. {left: '$$', right: '$$', display: true},
  508. {left: '$', right: '$', display: false},
  509. {left: '\\(', right: '\\)', display: false},
  510. {left: '\\[', right: '\\]', display: true}
  511. ],
  512. throwOnError: false,
  513. strict: false,
  514. trust: true,
  515. macros: {
  516. "\\f": "#1f(#2)"
  517. }
  518. });
  519. console.log('数学公式渲染完成');
  520. } catch (e) {
  521. console.warn('公式渲染警告:', e);
  522. }
  523. }
  524. // 页面加载后渲染
  525. renderMath();
  526. // 如果页面是动态加载的,等待一段时间后再次渲染
  527. setTimeout(renderMath, 500);
  528. setTimeout(renderMath, 1000);
  529. // 添加到全局,必要时手动调用
  530. window.renderExamMath = renderMath;
  531. });
  532. </script>
  533. </body>
  534. </html>