exam-paper.blade.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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: inline-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. @media print {
  324. .no-print {
  325. display: none;
  326. }
  327. body {
  328. -webkit-print-color-adjust: exact;
  329. }
  330. }
  331. </style>
  332. </head>
  333. <body>
  334. <div class="seal-line">
  335. 装&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;题
  336. </div>
  337. <div class="page">
  338. <div class="header">
  339. <div class="school-name">数学智能测试卷</div>
  340. <div class="paper-title">{{ $examCode }}</div>
  341. <div class="info-row">
  342. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  343. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  344. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  345. <span>得分:________</span>
  346. </div>
  347. </div>
  348. @include('components.exam.paper-body', ['questions' => $questions])
  349. {{-- 参考答案(仅在开启时显示) --}}
  350. @if($includeAnswer)
  351. <div style="page-break-before: always; margin-top: 40px;">
  352. <div style="text-align: center; font-size: 22px; font-weight: bold; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px;">
  353. 参考答案
  354. </div>
  355. <div style="font-size: 14px; margin-bottom: 20px; text-align: center; color: #666;">
  356. {{ $paper->paper_name ?? '未命名试卷' }}
  357. </div>
  358. {{-- 选择题答案 --}}
  359. @if(count($questions['choice']) > 0)
  360. <div style="margin-bottom: 20px;">
  361. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">一、选择题</div>
  362. <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 14px;">
  363. @foreach($questions['choice'] as $index => $q)
  364. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  365. <span style="font-weight: bold;">{{ $index + 1 }}.</span>
  366. @if(!empty($q->answer))
  367. <span style="margin-left: 8px; font-weight: bold; color: #d32f2f;">
  368. @php
  369. // 提取答案中的选项字母
  370. $answerText = $q->answer;
  371. $letter = '';
  372. if (preg_match('/([A-D])/i', $answerText, $match)) {
  373. $letter = strtoupper($match[1]);
  374. } elseif (preg_match('/答案[::]\s*([A-D])/i', $answerText, $match)) {
  375. $letter = strtoupper($match[1]);
  376. }
  377. echo $letter ?: '(待补充)';
  378. @endphp
  379. </span>
  380. @else
  381. <span style="margin-left: 8px; color: #999; font-style: italic;">(待补充)</span>
  382. @endif
  383. </div>
  384. @endforeach
  385. </div>
  386. </div>
  387. </div>
  388. @endif
  389. {{-- 填空题答案 --}}
  390. @if(count($questions['fill']) > 0)
  391. <div style="margin-bottom: 20px;">
  392. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">二、填空题</div>
  393. <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 14px;">
  394. @foreach($questions['fill'] as $index => $q)
  395. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  396. <span style="font-weight: bold;">{{ count($questions['choice']) + $index + 1 }}.</span>
  397. <span style="margin-left: 8px;">
  398. @if(!empty($q->answer))
  399. @math($q->answer)
  400. @else
  401. <span style="color: #999; font-style: italic;">(待补充)</span>
  402. @endif
  403. </span>
  404. </div>
  405. @endforeach
  406. </div>
  407. </div>
  408. @endif
  409. {{-- 解答题答案 --}}
  410. @if(count($questions['answer']) > 0)
  411. <div style="margin-bottom: 20px;">
  412. <div style="font-weight: bold; font-size: 16px; margin-bottom: 15px;">三、解答题</div>
  413. <div style="space-y: 15px;">
  414. @foreach($questions['answer'] as $index => $q)
  415. @php
  416. $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1;
  417. @endphp
  418. <div style="margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 4px; border-left: 4px solid #4163ff;">
  419. <div style="font-weight: bold; font-size: 15px; margin-bottom: 10px;">
  420. {{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
  421. </div>
  422. @if(!empty($q->answer))
  423. <div style="font-size: 14px; line-height: 1.8;">
  424. @math($q->answer)
  425. </div>
  426. @else
  427. <div style="font-size: 14px; color: #999; font-style: italic;">
  428. (答案待补充或请参考标准答案)
  429. </div>
  430. @endif
  431. @if(!empty($q->solution))
  432. <div style="margin-top: 10px; font-size: 13px; color: #666; padding-top: 10px; border-top: 1px dashed #ddd;">
  433. <strong>解析:</strong> @math($q->solution)
  434. </div>
  435. @endif
  436. </div>
  437. @endforeach
  438. </div>
  439. </div>
  440. @endif
  441. </div>
  442. @endif
  443. <!-- KaTeX JavaScript 库 -->
  444. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
  445. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
  446. <script>
  447. document.addEventListener('DOMContentLoaded', function() {
  448. console.log('试卷公式渲染器启动');
  449. // 配置 KaTeX 自动渲染
  450. function renderMath() {
  451. try {
  452. renderMathInElement(document.body, {
  453. delimiters: [
  454. {left: '$$', right: '$$', display: true},
  455. {left: '$', right: '$', display: false},
  456. {left: '\\(', right: '\\)', display: false},
  457. {left: '\\[', right: '\\]', display: true}
  458. ],
  459. throwOnError: false,
  460. strict: false,
  461. trust: true,
  462. macros: {
  463. "\\f": "#1f(#2)"
  464. }
  465. });
  466. console.log('数学公式渲染完成');
  467. } catch (e) {
  468. console.warn('公式渲染警告:', e);
  469. }
  470. }
  471. // 页面加载后渲染
  472. renderMath();
  473. // 如果页面是动态加载的,等待一段时间后再次渲染
  474. setTimeout(renderMath, 500);
  475. setTimeout(renderMath, 1000);
  476. // 添加到全局,必要时手动调用
  477. window.renderExamMath = renderMath;
  478. });
  479. </script>
  480. </body>
  481. </html>