|
@@ -1506,10 +1506,18 @@ class ExamPdfExportService
|
|
|
|
|
|
|
|
// 提取head内容(保留原始样式和meta信息)
|
|
// 提取head内容(保留原始样式和meta信息)
|
|
|
$examHead = $this->extractHeadContent($examHtml);
|
|
$examHead = $this->extractHeadContent($examHtml);
|
|
|
|
|
+ $gradingHead = $this->extractHeadContent($gradingHtml);
|
|
|
$kpExplainHead = $kpExplainHtml ? $this->extractHeadContent($kpExplainHtml) : null;
|
|
$kpExplainHead = $kpExplainHtml ? $this->extractHeadContent($kpExplainHtml) : null;
|
|
|
|
|
|
|
|
// 构建统一HTML文档(保留原始结构)
|
|
// 构建统一HTML文档(保留原始结构)
|
|
|
- $unifiedHtml = $this->buildUnifiedHtmlWithOriginalStructure($examHead, $examBody, $gradingBody, $kpExplainBody, $kpExplainHead);
|
|
|
|
|
|
|
+ $unifiedHtml = $this->buildUnifiedHtmlWithOriginalStructure(
|
|
|
|
|
+ $examHead,
|
|
|
|
|
+ $examBody,
|
|
|
|
|
+ $gradingBody,
|
|
|
|
|
+ $gradingHead,
|
|
|
|
|
+ $kpExplainBody,
|
|
|
|
|
+ $kpExplainHead
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
Log::info('HTML合并成功(保留原始样式)', [
|
|
Log::info('HTML合并成功(保留原始样式)', [
|
|
|
'exam_length' => strlen($examBody),
|
|
'exam_length' => strlen($examBody),
|
|
@@ -1596,7 +1604,14 @@ class ExamPdfExportService
|
|
|
* 【优化重构】构建统一的HTML文档(容器结构 + 消除空白页)
|
|
* 【优化重构】构建统一的HTML文档(容器结构 + 消除空白页)
|
|
|
* 使用容器结构替代空的 page-break div,避免中间出现空白页
|
|
* 使用容器结构替代空的 page-break div,避免中间出现空白页
|
|
|
*/
|
|
*/
|
|
|
- private function buildUnifiedHtmlWithOriginalStructure(string $examHead, string $examBody, string $gradingBody, ?string $kpExplainBody = null, ?string $kpExplainHead = null): string
|
|
|
|
|
|
|
+ private function buildUnifiedHtmlWithOriginalStructure(
|
|
|
|
|
+ string $examHead,
|
|
|
|
|
+ string $examBody,
|
|
|
|
|
+ string $gradingBody,
|
|
|
|
|
+ string $gradingHead,
|
|
|
|
|
+ ?string $kpExplainBody = null,
|
|
|
|
|
+ ?string $kpExplainHead = null
|
|
|
|
|
+ ): string
|
|
|
{
|
|
{
|
|
|
// 清洗内容:移除可能存在的分页符,避免双重分页
|
|
// 清洗内容:移除可能存在的分页符,避免双重分页
|
|
|
$examBody = $this->stripPageBreakElements($examBody);
|
|
$examBody = $this->stripPageBreakElements($examBody);
|
|
@@ -1605,15 +1620,16 @@ class ExamPdfExportService
|
|
|
$kpExplainBody = $this->stripPageBreakElements($kpExplainBody);
|
|
$kpExplainBody = $this->stripPageBreakElements($kpExplainBody);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 合并 head 内容:试卷 head + 知识点讲解 head(去重)+ 分页控制样式
|
|
|
|
|
|
|
+ // 合并 head 内容:试卷 head + 判卷 head + 知识点讲解 head(去重)+ 分页控制样式
|
|
|
$mergedHead = $examHead;
|
|
$mergedHead = $examHead;
|
|
|
|
|
|
|
|
- // 如果有知识点讲解 head,合并样式(避免重复)
|
|
|
|
|
- if ($kpExplainHead) {
|
|
|
|
|
- // 提取知识点讲解中的 <style> 内容并追加
|
|
|
|
|
- if (preg_match_all('/<style[^>]*>(.*?)<\/style>/is', $kpExplainHead, $styleMatches)) {
|
|
|
|
|
|
|
+ // 按顺序合并其他 head 里的 <style>(避免重复)
|
|
|
|
|
+ foreach ([$gradingHead, $kpExplainHead] as $extraHead) {
|
|
|
|
|
+ if (! $extraHead) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (preg_match_all('/<style[^>]*>(.*?)<\/style>/is', $extraHead, $styleMatches)) {
|
|
|
foreach ($styleMatches[0] as $idx => $styleTag) {
|
|
foreach ($styleMatches[0] as $idx => $styleTag) {
|
|
|
- // 避免重复添加相同的样式
|
|
|
|
|
if (! str_contains($mergedHead, $styleMatches[1][$idx])) {
|
|
if (! str_contains($mergedHead, $styleMatches[1][$idx])) {
|
|
|
$mergedHead .= "\n ".$styleTag;
|
|
$mergedHead .= "\n ".$styleTag;
|
|
|
}
|
|
}
|