exam-paper.blade.php 16 KB

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