#
Junjie
14 小时以前 d65863817c62bb9c91c5f701121a921ceb97eb7e
#
1个文件已修改
53 ■■■■■ 已修改文件
src/main/webapp/static/js/wrkAnalysis/wrkAnalysis.js 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/wrkAnalysis/wrkAnalysis.js
@@ -316,10 +316,15 @@
                    window.html2canvas(visualRoot, this.buildCaptureOptions(visualRoot)),
                    window.html2canvas(detailRoot, this.buildCaptureOptions(detailRoot))
                ]).then(function (results) {
                    var visualAvoidSplitBounds = self.collectAvoidSplitBounds(visualRoot, results[0], [
                        ".quality-banner",
                        ".chart-card"
                    ]);
                    self.appendCanvasSlicesToPdf(pdf, results[0], {
                        margin: 8,
                        startY: 8,
                        addNewPage: false
                        addNewPage: false,
                        avoidSplitBounds: visualAvoidSplitBounds
                    });
                    self.appendDetailTableToPdf(pdf, results[1], detailRoot, detailTable, 8);
                    pdf.save(self.buildPdfFileName());
@@ -360,6 +365,7 @@
                while (renderedHeight < canvas.height) {
                    var currentPageHeightPx = Math.max(1, Math.floor((pageHeight - margin - currentY) * pxPerMm));
                    var sliceHeight = Math.min(currentPageHeightPx, canvas.height - renderedHeight);
                    sliceHeight = this.resolveSliceHeight(renderedHeight, sliceHeight, settings.avoidSplitBounds);
                    pageCanvas.width = canvas.width;
                    pageCanvas.height = sliceHeight;
                    pageContext.fillStyle = "#ffffff";
@@ -395,6 +401,51 @@
                    currentY = margin;
                }
            },
            collectAvoidSplitBounds: function (rootElement, rootCanvas, selectors) {
                if (!rootElement || !rootCanvas || !selectors || !selectors.length) {
                    return [];
                }
                var rootRect = rootElement.getBoundingClientRect();
                if (!rootRect.width) {
                    return [];
                }
                var scale = rootCanvas.width / rootRect.width;
                var elements = [];
                selectors.forEach(function (selector) {
                    Array.prototype.push.apply(elements, Array.prototype.slice.call(rootElement.querySelectorAll(selector)));
                });
                return elements.map(function (element) {
                    var rect = element.getBoundingClientRect();
                    return {
                        top: Math.max(0, Math.round((rect.top - rootRect.top) * scale)),
                        bottom: Math.max(0, Math.round((rect.bottom - rootRect.top) * scale))
                    };
                }).filter(function (item) {
                    return item.bottom > item.top;
                }).sort(function (a, b) {
                    return a.top - b.top;
                });
            },
            resolveSliceHeight: function (renderedHeight, desiredHeight, avoidSplitBounds) {
                if (!avoidSplitBounds || !avoidSplitBounds.length) {
                    return desiredHeight;
                }
                var sliceEnd = renderedHeight + desiredHeight;
                var adjustedHeight = desiredHeight;
                avoidSplitBounds.forEach(function (bound) {
                    if (bound.top <= renderedHeight) {
                        return;
                    }
                    if (bound.top >= sliceEnd || bound.bottom <= sliceEnd) {
                        return;
                    }
                    var candidateHeight = bound.top - renderedHeight;
                    if (candidateHeight > 0 && candidateHeight < adjustedHeight) {
                        adjustedHeight = candidateHeight;
                    }
                });
                return adjustedHeight > 0 ? adjustedHeight : desiredHeight;
            },
            appendDetailTableToPdf: function (pdf, rootCanvas, detailRoot, detailTable, margin) {
                var tbody = detailTable && detailTable.tBodies && detailTable.tBodies[0];
                var rows = tbody ? Array.prototype.slice.call(tbody.rows) : [];