exam-paper.blade.php 19 KB

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