refactor(contract/export/preview): 优化合同打印导出功能,添加页码和修复样式

1.  移除coilTable的异常行高亮逻辑
2.  修复导航栏告警badge的显示逻辑
3.  为合同导出和预览添加页码标注,调整打印样式
4.  移除冗余的合同打印预览代码
This commit is contained in:
2026-06-10 11:29:41 +08:00
parent cc63aa80b2
commit fd50118161
4 changed files with 51 additions and 196 deletions

View File

@@ -404,7 +404,9 @@ export default {
const printW = pW - mg * 2;
const printH = pH - mg * 2;
const ratio = canvas.width / printW;
const pageCanvasHeight = printH * ratio;
const footerMargin = 8;
const imagePrintH = printH - footerMargin;
const pageCanvasHeight = imagePrintH * ratio;
let currentY = 0;
const pages = [];
@@ -435,17 +437,31 @@ export default {
currentY = pageBottom;
}
const checkedAttachmentCount = this.attachmentConfigs.filter(a => a.checked).length;
const totalPages = pages.length + checkedAttachmentCount;
let pageNum = 0;
const fullPageCanvasHeight = Math.round(printH * ratio);
for (let i = 0; i < pages.length; i++) {
pageNum++;
const { top, bottom } = pages[i];
const sliceH = bottom - top;
const sliceMm = sliceH / ratio;
const sc = document.createElement('canvas');
sc.width = canvas.width;
sc.height = Math.ceil(sliceH);
sc.getContext('2d').drawImage(canvas, 0, top, canvas.width, sliceH, 0, 0, canvas.width, sliceH);
sc.height = fullPageCanvasHeight;
const sctx = sc.getContext('2d');
sctx.fillStyle = '#ffffff';
sctx.fillRect(0, 0, sc.width, sc.height);
sctx.drawImage(canvas, 0, top, canvas.width, sliceH, 0, 0, canvas.width, sliceH);
sctx.fillStyle = '#000000';
sctx.font = 'bold 24px "SimHei","黑体",sans-serif';
sctx.textAlign = 'center';
sctx.textBaseline = 'bottom';
sctx.fillText(`${pageNum} 页,共 ${totalPages}`, sc.width / 2, sc.height - 4);
pdf.addImage(sc.toDataURL('image/jpeg', 0.95), 'JPEG', mg, mg, printW, sliceMm);
pdf.addImage(sc.toDataURL('image/jpeg', 0.95), 'JPEG', mg, mg, printW, printH);
if (i < pages.length - 1) {
pdf.addPage();
@@ -459,22 +475,34 @@ export default {
try {
const img = await this.loadImage(att.url);
pdf.addPage();
pageNum++;
let drawW = img.width;
let drawH = img.height;
const scale = Math.min(printW / drawW, printH / drawH, 1);
drawW *= scale;
drawH *= scale;
const canvasPageW = Math.round(printW * ratio);
const canvasImageH = Math.round(imagePrintH * ratio);
const canvasFooterH = Math.round(footerMargin * ratio);
const canvasTotalH = canvasImageH + canvasFooterH;
const x = mg + (printW - drawW) / 2;
const y = mg + (printH - drawH) / 2;
const attCanvas = document.createElement('canvas');
attCanvas.width = canvasPageW;
attCanvas.height = canvasTotalH;
const actx = attCanvas.getContext('2d');
actx.fillStyle = '#ffffff';
actx.fillRect(0, 0, canvasPageW, canvasTotalH);
const tmpCanvas = document.createElement('canvas');
tmpCanvas.width = img.width;
tmpCanvas.height = img.height;
tmpCanvas.getContext('2d').drawImage(img, 0, 0);
const imgScale = Math.min(canvasPageW / img.width, canvasImageH / img.height, 1);
const imgDrawW = img.width * imgScale;
const imgDrawH = img.height * imgScale;
const imgX = (canvasPageW - imgDrawW) / 2;
const imgY = (canvasImageH - imgDrawH) / 2;
actx.drawImage(img, imgX, imgY, imgDrawW, imgDrawH);
pdf.addImage(tmpCanvas.toDataURL('image/jpeg', 0.95), 'JPEG', x, y, drawW, drawH);
actx.fillStyle = '#000000';
actx.font = 'bold 24px "SimHei","黑体",sans-serif';
actx.textAlign = 'center';
actx.textBaseline = 'bottom';
actx.fillText(`${pageNum} 页,共 ${totalPages}`, canvasPageW / 2, canvasTotalH - 4);
pdf.addImage(attCanvas.toDataURL('image/jpeg', 0.95), 'JPEG', mg, mg, printW, printH);
} catch (e) {
console.error('加载附件图片失败: ' + att.originalName, e);
}