exam-paper.blade.php 16 KB

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