exam-paper.blade.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. body {
  13. font-family: "SimSun", "Songti SC", serif; /* 宋体,适合试卷 */
  14. line-height: 1.6;
  15. color: #000;
  16. background: #fff;
  17. }
  18. .header {
  19. text-align: center;
  20. margin-bottom: 2rem;
  21. border-bottom: 2px solid #000;
  22. padding-bottom: 1rem;
  23. }
  24. .school-name {
  25. font-size: 24px;
  26. font-weight: bold;
  27. margin-bottom: 10px;
  28. }
  29. .paper-title {
  30. font-size: 20px;
  31. font-weight: bold;
  32. margin-bottom: 15px;
  33. }
  34. .info-row {
  35. display: flex;
  36. justify-content: space-between;
  37. font-size: 14px;
  38. margin-bottom: 5px;
  39. }
  40. .seal-line {
  41. position: absolute;
  42. left: -1.5cm;
  43. top: 0;
  44. bottom: 0;
  45. width: 1cm;
  46. border-right: 1px dashed #999;
  47. writing-mode: vertical-rl;
  48. text-align: center;
  49. font-size: 12px;
  50. color: #666;
  51. display: flex;
  52. align-items: center;
  53. justify-content: center;
  54. }
  55. .section-title {
  56. font-size: 16px;
  57. font-weight: bold;
  58. margin-top: 20px;
  59. margin-bottom: 10px;
  60. }
  61. .question {
  62. margin-bottom: 15px;
  63. page-break-inside: avoid;
  64. }
  65. .question-content {
  66. font-size: 14px;
  67. margin-bottom: 8px;
  68. display: flex;
  69. align-items: baseline;
  70. }
  71. .omr-marker {
  72. display: inline-block;
  73. width: 20px;
  74. height: 20px;
  75. border: 1px solid #000;
  76. border-radius: 50%;
  77. margin-right: 10px;
  78. position: relative;
  79. top: 4px;
  80. }
  81. .options {
  82. display: flex;
  83. flex-wrap: wrap;
  84. margin-left: 35px; /* 对齐题目内容 */
  85. }
  86. .option {
  87. width: 25%; /* 四个选项一行 */
  88. font-size: 14px;
  89. }
  90. .fill-line {
  91. display: inline-block;
  92. border-bottom: 1px solid #000;
  93. width: 100px;
  94. text-align: center;
  95. }
  96. .answer-space {
  97. height: 150px; /* 解答题留白 */
  98. border: 1px dashed #eee;
  99. margin-top: 10px;
  100. }
  101. @media print {
  102. .no-print {
  103. display: none;
  104. }
  105. body {
  106. -webkit-print-color-adjust: exact;
  107. }
  108. }
  109. </style>
  110. </head>
  111. <body>
  112. <div class="seal-line">
  113. 装&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;题
  114. </div>
  115. <div class="header">
  116. <div class="school-name">数学智能测试卷</div>
  117. <div class="paper-title">{{ $paper->paper_name ?? '未命名试卷' }}</div>
  118. <div class="info-row">
  119. <span>老师:{{ $teacher['name'] ?? '________' }}</span>
  120. <span>年级:{{ $student['grade'] ?? '________' }}</span>
  121. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  122. <span>得分:________</span>
  123. </div>
  124. </div>
  125. <!-- 一、选择题 -->
  126. <div class="section-title">一、选择题
  127. @if(count($questions['choice']) > 0)
  128. (本大题共 {{ count($questions['choice']) }} 小题,每小题 {{ $questions['choice'][0]->score ?? 5 }} 分,共 {{ count($questions['choice']) * ($questions['choice'][0]->score ?? 5) }} 分)
  129. @else
  130. (本大题共 0 小题,共 0 分)
  131. @endif
  132. </div>
  133. @if(count($questions['choice']) > 0)
  134. @foreach($questions['choice'] as $index => $q)
  135. <div class="question">
  136. <div class="question-content">
  137. <span class="omr-marker"></span>
  138. <span class="font-bold mr-2">{{ $index + 1 }}.</span>
  139. <span>@math($q->content)</span>
  140. </div>
  141. @if(isset($q->options) && !empty($q->options))
  142. <div class="options">
  143. @foreach($q->options as $optIndex => $option)
  144. <div class="option">
  145. {{ chr(65 + $optIndex) }}. {{ $option }}
  146. </div>
  147. @endforeach
  148. </div>
  149. @endif
  150. </div>
  151. @endforeach
  152. @else
  153. <div class="question">
  154. <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
  155. 该题型正在生成中或暂无题目,请稍后刷新页面查看
  156. </div>
  157. </div>
  158. @endif
  159. <!-- 二、填空题 -->
  160. <div class="section-title">二、填空题
  161. @if(count($questions['fill']) > 0)
  162. (本大题共 {{ count($questions['fill']) }} 小题,每小题 {{ $questions['fill'][0]->score ?? 5 }} 分,共 {{ count($questions['fill']) * ($questions['fill'][0]->score ?? 5) }} 分)
  163. @else
  164. (本大题共 0 小题,共 0 分)
  165. @endif
  166. </div>
  167. @if(count($questions['fill']) > 0)
  168. @foreach($questions['fill'] as $index => $q)
  169. <div class="question">
  170. <div class="question-content">
  171. <span class="omr-marker"></span>
  172. <span class="font-bold mr-2">{{ $index + 1 }}.</span>
  173. <span>@math(str_replace('__________', '<span class="fill-line"></span>', $q->content))</span>
  174. </div>
  175. </div>
  176. @endforeach
  177. @else
  178. <div class="question">
  179. <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
  180. 该题型正在生成中或暂无题目,请稍后刷新页面查看
  181. </div>
  182. </div>
  183. @endif
  184. <!-- 三、解答题 -->
  185. <div class="section-title">三、解答题
  186. @if(count($questions['answer']) > 0)
  187. (本大题共 {{ count($questions['answer']) }} 小题,共 {{ array_sum(array_column($questions['answer'], 'score')) }} 分。解答应写出文字说明、证明过程或演算步骤)
  188. @else
  189. (本大题共 0 小题,共 0 分)
  190. @endif
  191. </div>
  192. @if(count($questions['answer']) > 0)
  193. @foreach($questions['answer'] as $index => $q)
  194. <div class="question">
  195. <div class="question-content">
  196. <span class="omr-marker"></span>
  197. <span class="font-bold mr-2">{{ $index + 1 }}.</span>
  198. <span>({{$q->score}}分) @math($q->content)</span>
  199. </div>
  200. <div class="answer-space"></div>
  201. </div>
  202. @endforeach
  203. @else
  204. <div class="question">
  205. <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
  206. 该题型正在生成中或暂无题目,请稍后刷新页面查看
  207. </div>
  208. </div>
  209. @endif
  210. <div class="no-print" style="position: fixed; bottom: 20px; right: 20px;">
  211. <button onclick="window.print()" style="padding: 10px 20px; background: #4163ff; color: white; border: none; border-radius: 5px; cursor: pointer;">打印试卷</button>
  212. </div>
  213. <!-- KaTeX JavaScript 库 -->
  214. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
  215. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
  216. <script>
  217. document.addEventListener('DOMContentLoaded', function() {
  218. console.log('试卷公式渲染器启动');
  219. // 配置 KaTeX 自动渲染
  220. function renderMath() {
  221. try {
  222. renderMathInElement(document.body, {
  223. delimiters: [
  224. {left: '$$', right: '$$', display: true},
  225. {left: '$', right: '$', display: false},
  226. {left: '\\(', right: '\\)', display: false},
  227. {left: '\\[', right: '\\]', display: true}
  228. ],
  229. throwOnError: false,
  230. strict: false,
  231. trust: true,
  232. macros: {
  233. "\\f": "#1f(#2)"
  234. }
  235. });
  236. console.log('数学公式渲染完成');
  237. } catch (e) {
  238. console.warn('公式渲染警告:', e);
  239. }
  240. }
  241. // 页面加载后渲染
  242. renderMath();
  243. // 如果页面是动态加载的,等待一段时间后再次渲染
  244. setTimeout(renderMath, 500);
  245. setTimeout(renderMath, 1000);
  246. // 添加到全局,必要时手动调用
  247. window.renderExamMath = renderMath;
  248. });
  249. </script>
  250. </body>
  251. </html>