pdf-report-v3.blade.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. @php
  2. $v3 = $v3 ?? [];
  3. $summary = $v3['summary'] ?? [];
  4. $radar = $v3['radar'] ?? [];
  5. $modules = $v3['modules'] ?? [];
  6. $paths = $v3['paths'] ?? ['keep' => [], 'boost' => [], 'key' => []];
  7. $overallPlan = $v3['overall_plan'] ?? [];
  8. $rawPaperId = $paper['id'] ?? $paper['paper_id'] ?? 'unknown';
  9. preg_match('/paper_(\d{15})/', $rawPaperId, $matches);
  10. $reportCode = $matches[1] ?? preg_replace('/[^0-9]/', '', (string) $rawPaperId);
  11. $generateDateTime = now()->format('Y年m月d日 H:i:s');
  12. $scoreObtained = $summary['score_obtained'] ?? null;
  13. $scoreTotal = $summary['score_total'] ?? null;
  14. $scoreRate = $summary['score_rate'] ?? null;
  15. $averageMastery = $summary['average_mastery'] ?? null;
  16. $overallLabel = $summary['overall_label'] ?? '待评估';
  17. $statusColor = function (string $status): string {
  18. return match ($status) {
  19. '良好' => '#16a34a',
  20. '一般' => '#f97316',
  21. '薄弱' => '#e11d48',
  22. default => '#64748b',
  23. };
  24. };
  25. $n = max(1, count($radar));
  26. $cx = 210;
  27. $cy = 155;
  28. $r = 108;
  29. $outer = [];
  30. $inner = [];
  31. for ($i = 0; $i < $n; $i++) {
  32. $angle = -M_PI / 2 + (2 * M_PI * $i / $n);
  33. $ox = $cx + $r * cos($angle);
  34. $oy = $cy + $r * sin($angle);
  35. $outer[] = [$ox, $oy];
  36. $value = isset($radar[$i]['value']) ? (float) $radar[$i]['value'] : 0.0;
  37. $ratio = max(0.0, min(1.0, $value / 5));
  38. $ix = $cx + $r * $ratio * cos($angle);
  39. $iy = $cy + $r * $ratio * sin($angle);
  40. $inner[] = [$ix, $iy];
  41. }
  42. $outerPoints = implode(' ', array_map(fn ($p) => round($p[0], 2).','.round($p[1], 2), $outer));
  43. $innerPoints = implode(' ', array_map(fn ($p) => round($p[0], 2).','.round($p[1], 2), $inner));
  44. $insightMap = [];
  45. foreach (($question_insights ?? []) as $insight) {
  46. $no = $insight['question_number'] ?? $insight['question_id'] ?? null;
  47. if ($no !== null) {
  48. $insightMap[$no] = $insight;
  49. }
  50. }
  51. $analysisWrongMap = [];
  52. foreach (($analysis_data['question_analysis'] ?? []) as $qa) {
  53. $qid = $qa['question_bank_id'] ?? $qa['question_id'] ?? null;
  54. if ($qid === null || $qid === '') {
  55. continue;
  56. }
  57. $rawCorrect = $qa['is_correct'] ?? null;
  58. $isWrongFromAnalysis = false;
  59. if (is_array($rawCorrect)) {
  60. $isWrongFromAnalysis = in_array(0, $rawCorrect, true);
  61. } elseif ($rawCorrect !== null) {
  62. $isWrongFromAnalysis = !boolval($rawCorrect);
  63. }
  64. if ($isWrongFromAnalysis) {
  65. $analysisWrongMap[(string) $qid] = true;
  66. }
  67. }
  68. $wrongQuestions = [];
  69. foreach (($questions ?? []) as $qItem) {
  70. $isCorrectProbe = $qItem['is_correct'] ?? null;
  71. $studentAnswerProbe = $qItem['student_answer'] ?? null;
  72. $correctAnswerProbe = $qItem['answer'] ?? ($qItem['correct_answer'] ?? null);
  73. if ($isCorrectProbe === null && !empty($studentAnswerProbe) && !empty($correctAnswerProbe)) {
  74. $isCorrectProbe = (trim((string) $studentAnswerProbe) === trim((string) $correctAnswerProbe)) ? 1 : 0;
  75. }
  76. $normalizedCorrect = $isCorrectProbe;
  77. if ($isCorrectProbe !== null) {
  78. $normalizedCorrect = is_bool($isCorrectProbe) ? ($isCorrectProbe ? 1 : 0) : intval($isCorrectProbe);
  79. }
  80. $qidProbe = (string) ($qItem['question_bank_id'] ?? $qItem['question_id'] ?? '');
  81. $isWrongByAnalysis = ($qidProbe !== '' && isset($analysisWrongMap[$qidProbe]));
  82. if ($normalizedCorrect === 0 || $isWrongByAnalysis) {
  83. $wrongQuestions[] = $qItem;
  84. }
  85. }
  86. $kpStats = [];
  87. foreach (($questions ?? []) as $qItem) {
  88. $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
  89. $kpName = $kpName === '' ? '未标注知识点' : $kpName;
  90. if (!isset($kpStats[$kpName])) {
  91. $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
  92. }
  93. $kpStats[$kpName]['total']++;
  94. }
  95. foreach ($wrongQuestions as $qItem) {
  96. $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
  97. $kpName = $kpName === '' ? '未标注知识点' : $kpName;
  98. if (!isset($kpStats[$kpName])) {
  99. $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
  100. }
  101. $kpStats[$kpName]['wrong']++;
  102. }
  103. $kpWrongStats = [];
  104. foreach ($kpStats as $kpName => $stat) {
  105. if (($stat['wrong'] ?? 0) <= 0) {
  106. continue;
  107. }
  108. $total = max(1, intval($stat['total'] ?? 0));
  109. $wrong = intval($stat['wrong'] ?? 0);
  110. $kpWrongStats[] = [
  111. 'kp_name' => $kpName,
  112. 'wrong' => $wrong,
  113. 'total' => $total,
  114. 'rate' => $wrong / $total,
  115. ];
  116. }
  117. usort($kpWrongStats, function ($a, $b) {
  118. if ($a['rate'] === $b['rate']) {
  119. return $b['wrong'] <=> $a['wrong'];
  120. }
  121. return $b['rate'] <=> $a['rate'];
  122. });
  123. @endphp
  124. <!DOCTYPE html>
  125. <html lang="zh-CN">
  126. <head>
  127. <meta charset="UTF-8">
  128. <title>学情分析报告</title>
  129. <link rel="stylesheet" href="/css/katex/katex.min.css">
  130. <style>
  131. @page {
  132. size: A4;
  133. margin: 2.2cm 2cm 2.3cm 2cm;
  134. @top-left { content: "知了数学·{{ $generateDateTime }}"; font-size: 13px; color: #666; }
  135. @top-center { content: "{{ $student['name'] ?? '-' }}"; font-size: 13px; color: #666; }
  136. @top-right {
  137. content: "{{ $reportCode }}";
  138. font-size: 19px;
  139. font-weight: 600;
  140. font-family: "Noto Sans", "Liberation Sans", "Nimbus Sans", sans-serif;
  141. color: #222;
  142. }
  143. @bottom-left { content: "{{ $reportCode }}"; font-size: 11px; color: #666; }
  144. @bottom-right { content: counter(page) "/" counter(pages); font-size: 13px; color: #666; }
  145. }
  146. * { box-sizing: border-box; }
  147. body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; margin: 0; color: #0f172a; font-size: 13px; line-height: 1.65; }
  148. .page { page-break-after: auto; }
  149. .header { text-align: left; margin-bottom: 16px; }
  150. .paper-title { font-size: 30px; font-weight: 700; margin-bottom: 8px; color: #0b3a75; letter-spacing: 1px; }
  151. .meta-row { display: flex; justify-content: flex-start; gap: 16px; font-size: 13px; color: #475569; flex-wrap: wrap; }
  152. .section { margin-bottom: 14px; page-break-inside: auto; break-inside: auto; }
  153. .section-title { font-size: 20px; margin-bottom: 10px; font-weight: 700; color: #0b3a75; border-left: 5px solid #3b82f6; padding-left: 10px; line-height: 1.3; }
  154. .card { border: 1px solid #dbeafe; border-radius: 12px; padding: 14px; background: #f8fbff; }
  155. .summary-list { margin: 0; padding-left: 18px; }
  156. .summary-list li { margin: 6px 0; font-size: 13px; }
  157. .radar-center { text-align: center; }
  158. .legend { margin-top: 8px; font-size: 12px; color: #475569; }
  159. .legend span { margin: 0 8px; }
  160. .dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-right: 4px; vertical-align: middle; }
  161. /* PDF 版优先上下结构,避免左右分栏导致拥挤 */
  162. .radar-split { display: block; width: 100%; }
  163. .radar-left { width: 100%; text-align: center; }
  164. .radar-right { width: 100%; padding-left: 0; margin-top: 10px; }
  165. .radar-desc { border: 1px solid #dbeafe; background: #f8fbff; border-radius: 12px; padding: 12px; text-align: left; }
  166. .radar-item { display: block; margin: 6px 0; font-size: 12px; }
  167. .kp-burst-card { margin-top: 10px; border: 1px solid #dbeafe; border-radius: 12px; padding: 10px; background: #fff; }
  168. .kp-burst-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; color: #0b3a75; }
  169. .kp-burst-meta { font-size: 12px; color: #334155; margin-top: 6px; line-height: 1.6; }
  170. .kp-burst-list { margin-top: 6px; font-size: 11px; color: #334155; line-height: 1.5; }
  171. .kp-burst-list span { display: inline-block; margin-right: 10px; margin-bottom: 3px; }
  172. table { width: 100%; border-collapse: collapse; font-size: 12px; background: #fff; }
  173. th, td { border: 1px solid #d0d7e2; padding: 8px 10px; text-align: left; vertical-align: top; }
  174. th { background: #f1f5f9; color: #1e293b; font-weight: 700; }
  175. .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; color: #fff; font-size: 11px; font-weight: 600; }
  176. .path-stack { display: block; }
  177. .path-box { border: 1px solid #e5e7eb; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
  178. .path-box.keep { background: #f0fdf4; border-color: #86efac; }
  179. .path-box.boost { background: #fff7ed; border-color: #fdba74; }
  180. .path-box.key { background: #fff1f2; border-color: #fda4af; }
  181. .path-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; color: #111827; }
  182. .path-box ul { margin: 0; padding-left: 16px; }
  183. .path-box li { font-size: 13px; margin: 2px 0; }
  184. .plan { background: #eef4ff; border-left: 4px solid #3b82f6; border-radius: 12px; padding: 12px 14px; }
  185. .plan ol { margin: 0; padding-left: 18px; }
  186. .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; color: #334155; background: #e5e7eb; }
  187. .error-kp-tag { display: inline-block; margin: 0 6px 6px 0; padding: 1px 7px; border-radius: 999px; font-size: 10px; color: #334155; background: #f8fafc; border: 1px solid #d1d5db; }
  188. .error-kp-tag.high-risk { color: #b91c1c; border-color: #fca5a5; background: #fff; font-weight: 600; }
  189. .question-card { border:1px solid #e5e7eb; border-radius:8px; padding:6px 9px; margin-bottom:5px; background:#fff; page-break-inside:auto; break-inside:auto; }
  190. .question-block { margin-bottom: 5px; padding: 5px; border-radius: 4px; page-break-inside: auto; break-inside: auto; }
  191. .question-card,
  192. .question-card .math-content,
  193. .question-card .solution-content { font-size: 12px; line-height: 1.7; }
  194. .question-card .question-stem svg,
  195. .question-card .math-content svg { max-width: 100%; height: auto; display: block; shape-rendering: geometricPrecision; text-rendering: geometricPrecision; }
  196. .question-card .question-stem svg text {
  197. font-family: "Noto Serif", "Noto Serif CJK SC", "Noto Sans CJK SC", "Noto Sans", "STSongti-SC", "PingFang SC", "Songti SC", serif !important;
  198. font-size: 13px !important;
  199. font-weight: bold;
  200. dominant-baseline: middle;
  201. text-anchor: middle;
  202. }
  203. .question-card .question-stem svg circle,
  204. .question-card .question-stem svg line,
  205. .question-card .question-stem svg polygon,
  206. .question-card .question-stem svg polyline { shape-rendering: geometricPrecision; }
  207. .question-card .question-stem img,
  208. .question-card .question-main img {
  209. display: block;
  210. max-width: 220px;
  211. max-height: 60mm;
  212. width: auto;
  213. height: auto;
  214. margin: 6px auto;
  215. box-sizing: border-box;
  216. object-fit: contain;
  217. -webkit-print-color-adjust: exact;
  218. print-color-adjust: exact;
  219. image-rendering: -webkit-optimize-contrast;
  220. }
  221. .question-card .question-stem .katex { font-size: 1em !important; vertical-align: 0; }
  222. .question-card .question-stem .katex-display { margin: 0.35em 0 !important; }
  223. .question-card .solution-content img,
  224. .question-card .report-answer-meta img {
  225. display: block;
  226. max-width: 220px;
  227. max-height: 60mm;
  228. width: auto;
  229. height: auto;
  230. margin: 6px auto;
  231. object-fit: contain;
  232. -webkit-print-color-adjust: exact;
  233. print-color-adjust: exact;
  234. }
  235. .solution-content {
  236. display: block;
  237. line-height: 1.75;
  238. white-space: normal;
  239. word-break: break-word;
  240. overflow-wrap: anywhere;
  241. page-break-inside: auto;
  242. break-inside: auto;
  243. }
  244. .report-options { margin-top: 6px; page-break-inside: auto; break-inside: auto; }
  245. .report-options.options-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 12px; }
  246. .report-options.options-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; }
  247. .report-options.options-grid-1 { display: grid; grid-template-columns: 1fr; gap: 8px; }
  248. .report-options .option { display: flex; align-items: baseline; font-size: 12px; line-height: 1.6; page-break-inside: auto; break-inside: auto; }
  249. .report-options .option strong { margin-right: 4px; flex: 0 0 auto; }
  250. .report-options .option-value.option-short { white-space: nowrap; }
  251. .report-options .option-value.option-long { white-space: normal; word-break: break-word; }
  252. .report-options .option p, .report-options .option div { margin: 0; display: inline; }
  253. .report-options .option img { max-width: 100%; height: auto; vertical-align: middle; }
  254. .report-answer-meta { font-size: 12px; color: #2f2f2f; line-height: 1.75; margin-top: 6px; page-break-inside: auto; break-inside: auto; }
  255. .report-answer-meta .answer-line + .answer-line { margin-top: 4px; }
  256. .report-answer-meta .solution-content { display: inline; line-height: 1.75; }
  257. .muted { color: #6b7280; font-size: 12px; }
  258. </style>
  259. </head>
  260. <body>
  261. <div class="page">
  262. <div class="header">
  263. <h1 class="paper-title">学情分析报告</h1>
  264. <div class="meta-row">
  265. <span>学生姓名:{{ $student['name'] ?? '未知' }}</span>
  266. <span>报告日期:{{ now()->format('Y年n月j日') }}</span>
  267. </div>
  268. </div>
  269. <div class="section">
  270. <div class="section-title">一、总体评估</div>
  271. <div class="card">
  272. <ul class="summary-list">
  273. <li>本次诊断得分:
  274. @if($scoreObtained !== null && $scoreTotal !== null && $scoreTotal > 0)
  275. {{ rtrim(rtrim(number_format((float) $scoreObtained, 1), '0'), '.') }}/{{ rtrim(rtrim(number_format((float) $scoreTotal, 1), '0'), '.') }}
  276. @else
  277. 暂无得分数据
  278. @endif
  279. </li>
  280. <li>得分率:{{ $scoreRate !== null ? number_format((float) $scoreRate * 100, 1) . '%' : '暂无得分率' }}</li>
  281. <li>平均掌握度:{{ $averageMastery !== null ? number_format((float) $averageMastery * 100, 1) . '%' : '暂无掌握度' }}</li>
  282. <li>整体水平:{{ $overallLabel }}</li>
  283. </ul>
  284. </div>
  285. </div>
  286. <div class="section">
  287. <div class="section-title">二、知识点掌握雷达图</div>
  288. <div class="radar-split">
  289. <div class="radar-left">
  290. <svg width="430" height="320" viewBox="0 0 430 320">
  291. <polygon points="{{ $outerPoints }}" fill="#f8fafc" stroke="#cbd5e1" stroke-width="1"/>
  292. <polygon points="{{ $innerPoints }}" fill="rgba(59,130,246,0.28)" stroke="#3b82f6" stroke-width="2"/>
  293. @foreach($outer as $i => $p)
  294. <line x1="{{ $cx }}" y1="{{ $cy }}" x2="{{ round($p[0],2) }}" y2="{{ round($p[1],2) }}" stroke="#e2e8f0" stroke-width="1"/>
  295. @endforeach
  296. @foreach($outer as $i => $p)
  297. @php
  298. $name = $radar[$i]['name'] ?? '';
  299. $children = $radar[$i]['children'] ?? [];
  300. $labelX = $p[0] + (($p[0] >= $cx) ? 9 : -9);
  301. $labelY = $p[1] + (($p[1] >= $cy) ? 12 : -8);
  302. $anchor = $p[0] >= $cx ? 'start' : 'end';
  303. $dotColor = $statusColor((string) ($radar[$i]['status'] ?? '暂无'));
  304. $value = number_format((float) ($radar[$i]['value'] ?? 0), 2);
  305. $axisAngle = atan2(($p[1] - $cy), ($p[0] - $cx));
  306. @endphp
  307. <text x="{{ round($labelX,2) }}" y="{{ round($labelY,2) }}" font-size="11" fill="#334155" text-anchor="{{ $anchor }}">{{ $name }} {{ $value }}</text>
  308. <circle cx="{{ round($inner[$i][0],2) }}" cy="{{ round($inner[$i][1],2) }}" r="4" fill="{{ $dotColor }}" />
  309. @if(!empty($children))
  310. @foreach($children as $cIdx => $child)
  311. @php
  312. $childN = max(1, count($children));
  313. $depth = max(1, intval($child['depth'] ?? 1));
  314. $offset = ($cIdx - (($childN - 1) / 2)) * 0.04;
  315. $childAngle = $axisAngle + $offset;
  316. // 子知识点必须从父轴外圈向外发散,避免父轴值低时挤在中心
  317. $axisOuterR = sqrt(pow(($outer[$i][0] - $cx), 2) + pow(($outer[$i][1] - $cy), 2));
  318. $startR = max($axisOuterR + 4, 112 + (($depth - 1) * 10));
  319. $endR = $startR + 12 + (($depth - 1) * 4);
  320. $sx = $cx + $startR * cos($childAngle);
  321. $sy = $cy + $startR * sin($childAngle);
  322. $ex = $cx + $endR * cos($childAngle);
  323. $ey = $cy + $endR * sin($childAngle);
  324. $changed = !empty($child['changed']);
  325. $cColor = $changed ? '#e11d48' : '#94a3b8';
  326. $cWidth = $changed ? 1.5 : 0.8;
  327. $masteryPct = isset($child['mastery_level']) ? max(0, min(100, (float) $child['mastery_level'] * 100)) : null;
  328. $label = $masteryPct !== null ? number_format($masteryPct, 1) . '%' : '—';
  329. $tx = $cx + ($endR + 5 + (($depth - 1) * 2)) * cos($childAngle);
  330. $ty = $cy + ($endR + 5 + (($depth - 1) * 2)) * sin($childAngle);
  331. $anchor = cos($childAngle) >= 0 ? 'start' : 'end';
  332. @endphp
  333. <line x1="{{ round($sx,2) }}" y1="{{ round($sy,2) }}" x2="{{ round($ex,2) }}" y2="{{ round($ey,2) }}"
  334. stroke="{{ $cColor }}" stroke-width="{{ $cWidth }}" opacity="{{ $changed ? 0.95 : 0.85 }}"/>
  335. <circle cx="{{ round($ex,2) }}" cy="{{ round($ey,2) }}" r="{{ $changed ? 1.6 : 1.0 }}" fill="{{ $cColor }}" />
  336. <text x="{{ round($tx,2) }}" y="{{ round($ty,2) }}" font-size="9" fill="{{ $cColor }}" text-anchor="{{ $anchor }}">{{ $label }}</text>
  337. @endforeach
  338. @endif
  339. @endforeach
  340. </svg>
  341. <div class="legend">
  342. <span><i class="dot" style="background:#16a34a"></i>良好(4.0-5.0)</span>
  343. <span><i class="dot" style="background:#f97316"></i>一般(2.0-3.9)</span>
  344. <span><i class="dot" style="background:#e11d48"></i>薄弱(0-1.9)</span>
  345. <span><i class="dot" style="background:#64748b"></i>未涉及</span>
  346. <span><i class="dot" style="background:#94a3b8"></i>子知识点</span>
  347. <span><i class="dot" style="background:#e11d48"></i>子知识点变化</span>
  348. <span>外圈越远表示层级越深</span>
  349. </div>
  350. </div>
  351. <div class="radar-right">
  352. <div class="radar-desc">
  353. <strong>雷达图解读</strong>
  354. @foreach($radar as $item)
  355. @php $color = $statusColor((string) ($item['status'] ?? '暂无')); @endphp
  356. <span class="radar-item">
  357. <i class="dot" style="background:{{ $color }}"></i>
  358. {{ $item['name'] }}:{{ $item['status'] }}
  359. ({{ !empty($item['has_mastery']) ? number_format((float) ($item['value'] ?? 0), 2) . '/5' : '—' }})
  360. @if(!empty($item['children']))
  361. ,子知识点 {{ count($item['children']) }} 个
  362. @endif
  363. </span>
  364. @endforeach
  365. </div>
  366. </div>
  367. </div>
  368. </div>
  369. <div class="section">
  370. <div class="section-title">三、模块能力分析表</div>
  371. <table>
  372. <thead>
  373. <tr>
  374. <th style="width: 16%;">模块</th>
  375. <th style="width: 13%;">掌握分值</th>
  376. <th style="width: 12%;">掌握状态</th>
  377. <th style="width: 10%;">样本数</th>
  378. <th style="width: 12%;">得分率</th>
  379. <th>学生当前能力</th>
  380. </tr>
  381. </thead>
  382. <tbody>
  383. @foreach($modules as $m)
  384. @php
  385. $status = (string) ($m['status'] ?? '暂无');
  386. $color = $statusColor($status);
  387. $rate = $m['exam_score_rate'] ?? null;
  388. @endphp
  389. <tr>
  390. <td>{{ $m['module_name'] ?? '-' }}</td>
  391. <td>{{ $m['mastery_score_5'] !== null ? number_format((float) $m['mastery_score_5'], 2) . '/5' : '-' }}</td>
  392. <td><span class="badge" style="background:{{ $color }}">{{ $status }}</span></td>
  393. <td>{{ $m['kp_count'] ?? 0 }}</td>
  394. <td>{{ $rate !== null ? number_format((float) $rate * 100, 1) . '%' : '-' }}</td>
  395. <td>{{ $m['ability_text'] ?? '-' }}</td>
  396. </tr>
  397. @endforeach
  398. </tbody>
  399. </table>
  400. </div>
  401. <div class="section">
  402. <div class="section-title">四、分模块提分路径</div>
  403. <div class="path-stack">
  404. <div class="path-box keep">
  405. <div class="path-title">保分模块(保持优势)</div>
  406. <ul>
  407. @foreach(($paths['keep'] ?? []) as $item)
  408. <li>{{ $item['name'] }}:掌握度 {{ number_format((float) ($item['mastery_level'] ?? 0) * 100, 1) }}%</li>
  409. @endforeach
  410. </ul>
  411. @if(empty($paths['keep']))
  412. <div class="muted">暂无数据</div>
  413. @endif
  414. </div>
  415. <div class="path-box boost">
  416. <div class="path-title">涨分模块(重点突破)</div>
  417. <ul>
  418. @foreach(($paths['boost'] ?? []) as $item)
  419. <li>{{ $item['name'] }}:掌握度 {{ number_format((float) ($item['mastery_level'] ?? 0) * 100, 1) }}%</li>
  420. @endforeach
  421. </ul>
  422. @if(empty($paths['boost']))
  423. <div class="muted">暂无数据</div>
  424. @endif
  425. </div>
  426. <div class="path-box key">
  427. <div class="path-title">提分关键(优先补短)</div>
  428. <ul>
  429. @foreach(($paths['key'] ?? []) as $item)
  430. <li>{{ $item['name'] }}:掌握度 {{ number_format((float) ($item['mastery_level'] ?? 0) * 100, 1) }}%</li>
  431. @endforeach
  432. </ul>
  433. @if(empty($paths['key']))
  434. <div class="muted">暂无数据</div>
  435. @endif
  436. </div>
  437. </div>
  438. </div>
  439. <div class="section">
  440. <div class="section-title">五、整体提升方案</div>
  441. <div class="plan">
  442. <ol>
  443. @foreach($overallPlan as $line)
  444. <li>{{ $line }}</li>
  445. @endforeach
  446. </ol>
  447. </div>
  448. </div>
  449. @if(!empty($wrongQuestions))
  450. <div class="section" style="page-break-inside:auto; break-inside:auto;">
  451. <div class="section-title">六、这次错题记录</div>
  452. @if(!empty($kpWrongStats))
  453. <div style="margin-bottom:8px; padding:8px; border:1px solid #e5e7eb; border-radius:6px; background:#f8fafc;">
  454. <div style="font-size:12px; font-weight:600; margin-bottom:6px;">知识点错误率</div>
  455. <div style="font-size:12px; color:#475569; line-height:1.7;">
  456. @foreach($kpWrongStats as $item)
  457. <span class="error-kp-tag {{ $item['rate'] > 0.5 ? 'high-risk' : '' }}">{{ $item['kp_name'] }}:{{ $item['wrong'] }}/{{ $item['total'] }}({{ number_format($item['rate'] * 100, 1) }}%)</span>
  458. @endforeach
  459. </div>
  460. </div>
  461. @endif
  462. @foreach($wrongQuestions as $q)
  463. @php
  464. $studentAnswer = $q['student_answer'] ?? null;
  465. $correctAnswer = $q['answer'] ?? $q['correct_answer'] ?? null;
  466. $isCorrect = $q['is_correct'] ?? null;
  467. if ($isCorrect === null && !empty($studentAnswer) && !empty($correctAnswer)) {
  468. $isCorrect = (trim($studentAnswer) === trim($correctAnswer)) ? 1 : 0;
  469. }
  470. $statusText = '';
  471. $statusColorValue = '';
  472. if ($isCorrect === 1) {
  473. $statusText = '正确';
  474. $statusColorValue = '#10b981';
  475. } elseif ($isCorrect === 0) {
  476. $statusText = '错误';
  477. $statusColorValue = '#ef4444';
  478. }
  479. $showStatus = $statusText !== '';
  480. $insight = $insightMap[$q['question_number']] ?? ($insightMap[$q['display_number'] ?? null] ?? []);
  481. $fullScore = $insight['full_score'] ?? ($q['score'] ?? null);
  482. if ($isCorrect === 1) {
  483. $score = $fullScore;
  484. } elseif ($isCorrect === 0) {
  485. $score = $q['score_obtained'] ?? 0;
  486. } else {
  487. $score = null;
  488. }
  489. $analysisRaw = $insight['analysis']
  490. ?? $insight['thinking_process']
  491. ?? $insight['feedback']
  492. ?? $insight['suggestions']
  493. ?? $insight['reason']
  494. ?? ($insight['correct_solution'] ?? null);
  495. if (empty($analysisRaw) && !empty($insight['next_steps'])) {
  496. $analysisRaw = '后续建议:' . (is_array($insight['next_steps']) ? implode(';', $insight['next_steps']) : $insight['next_steps']);
  497. }
  498. $analysis = is_array($analysisRaw) ? json_encode($analysisRaw, JSON_UNESCAPED_UNICODE) : $analysisRaw;
  499. if ($analysis === null || $analysis === '') {
  500. $analysis = '暂无解题思路,待补充';
  501. }
  502. if (is_string($analysis)) {
  503. $analysis = preg_replace('/^【?\s*解题思路\s*】?\s*[::]?\s*/u', '', $analysis);
  504. }
  505. $formatSolutionLikeGrading = function ($text) {
  506. if (!is_string($text) || trim($text) === '') {
  507. return $text;
  508. }
  509. $normalized = preg_replace('/\s*;\s*步骤\s*(\d+)/u', ";\n步骤$1", $text);
  510. $normalized = preg_replace('/\s*。\s*步骤\s*(\d+)/u', "。\n步骤$1", $normalized);
  511. $normalized = preg_replace('/(?<!^)(步骤\s*\d+\s*[::])/u', "\n$1", $normalized);
  512. $normalized = preg_replace('/(?<!^)(第\s*\d+\s*步\s*[::]?)/u', "\n$1", $normalized);
  513. $normalized = preg_replace('/\n{3,}/u', "\n\n", $normalized);
  514. $normalized = preg_replace('/^[\h\x{3000}]+/mu', '', $normalized);
  515. return trim($normalized);
  516. };
  517. $stepsRaw = $insight['steps'] ?? $insight['solution_steps'] ?? $insight['analysis_steps'] ?? null;
  518. $steps = [];
  519. if (is_array($stepsRaw)) {
  520. $steps = $stepsRaw;
  521. } elseif (is_string($stepsRaw) && trim($stepsRaw) !== '') {
  522. $steps = preg_split('/[\r\n]+/', trim($stepsRaw));
  523. }
  524. $typeMap = ['choice' => '选择题', 'fill' => '填空题', 'answer' => '解答题'];
  525. $typeLabel = $typeMap[$q['question_type'] ?? ''] ?? ($q['question_type'] ?? '题型未标注');
  526. $questionText = is_string($q['question_text']) ? $q['question_text'] : json_encode($q['question_text'], JSON_UNESCAPED_UNICODE);
  527. $solution = $q['solution'] ?? null;
  528. if (is_string($solution)) {
  529. $solution = preg_replace('/^【?\s*解题思路\s*】?\s*[::]?\s*/u', '', $solution);
  530. }
  531. $solution = $formatSolutionLikeGrading($solution);
  532. $analysis = $formatSolutionLikeGrading($analysis);
  533. $renderLikeGrading = function ($text) {
  534. if (is_array($text)) {
  535. $text = json_encode($text, JSON_UNESCAPED_UNICODE);
  536. }
  537. $text = is_string($text) ? trim($text) : '';
  538. if ($text === '') {
  539. return '';
  540. }
  541. // 兼容题库里常见的转义写法:\$x\$、\$\frac{...}\$
  542. $text = preg_replace('/\\\\\\$/u', '$', $text);
  543. return \App\Services\MathFormulaProcessor::processFormulas($text);
  544. };
  545. $questionTextRendered = $renderLikeGrading($questionText);
  546. $displayCorrectAnswer = is_array($correctAnswer) ? json_encode($correctAnswer, JSON_UNESCAPED_UNICODE) : (string) $correctAnswer;
  547. $questionTypeRaw = strtolower(trim((string) ($q['question_type'] ?? '')));
  548. $isChoiceQuestion = in_array($questionTypeRaw, ['choice', 'multiple_choice', 'single_choice', '选择题', 'select'], true);
  549. $normalizedOptions = [];
  550. $correctAnswerLetters = [];
  551. if ($isChoiceQuestion) {
  552. $rawOptions = $q['options'] ?? [];
  553. if (is_string($rawOptions)) {
  554. $decodedOptions = json_decode($rawOptions, true);
  555. $rawOptions = is_array($decodedOptions) ? $decodedOptions : [];
  556. }
  557. if (is_array($rawOptions)) {
  558. foreach ($rawOptions as $optKey => $optValue) {
  559. $letter = null;
  560. if (is_string($optKey) && preg_match('/([A-H])/i', $optKey, $m)) {
  561. $letter = strtoupper($m[1]);
  562. } elseif (is_array($optValue)) {
  563. $candidate = $optValue['label'] ?? $optValue['key'] ?? $optValue['option'] ?? null;
  564. if (is_string($candidate) && preg_match('/([A-H])/i', $candidate, $m)) {
  565. $letter = strtoupper($m[1]);
  566. }
  567. }
  568. if ($letter === null) {
  569. continue;
  570. }
  571. $content = is_array($optValue) ? ($optValue['content'] ?? $optValue['text'] ?? $optValue['value'] ?? '') : $optValue;
  572. if (!is_string($content)) {
  573. $content = json_encode($content, JSON_UNESCAPED_UNICODE);
  574. }
  575. $content = trim((string) $content);
  576. if ($content !== '') {
  577. $normalizedOptions[$letter] = $content;
  578. }
  579. }
  580. }
  581. if (trim((string) $correctAnswer) !== '') {
  582. preg_match_all('/[A-H]/i', strtoupper((string) $correctAnswer), $answerMatches);
  583. $correctAnswerLetters = array_values(array_unique($answerMatches[0] ?? []));
  584. }
  585. if (!empty($normalizedOptions) && !empty($correctAnswerLetters)) {
  586. $mappedAnswers = [];
  587. foreach ($correctAnswerLetters as $letter) {
  588. if (isset($normalizedOptions[$letter])) {
  589. $mappedAnswers[] = $letter . '. ' . $normalizedOptions[$letter];
  590. }
  591. }
  592. if (!empty($mappedAnswers)) {
  593. $displayCorrectAnswer = implode(';', $mappedAnswers);
  594. }
  595. }
  596. }
  597. $choiceOptionLetters = !empty($normalizedOptions) ? array_keys($normalizedOptions) : [];
  598. sort($choiceOptionLetters);
  599. $choiceLayoutClass = 'options-grid-1';
  600. $layoutDecider = app(\App\Support\OptionLayoutDecider::class);
  601. if (! empty($normalizedOptions) && ! empty($choiceOptionLetters)) {
  602. $optValuesForLayout = [];
  603. foreach ($choiceOptionLetters as $L) {
  604. $optValuesForLayout[] = $normalizedOptions[$L];
  605. }
  606. $layoutMeta = $layoutDecider->decide($optValuesForLayout, 'grading');
  607. $choiceLayoutClass = $layoutMeta['class'] ?? 'options-grid-1';
  608. }
  609. @endphp
  610. <div class="question-card">
  611. <div style="display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:4px;">
  612. <div style="display:flex; align-items:center; gap:8px; font-weight:600;">
  613. <span class="tag">题号 {{ $q['display_number'] ?? $q['question_number'] }} · {{ $typeLabel }}</span>
  614. @php
  615. $kpName = $q['knowledge_point_name'] ?? $q['knowledge_point'] ?? null;
  616. if (!empty($kpName) && $kpName !== '-' && $kpName !== '未标注') {
  617. echo '<span class="tag" style="background: #eef2ff; color:#4338ca;">' . e($kpName) . '</span>';
  618. }
  619. @endphp
  620. @if($showStatus)
  621. <span class="tag" style="background: {{ $statusColorValue }}; color:#fff;">{{ $statusText }}</span>
  622. @endif
  623. </div>
  624. @if($score !== null && $fullScore !== null)
  625. <div class="muted">得分 {{ $score }} / {{ $fullScore }}</div>
  626. @endif
  627. </div>
  628. <div class="question-stem math-content" style="margin-bottom:6px;">{!! $questionTextRendered !!}</div>
  629. @if(!empty($isChoiceQuestion) && !empty($normalizedOptions))
  630. <div class="report-options {{ $choiceLayoutClass }}">
  631. @foreach($choiceOptionLetters as $optLetter)
  632. @php
  633. $isCorrectOpt = in_array($optLetter, $correctAnswerLetters ?? [], true);
  634. $rawOpt = (string) ($normalizedOptions[$optLetter] ?? '');
  635. $normalizedOpt = str_replace('\\dfrac', '\\frac', $rawOpt);
  636. $normalizedOpt = str_replace('\\displaystyle', '', $normalizedOpt);
  637. $normalizedOpt = $layoutDecider->normalizeCompactMathForDisplay($normalizedOpt);
  638. $rawOptPlain = html_entity_decode(strip_tags($rawOpt), ENT_QUOTES | ENT_HTML5, 'UTF-8');
  639. $rawOptPlain = preg_replace('/\s+/u', '', $rawOptPlain ?? '');
  640. $isShortOption = mb_strlen((string) $rawOptPlain, 'UTF-8') <= 8;
  641. $valClass = $isShortOption ? 'option-short' : 'option-long';
  642. $renderedOpt = $renderLikeGrading($normalizedOpt);
  643. @endphp
  644. <div class="option option-compact">
  645. <strong>{{ $optLetter }}.</strong>
  646. <span class="option-value {{ $valClass }}">{!! $renderedOpt !!}</span>
  647. @if($isCorrectOpt)
  648. <span style="margin-left:4px; font-size:13px; color:#15803d; font-weight:700;">✅</span>
  649. @endif
  650. </div>
  651. @endforeach
  652. </div>
  653. @endif
  654. @if(!empty($correctAnswer) && (!$isChoiceQuestion || empty($normalizedOptions)))
  655. <div class="question-block" style="background:#f0fdf4; border-left:3px solid #10b981;">
  656. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:3px;">正确答案</div>
  657. <div class="math-content" style="line-height:1.7; color:#374151;">
  658. {!! $renderLikeGrading($displayCorrectAnswer) !!}
  659. </div>
  660. </div>
  661. @endif
  662. @if(!empty($solution))
  663. <div class="report-answer-meta">
  664. <div class="answer-line">
  665. <strong>解题思路:</strong>
  666. <span class="solution-content">{!! $renderLikeGrading($solution) !!}</span>
  667. </div>
  668. </div>
  669. @elseif(!empty($analysis) && $analysis !== '暂无解题思路记录')
  670. <div class="report-answer-meta">
  671. <div class="answer-line">
  672. <strong>解题思路:</strong>
  673. <span class="solution-content">{!! $renderLikeGrading($analysis) !!}</span>
  674. </div>
  675. </div>
  676. @endif
  677. @if(!empty($steps))
  678. <div style="margin-top:6px; font-size:12px;">
  679. <div style="font-weight:600; margin-bottom:3px;">解题步骤</div>
  680. <ol style="margin:0; padding-left:18px;">
  681. @foreach($steps as $s)
  682. @php
  683. $stepText = is_array($s) ? json_encode($s, JSON_UNESCAPED_UNICODE) : (string) $s;
  684. @endphp
  685. <li style="margin-bottom:2px;">{!! nl2br($renderLikeGrading($stepText)) !!}</li>
  686. @endforeach
  687. </ol>
  688. </div>
  689. @endif
  690. </div>
  691. @endforeach
  692. </div>
  693. @endif
  694. </div>
  695. <script src="/js/katex.min.js"></script>
  696. <script src="/js/auto-render.min.js"></script>
  697. <script>
  698. document.addEventListener('DOMContentLoaded', function() {
  699. try {
  700. renderMathInElement(document.body, {
  701. delimiters: [
  702. {left: "$$", right: "$$", display: true},
  703. {left: "$", right: "$", display: false},
  704. {left: "\\(", right: "\\)", display: false},
  705. {left: "\\[", right: "\\]", display: true}
  706. ],
  707. throwOnError: false,
  708. strict: false,
  709. trust: true
  710. });
  711. } catch (e) {}
  712. });
  713. </script>
  714. </body>
  715. </html>