exam-paper.blade.php 18 KB

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