exam-paper.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. .section-title { font-size: 16px; font-weight: bold; margin-top: 20px; margin-bottom: 10px; }
  91. .question { margin-bottom: 15px; page-break-inside: avoid; }
  92. .question-grid {
  93. display: grid;
  94. grid-template-columns: auto 1fr;
  95. column-gap: 4px;
  96. row-gap: 6px;
  97. align-items: flex-start;
  98. }
  99. .question-lead {
  100. display: flex;
  101. gap: 4px;
  102. align-items: flex-start;
  103. font-weight: 600;
  104. font-size: 14px;
  105. line-height: 1.6;
  106. margin-top: 2px;
  107. }
  108. .question-lead.spacer { visibility: hidden; }
  109. .question-number { white-space: nowrap; margin-right: 2px; }
  110. .grading-boxes { gap: 4px; flex-wrap: wrap; align-items: center; }
  111. .grading-boxes span { vertical-align: middle; }
  112. .question-main { font-size: 14px; line-height: 1.65; font-family: inherit; display: block; }
  113. .question-score { margin-right: 6px; font-weight: 600; }
  114. .question-score-inline {
  115. display: block;
  116. font-size: 13px;
  117. color: #555;
  118. margin: 0 0 4px 0;
  119. white-space: nowrap;
  120. }
  121. .question-stem { display: inline-block; font-size: 14px; font-family: inherit; }
  122. .question-content { font-size: 14px; margin-bottom: 8px; line-height: 1.6; }
  123. .options { display: grid; row-gap: 8px; margin-top: 8px; }
  124. .options-grid-4 {
  125. display: grid;
  126. grid-template-columns: repeat(4, 1fr);
  127. gap: 8px 12px;
  128. }
  129. .options-grid-2 {
  130. display: grid;
  131. grid-template-columns: 1fr 1fr;
  132. gap: 8px 20px;
  133. }
  134. .options-grid-1 {
  135. display: grid;
  136. grid-template-columns: 1fr;
  137. gap: 8px;
  138. }
  139. .option {
  140. width: 100%;
  141. font-size: 14px;
  142. line-height: 1.6;
  143. word-wrap: break-word;
  144. display: flex;
  145. align-items: flex-start;
  146. }
  147. .option strong { margin-right: 4px; }
  148. .option-inline { display: inline-flex; align-items: baseline; margin-right: 20px; }
  149. .option-compact { font-size: 14px; line-height: 1.6; }
  150. .answer-meta {
  151. font-size: 12px;
  152. color: #2f2f2f;
  153. line-height: 1.75;
  154. margin-top: 4px;
  155. }
  156. .answer-line + .answer-line { margin-top: 4px; }
  157. .solution-step {
  158. align-items: center;
  159. gap: 6px;
  160. }
  161. .step-box { display: inline-block; }
  162. .step-label { white-space: nowrap; }
  163. .solution-heading { font-weight: 700; }
  164. .solution-content { display: inline-block; line-height: 1.75; }
  165. .solution-section {
  166. margin-top: 8px;
  167. padding: 6px 8px;
  168. }
  169. .solution-section strong {
  170. font-size: 13px;
  171. }
  172. .solution-parsed {
  173. margin-top: 6px;
  174. line-height: 1.8;
  175. }
  176. .fill-line {
  177. display: inline-block;
  178. border-bottom: 1px solid #000;
  179. width: 100px;
  180. text-align: center;
  181. }
  182. .answer-space {
  183. height: 150px; /* 解答题留白 */
  184. border: 1px dashed #eee;
  185. margin-top: 10px;
  186. }
  187. .answer-area {
  188. position: relative;
  189. margin-top: 12px;
  190. }
  191. .answer-area .answer-label {
  192. position: absolute;
  193. top: -10px;
  194. left: 10px;
  195. font-size: 10px;
  196. background: #fff;
  197. padding: 0 4px;
  198. color: #555;
  199. letter-spacing: 1px;
  200. }
  201. .answer-area.wavy {
  202. height: 28px;
  203. border-bottom: 1.5px dashed #555;
  204. background-image: repeating-linear-gradient(
  205. -45deg,
  206. rgba(0, 0, 0, 0.35),
  207. rgba(0, 0, 0, 0.35) 4px,
  208. transparent 4px,
  209. transparent 8px
  210. );
  211. background-size: 16px 16px;
  212. background-repeat: repeat-x;
  213. background-position: bottom;
  214. }
  215. .answer-area.boxy {
  216. min-height: 150px;
  217. border: 1.5px solid #444;
  218. border-radius: 6px;
  219. padding: 14px;
  220. }
  221. /* 让内嵌 SVG 按比例缩放展示 */
  222. svg, .math-render svg {
  223. max-width: 100%;
  224. height: auto;
  225. display: block;
  226. /* 确保SVG中的文字和图形元素正确对齐 */
  227. shape-rendering: geometricPrecision;
  228. text-rendering: geometricPrecision;
  229. }
  230. /* 优化SVG中文字标签的显示 */
  231. svg text {
  232. font-family: "SimSun", "Times New Roman", serif !important;
  233. font-size: 12px;
  234. font-weight: bold;
  235. dominant-baseline: middle;
  236. text-anchor: middle;
  237. alignment-baseline: central;
  238. /* 确保文字在点的正中央 */
  239. paint-order: stroke fill;
  240. stroke: none;
  241. fill: #000;
  242. }
  243. /* SVG中点标签的精确对齐 */
  244. svg text.label-point {
  245. font-size: 14px;
  246. font-weight: bold;
  247. dx: 0;
  248. dy: 0;
  249. }
  250. /* 确保SVG中的圆形和线条正确渲染 */
  251. svg circle, svg line, svg polygon, svg polyline {
  252. shape-rendering: geometricPrecision;
  253. }
  254. .wavy-underline {
  255. display: inline-block;
  256. min-width: 80px;
  257. height: 22px;
  258. border-bottom: 1.2px dashed #444;
  259. vertical-align: middle;
  260. }
  261. .wavy-underline.short {
  262. min-width: 60px;
  263. }
  264. @media print {
  265. .no-print {
  266. display: none;
  267. }
  268. body {
  269. -webkit-print-color-adjust: exact;
  270. }
  271. }
  272. </style>
  273. </head>
  274. <body>
  275. <div class="seal-line">
  276. 装&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;题
  277. </div>
  278. <div class="page">
  279. <div class="header">
  280. <div class="school-name">数学智能测试卷</div>
  281. <div class="paper-title">{{ $examCode }}</div>
  282. <div class="info-row">
  283. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  284. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  285. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  286. <span>得分:________</span>
  287. </div>
  288. </div>
  289. @include('components.exam.paper-body', ['questions' => $questions])
  290. {{-- 参考答案(仅在开启时显示) --}}
  291. @if($includeAnswer)
  292. <div style="page-break-before: always; margin-top: 40px;">
  293. <div style="text-align: center; font-size: 22px; font-weight: bold; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px;">
  294. 参考答案
  295. </div>
  296. <div style="font-size: 14px; margin-bottom: 20px; text-align: center; color: #666;">
  297. {{ $paper->paper_name ?? '未命名试卷' }}
  298. </div>
  299. {{-- 选择题答案 --}}
  300. @if(count($questions['choice']) > 0)
  301. <div style="margin-bottom: 20px;">
  302. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">一、选择题</div>
  303. <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 14px;">
  304. @foreach($questions['choice'] as $index => $q)
  305. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  306. <span style="font-weight: bold;">{{ $index + 1 }}.</span>
  307. @if(!empty($q->answer))
  308. <span style="margin-left: 8px; font-weight: bold; color: #d32f2f;">
  309. @php
  310. // 提取答案中的选项字母
  311. $answerText = $q->answer;
  312. $letter = '';
  313. if (preg_match('/([A-D])/i', $answerText, $match)) {
  314. $letter = strtoupper($match[1]);
  315. } elseif (preg_match('/答案[::]\s*([A-D])/i', $answerText, $match)) {
  316. $letter = strtoupper($match[1]);
  317. }
  318. echo $letter ?: '(待补充)';
  319. @endphp
  320. </span>
  321. @else
  322. <span style="margin-left: 8px; color: #999; font-style: italic;">(待补充)</span>
  323. @endif
  324. </div>
  325. @endforeach
  326. </div>
  327. </div>
  328. </div>
  329. @endif
  330. {{-- 填空题答案 --}}
  331. @if(count($questions['fill']) > 0)
  332. <div style="margin-bottom: 20px;">
  333. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">二、填空题</div>
  334. <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 14px;">
  335. @foreach($questions['fill'] as $index => $q)
  336. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  337. <span style="font-weight: bold;">{{ count($questions['choice']) + $index + 1 }}.</span>
  338. <span style="margin-left: 8px;">
  339. @if(!empty($q->answer))
  340. @math($q->answer)
  341. @else
  342. <span style="color: #999; font-style: italic;">(待补充)</span>
  343. @endif
  344. </span>
  345. </div>
  346. @endforeach
  347. </div>
  348. </div>
  349. @endif
  350. {{-- 解答题答案 --}}
  351. @if(count($questions['answer']) > 0)
  352. <div style="margin-bottom: 20px;">
  353. <div style="font-weight: bold; font-size: 16px; margin-bottom: 15px;">三、解答题</div>
  354. <div style="space-y: 15px;">
  355. @foreach($questions['answer'] as $index => $q)
  356. @php
  357. $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1;
  358. @endphp
  359. <div style="margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 4px; border-left: 4px solid #4163ff;">
  360. <div style="font-weight: bold; font-size: 15px; margin-bottom: 10px;">
  361. {{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
  362. </div>
  363. @if(!empty($q->answer))
  364. <div style="font-size: 14px; line-height: 1.8;">
  365. @math($q->answer)
  366. </div>
  367. @else
  368. <div style="font-size: 14px; color: #999; font-style: italic;">
  369. (答案待补充或请参考标准答案)
  370. </div>
  371. @endif
  372. @if(!empty($q->solution))
  373. <div style="margin-top: 10px; font-size: 13px; color: #666; padding-top: 10px; border-top: 1px dashed #ddd;">
  374. <strong>解析:</strong> @math($q->solution)
  375. </div>
  376. @endif
  377. </div>
  378. @endforeach
  379. </div>
  380. </div>
  381. @endif
  382. </div>
  383. @endif
  384. <!-- KaTeX JavaScript 库 -->
  385. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
  386. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
  387. <script>
  388. document.addEventListener('DOMContentLoaded', function() {
  389. console.log('试卷公式渲染器启动');
  390. // 配置 KaTeX 自动渲染
  391. function renderMath() {
  392. try {
  393. renderMathInElement(document.body, {
  394. delimiters: [
  395. {left: '$$', right: '$$', display: true},
  396. {left: '$', right: '$', display: false},
  397. {left: '\\(', right: '\\)', display: false},
  398. {left: '\\[', right: '\\]', display: true}
  399. ],
  400. throwOnError: false,
  401. strict: false,
  402. trust: true,
  403. macros: {
  404. "\\f": "#1f(#2)"
  405. }
  406. });
  407. console.log('数学公式渲染完成');
  408. } catch (e) {
  409. console.warn('公式渲染警告:', e);
  410. }
  411. }
  412. // 页面加载后渲染
  413. renderMath();
  414. // 如果页面是动态加载的,等待一段时间后再次渲染
  415. setTimeout(renderMath, 500);
  416. setTimeout(renderMath, 1000);
  417. // 添加到全局,必要时手动调用
  418. window.renderExamMath = renderMath;
  419. });
  420. </script>
  421. </body>
  422. </html>