From 7f79a361bc60620eaa698c2c8b53e2bc0563c24b Mon Sep 17 00:00:00 2001 From: baiqi Date: Wed, 18 Sep 2024 13:57:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8A=A5=E5=91=8A):=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E3=80=81=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=AF=BC=E5=87=BA=20PDF=20=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E6=97=A0=E5=8F=8D=E5=BA=94=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046555 --user=白奇 【测试计划】批量导出当前页10条/3条以上计划报告失败 https://www.tapd.cn/55049933/s/1579351 --- frontend/src/hooks/useOpenNewPage.ts | 23 ++++++++++++++++--- .../views/api-test/report/exportCasePDF.vue | 13 +++++++---- .../api-test/report/exportScenarioPDF.vue | 13 +++++++---- .../setting/system/config/locale/zh-CN.ts | 8 +++---- .../test-plan/report/detail/exportPDF.vue | 8 ++++--- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/frontend/src/hooks/useOpenNewPage.ts b/frontend/src/hooks/useOpenNewPage.ts index b5039d1970..5193ce803f 100644 --- a/frontend/src/hooks/useOpenNewPage.ts +++ b/frontend/src/hooks/useOpenNewPage.ts @@ -1,6 +1,7 @@ import { RouteRecordName, useRouter } from 'vue-router'; import { useAppStore } from '@/store'; +import { getGenerateId } from '@/utils'; /** * 打开新页面 @@ -71,11 +72,27 @@ export default function useOpenNewPage() { // 等待新标签页加载完成后发送消息 if (newTab) { + let timeInterval: NodeJS.Timeout; + const eventId = `${name as string}-${getGenerateId()}`; newTab.onload = () => { - setTimeout(() => { - newTab.postMessage(JSON.stringify(params), window.location.origin); - }, 300); + timeInterval = setInterval(() => { + newTab.postMessage( + JSON.stringify({ + eventId, + data: params, + }), + window.location.origin + ); + }, 100); }; + window.addEventListener('message', (event) => { + if (event.origin !== window.location.origin) { + return; + } + if (event.data === eventId) { + clearInterval(timeInterval); + } + }); } } diff --git a/frontend/src/views/api-test/report/exportCasePDF.vue b/frontend/src/views/api-test/report/exportCasePDF.vue index 475e27712f..af7dd55b0a 100644 --- a/frontend/src/views/api-test/report/exportCasePDF.vue +++ b/frontend/src/views/api-test/report/exportCasePDF.vue @@ -26,6 +26,7 @@ } from '@/api/modules/api-test/management'; import { reportCaseDetail } from '@/api/modules/api-test/report'; import { useI18n } from '@/hooks/useI18n'; + import { characterLimit } from '@/utils'; import exportPDF from '@/utils/exportPdf'; import { ReportDetail } from '@/models/apiTest/report'; @@ -45,7 +46,9 @@ nextTick(async () => { await exportPDF(reportStepDetail.value?.name || '', 'report-detail'); loading.value = false; - Message.success(t('report.detail.exportPdfSuccess')); + Message.success( + t('report.detail.exportPdfSuccess', { name: characterLimit(reportStepDetail.value?.name, 50) }) + ); }); }, 500); } catch (error) { @@ -98,10 +101,12 @@ if (event.origin !== window.location.origin) { return; } + const { data, eventId } = JSON.parse(event.data); + // 发送响应回旧标签页 + window.opener.postMessage(eventId, window.location.origin); // 初始化批量导出报告 id 集合 - const batchParams = event.data; - initBatchIds(batchParams); - logExport(batchParams); + initBatchIds(data); + logExport(data); }); if (route.query.id) { initReportDetail(); diff --git a/frontend/src/views/api-test/report/exportScenarioPDF.vue b/frontend/src/views/api-test/report/exportScenarioPDF.vue index 2599ff0c03..008c6d7edc 100644 --- a/frontend/src/views/api-test/report/exportScenarioPDF.vue +++ b/frontend/src/views/api-test/report/exportScenarioPDF.vue @@ -26,6 +26,7 @@ logScenarioReportExport, } from '@/api/modules/api-test/scenario'; import { useI18n } from '@/hooks/useI18n'; + import { characterLimit } from '@/utils'; import exportPDF from '@/utils/exportPdf'; import { ReportDetail } from '@/models/apiTest/report'; @@ -46,7 +47,9 @@ await nextTick(async () => { await exportPDF(reportStepDetail.value?.name || '', 'report-detail'); loading.value = false; - Message.success(t('report.detail.exportPdfSuccess')); + Message.success( + t('report.detail.exportPdfSuccess', { name: characterLimit(reportStepDetail.value?.name, 50) }) + ); resolve(true); }); }, 500); // TODO:树组件渲染延迟导致导出 pdf 时内容不全,暂时延迟 500ms @@ -101,10 +104,12 @@ if (event.origin !== window.location.origin) { return; } + const { data, eventId } = JSON.parse(event.data); + // 发送响应回旧标签页 + window.opener.postMessage(eventId, window.location.origin); // 初始化批量导出报告 id 集合 - const batchParams = event.data; - initBatchIds(batchParams); - logExport(batchParams); + initBatchIds(data); + logExport(data); }); if (route.query.id) { initReportDetail(); diff --git a/frontend/src/views/setting/system/config/locale/zh-CN.ts b/frontend/src/views/setting/system/config/locale/zh-CN.ts index 5d218cb84e..f647a802fc 100644 --- a/frontend/src/views/setting/system/config/locale/zh-CN.ts +++ b/frontend/src/views/setting/system/config/locale/zh-CN.ts @@ -139,10 +139,10 @@ export default { 'system.config.auth.callbackUrlRequired': '回调地址不能为空', 'system.config.auth.authUrl': '授权端地址', 'system.config.auth.authUrlRequired': '授权端地址不能为空', - 'system.config.auth.tokenUrl': 'Token 端点地址', - 'system.config.auth.tokenUrlRequired': 'Token 端点地址不能为空', - 'system.config.auth.userInfoUrl': '用户信息端点地址', - 'system.config.auth.userInfoUrlRequired': '用户信息端点地址不能为空', + 'system.config.auth.tokenUrl': 'Token 端地址', + 'system.config.auth.tokenUrlRequired': 'Token 端地址不能为空', + 'system.config.auth.userInfoUrl': '用户信息端地址', + 'system.config.auth.userInfoUrlRequired': '用户信息端地址不能为空', 'system.config.auth.clientId': '客户端 ID', 'system.config.auth.clientIdRequired': '客户端 ID不能为空', 'system.config.auth.clientIdPlaceholder': '例如:metersphere', diff --git a/frontend/src/views/test-plan/report/detail/exportPDF.vue b/frontend/src/views/test-plan/report/detail/exportPDF.vue index c729bb9e29..ebd2247c0f 100644 --- a/frontend/src/views/test-plan/report/detail/exportPDF.vue +++ b/frontend/src/views/test-plan/report/detail/exportPDF.vue @@ -830,10 +830,12 @@ if (event.origin !== window.location.origin) { return; } + const { data, eventId } = JSON.parse(event.data); + // 发送响应回旧标签页 + window.opener.postMessage(eventId, window.location.origin); // 初始化批量导出报告 id 集合 - const batchParams = event.data; - initBatchIds(batchParams); - logExport(batchParams); + initBatchIds(data); + logExport(data); }); if (reportId.value) { getDetail();