diff --git a/public/static/css/phone-image-templates.css b/public/static/css/phone-image-templates.css index 89e1aa5..8512105 100644 --- a/public/static/css/phone-image-templates.css +++ b/public/static/css/phone-image-templates.css @@ -591,3 +591,9 @@ border: none; padding: 0; } + +/* 中间栏表格样式 */ +.content-flow-block table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; } +.content-flow-block th { background-color: #f0f0f0; font-weight: bold; padding: 8px 10px; border: 1px solid #ddd; text-align: left; } +.content-flow-block td { padding: 8px 10px; border: 1px solid #ddd; } +.content-flow-block tr:nth-child(even) td { background-color: #f9f9f9; } diff --git a/public/static/js/phone-image.js b/public/static/js/phone-image.js index fa49425..a9a97f9 100644 --- a/public/static/js/phone-image.js +++ b/public/static/js/phone-image.js @@ -691,23 +691,14 @@ var PhoneImageEngine = (function () { Prism.highlightElement(this); }); - // 找到所有代码块,逐个截图替换 - var $preBlocks = $staging.find('pre'); - if ($preBlocks.length === 0) { - deferred.resolve(); - return deferred.promise(); - } - - var idx = 0; - var total = $preBlocks.length; - + // 逐个截图替换,每次重新查找避免 replaceWith 后索引失效 function convertNext() { - if (idx >= total) { + var $pre = $staging.find('pre').first(); + if ($pre.length === 0) { deferred.resolve(); return; } - var $pre = $preBlocks.eq(idx); html2canvas($pre[0], { scale: 2, useCORS: true, @@ -724,11 +715,10 @@ var PhoneImageEngine = (function () { margin: '10px 0' }); $pre.replaceWith($img); - idx++; convertNext(); }).catch(function () { - // 截图失败则保留原始代码块 - idx++; + // 截图失败则跳过当前元素继续处理下一个 + $pre.remove(); convertNext(); }); } @@ -746,22 +736,14 @@ var PhoneImageEngine = (function () { var deferred = $.Deferred(); var $staging = $('#render-staging'); - var $tables = $staging.find('.page-content table'); - if ($tables.length === 0) { - deferred.resolve(); - return deferred.promise(); - } - - var idx = 0; - var total = $tables.length; - + // 逐个截图替换,每次重新查找避免 replaceWith 后索引失效 function convertNext() { - if (idx >= total) { + var $table = $staging.find('.page-content table').first(); + if ($table.length === 0) { deferred.resolve(); return; } - var $table = $tables.eq(idx); html2canvas($table[0], { scale: 2, useCORS: true, @@ -778,10 +760,10 @@ var PhoneImageEngine = (function () { margin: '10px 0' }); $table.replaceWith($img); - idx++; convertNext(); }).catch(function () { - idx++; + // 截图失败则跳过当前元素继续处理下一个 + $table.remove(); convertNext(); }); } diff --git a/view/admin/post/phone_image.html b/view/admin/post/phone_image.html index df366ef..f16b420 100644 --- a/view/admin/post/phone_image.html +++ b/view/admin/post/phone_image.html @@ -144,6 +144,8 @@