exam-paper.blade.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. .fill-line {
  135. display: inline-block;
  136. border-bottom: 1px solid #000;
  137. width: 100px;
  138. text-align: center;
  139. }
  140. .answer-space {
  141. height: 150px; /* 解答题留白 */
  142. border: 1px dashed #eee;
  143. margin-top: 10px;
  144. }
  145. .answer-area {
  146. position: relative;
  147. margin-top: 12px;
  148. }
  149. .answer-area .answer-label {
  150. position: absolute;
  151. top: -10px;
  152. left: 10px;
  153. font-size: 10px;
  154. background: #fff;
  155. padding: 0 4px;
  156. color: #555;
  157. letter-spacing: 1px;
  158. }
  159. .answer-area.wavy {
  160. height: 28px;
  161. border-bottom: 1.5px dashed #555;
  162. background-image: repeating-linear-gradient(
  163. -45deg,
  164. rgba(0, 0, 0, 0.35),
  165. rgba(0, 0, 0, 0.35) 4px,
  166. transparent 4px,
  167. transparent 8px
  168. );
  169. background-size: 16px 16px;
  170. background-repeat: repeat-x;
  171. background-position: bottom;
  172. }
  173. .answer-area.boxy {
  174. min-height: 150px;
  175. border: 1.5px solid #444;
  176. border-radius: 6px;
  177. padding: 14px;
  178. }
  179. /* 让内嵌 SVG 按比例缩放展示 */
  180. svg, .math-render svg {
  181. max-width: 100%;
  182. height: auto;
  183. display: block;
  184. }
  185. .wavy-underline {
  186. display: inline-block;
  187. min-width: 80px;
  188. height: 22px;
  189. border-bottom: 1.2px dashed #444;
  190. vertical-align: middle;
  191. }
  192. .wavy-underline.short {
  193. min-width: 60px;
  194. }
  195. @media print {
  196. .no-print {
  197. display: none;
  198. }
  199. body {
  200. -webkit-print-color-adjust: exact;
  201. }
  202. }
  203. </style>
  204. </head>
  205. <body>
  206. <div class="seal-line">
  207. 装&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;题
  208. </div>
  209. <div class="page">
  210. <div class="header">
  211. <div class="school-name">数学智能测试卷</div>
  212. <div class="paper-title">{{ $paper->paper_name ?? '未命名试卷' }}</div>
  213. <div class="info-row">
  214. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  215. <span>年级:{{ $student['grade'] ?? '________' }}</span>
  216. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  217. <span>得分:________</span>
  218. </div>
  219. </div>
  220. @include('components.exam.paper-body', ['questions' => $questions])
  221. {{-- 参考答案(仅在开启时显示) --}}
  222. @if($includeAnswer)
  223. <div style="page-break-before: always; margin-top: 40px;">
  224. <div style="text-align: center; font-size: 22px; font-weight: bold; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px;">
  225. 参考答案
  226. </div>
  227. <div style="font-size: 14px; margin-bottom: 20px; text-align: center; color: #666;">
  228. {{ $paper->paper_name ?? '未命名试卷' }}
  229. </div>
  230. {{-- 选择题答案 --}}
  231. @if(count($questions['choice']) > 0)
  232. <div style="margin-bottom: 20px;">
  233. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">一、选择题</div>
  234. <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 14px;">
  235. @foreach($questions['choice'] as $index => $q)
  236. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  237. <span style="font-weight: bold;">{{ $index + 1 }}.</span>
  238. @if(!empty($q->answer))
  239. <span style="margin-left: 8px; font-weight: bold; color: #d32f2f;">
  240. @php
  241. // 提取答案中的选项字母
  242. $answerText = $q->answer;
  243. $letter = '';
  244. if (preg_match('/([A-D])/i', $answerText, $match)) {
  245. $letter = strtoupper($match[1]);
  246. } elseif (preg_match('/答案[::]\s*([A-D])/i', $answerText, $match)) {
  247. $letter = strtoupper($match[1]);
  248. }
  249. echo $letter ?: '(待补充)';
  250. @endphp
  251. </span>
  252. @else
  253. <span style="margin-left: 8px; color: #999; font-style: italic;">(待补充)</span>
  254. @endif
  255. </div>
  256. @endforeach
  257. </div>
  258. </div>
  259. </div>
  260. @endif
  261. {{-- 填空题答案 --}}
  262. @if(count($questions['fill']) > 0)
  263. <div style="margin-bottom: 20px;">
  264. <div style="font-weight: bold; font-size: 16px; margin-bottom: 10px;">二、填空题</div>
  265. <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 14px;">
  266. @foreach($questions['fill'] as $index => $q)
  267. <div style="padding: 8px; background: #f5f5f5; border-radius: 4px;">
  268. <span style="font-weight: bold;">{{ count($questions['choice']) + $index + 1 }}.</span>
  269. <span style="margin-left: 8px;">
  270. @if(!empty($q->answer))
  271. @math($q->answer)
  272. @else
  273. <span style="color: #999; font-style: italic;">(待补充)</span>
  274. @endif
  275. </span>
  276. </div>
  277. @endforeach
  278. </div>
  279. </div>
  280. @endif
  281. {{-- 解答题答案 --}}
  282. @if(count($questions['answer']) > 0)
  283. <div style="margin-bottom: 20px;">
  284. <div style="font-weight: bold; font-size: 16px; margin-bottom: 15px;">三、解答题</div>
  285. <div style="space-y: 15px;">
  286. @foreach($questions['answer'] as $index => $q)
  287. @php
  288. $questionNumber = count($questions['choice']) + count($questions['fill']) + $index + 1;
  289. @endphp
  290. <div style="margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 4px; border-left: 4px solid #4163ff;">
  291. <div style="font-weight: bold; font-size: 15px; margin-bottom: 10px;">
  292. {{ $questionNumber }}. ({{ $q->score ?? 10 }}分)
  293. </div>
  294. @if(!empty($q->answer))
  295. <div style="font-size: 14px; line-height: 1.8;">
  296. @math($q->answer)
  297. </div>
  298. @else
  299. <div style="font-size: 14px; color: #999; font-style: italic;">
  300. (答案待补充或请参考标准答案)
  301. </div>
  302. @endif
  303. @if(!empty($q->solution))
  304. <div style="margin-top: 10px; font-size: 13px; color: #666; padding-top: 10px; border-top: 1px dashed #ddd;">
  305. <strong>解析:</strong> @math($q->solution)
  306. </div>
  307. @endif
  308. </div>
  309. @endforeach
  310. </div>
  311. </div>
  312. @endif
  313. </div>
  314. @endif
  315. <div class="no-print" style="position: fixed; bottom: 20px; right: 20px;">
  316. <button onclick="window.print()" style="padding: 10px 20px; background: #4163ff; color: white; border: none; border-radius: 5px; cursor: pointer;">打印试卷</button>
  317. </div>
  318. <!-- KaTeX JavaScript 库 -->
  319. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
  320. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
  321. <script>
  322. document.addEventListener('DOMContentLoaded', function() {
  323. console.log('试卷公式渲染器启动');
  324. // 配置 KaTeX 自动渲染
  325. function renderMath() {
  326. try {
  327. renderMathInElement(document.body, {
  328. delimiters: [
  329. {left: '$$', right: '$$', display: true},
  330. {left: '$', right: '$', display: false},
  331. {left: '\\(', right: '\\)', display: false},
  332. {left: '\\[', right: '\\]', display: true}
  333. ],
  334. throwOnError: false,
  335. strict: false,
  336. trust: true,
  337. macros: {
  338. "\\f": "#1f(#2)"
  339. }
  340. });
  341. console.log('数学公式渲染完成');
  342. } catch (e) {
  343. console.warn('公式渲染警告:', e);
  344. }
  345. }
  346. // 页面加载后渲染
  347. renderMath();
  348. // 如果页面是动态加载的,等待一段时间后再次渲染
  349. setTimeout(renderMath, 500);
  350. setTimeout(renderMath, 1000);
  351. // 添加到全局,必要时手动调用
  352. window.renderExamMath = renderMath;
  353. });
  354. </script>
  355. </body>
  356. </html>