exam-paper.blade.php 17 KB

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