exam-paper.blade.php 18 KB

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