From b0b0dad3047362b7ee8696fc51eb47515016c78a Mon Sep 17 00:00:00 2001 From: baiqi Date: Tue, 24 Sep 2024 14:15:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=AF=BC=E5=87=BA):=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E6=8A=A5=E5=91=8A=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1047049 --user=白奇 【测试计划】计划-编辑修改报告总结内容-导出自定义的报告失败 https://www.tapd.cn/55049933/s/1584661 --- .../pure/ms-rich-text/MsRichText.vue | 4 +-- frontend/src/hooks/useExportPDF.ts | 2 +- .../test-plan/report/detail/exportPDF.vue | 36 +++++++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/pure/ms-rich-text/MsRichText.vue b/frontend/src/components/pure/ms-rich-text/MsRichText.vue index a3c339b3ac..2ce7a8a5e0 100644 --- a/frontend/src/components/pure/ms-rich-text/MsRichText.vue +++ b/frontend/src/components/pure/ms-rich-text/MsRichText.vue @@ -521,8 +521,8 @@ const contentStyles = computed(() => { return { - maxHeight: props.autoHeight ? '800px' : props.maxHeight || '260px', - overflow: 'auto', + maxHeight: props.autoHeight ? '' : props.maxHeight || '260px', + overflow: props.autoHeight ? 'hidden' : 'auto', }; }); diff --git a/frontend/src/hooks/useExportPDF.ts b/frontend/src/hooks/useExportPDF.ts index 8a86b6d870..5025078c3d 100644 --- a/frontend/src/hooks/useExportPDF.ts +++ b/frontend/src/hooks/useExportPDF.ts @@ -107,9 +107,9 @@ export default async function exportPDF( }; autoTableConfig.forEach((config, index) => { autoTable(pdf, { + ...(commonOdfTableConfig as UserOptions), ...config, startY: index === 0 && lastImagePageUseHeight > 0 ? lastImagePageUseHeight + 32 : undefined, // 第一页表格如果和图片同一页,则需要设置 startY 为当前图片占用高度+32,以避免表格遮挡图片 - ...(commonOdfTableConfig as UserOptions), didDrawPage: (data) => { pdf.text( `${data.doc.internal.getCurrentPageInfo().pageNumber}`, diff --git a/frontend/src/views/test-plan/report/detail/exportPDF.vue b/frontend/src/views/test-plan/report/detail/exportPDF.vue index d6e82b7559..8895109c05 100644 --- a/frontend/src/views/test-plan/report/detail/exportPDF.vue +++ b/frontend/src/views/test-plan/report/detail/exportPDF.vue @@ -167,7 +167,6 @@ import { BatchApiParams } from '@/models/common'; import type { - componentItem, configItem, countDetail, PlanReportDetail, @@ -685,10 +684,10 @@ ); return { - apiColumns: apiColumns || apiDefaultColumns, - scenarioColumns: scenarioColumns || apiDefaultColumns, - bugColumns: bugColumns || bugDefaultColumns, - functionalCaseColumns: functionalCaseColumns || caseDefaultColumns, + apiColumns: apiColumns.length > 0 ? apiColumns : apiDefaultColumns.value, + scenarioColumns: scenarioColumns.length > 0 ? scenarioColumns : apiDefaultColumns.value, + bugColumns: bugColumns.length > 0 ? bugColumns : bugDefaultColumns, + functionalCaseColumns: functionalCaseColumns.length > 0 ? functionalCaseColumns : caseDefaultColumns.value, }; } @@ -869,16 +868,23 @@ if (customCardImages.length > 0 || summaryImages.length > 0) { let loadedImageCount = 0; await new Promise((resolve) => { - const images = [...customCardImages, ...summaryImages]; - images.forEach((image) => { - image.onload = () => { - loadedImageCount += 1; - if (loadedImageCount === images.length) { - doExport(name, tableArr); - resolve(true); - } - }; - }); + const images = [...customCardImages, ...summaryImages].filter((image) => !image.complete); // 图片的加载是异步的,与 JS 解析是同时进行,所以需要过滤掉此时已经加载完毕的图片 + if (images.length > 0) { + // 此时还有未加载完成的图片,则给图片绑定加载事件,等待图片加载完毕后导出 + images.forEach((image) => { + image.onload = () => { + loadedImageCount += 1; + if (loadedImageCount === images.length) { + doExport(name, tableArr); + resolve(true); + } + }; + }); + } else { + // 此时图片都已加载完毕,则直接导出 PDF + doExport(name, tableArr); + resolve(true); + } }); } else { doExport(name, tableArr);