exam-paper.blade.php 19 KB

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