fix(报告): 接口测试、测试计划批量导出 PDF 报告无反应修复

--bug=1046555 --user=白奇 【测试计划】批量导出当前页10条/3条以上计划报告失败 https://www.tapd.cn/55049933/s/1579351
This commit is contained in:
baiqi 2024-09-18 13:57:31 +08:00 committed by Craftsman
parent 0b6a10e9a3
commit 7f79a361bc
5 changed files with 47 additions and 18 deletions

View File

@ -1,6 +1,7 @@
import { RouteRecordName, useRouter } from 'vue-router'; import { RouteRecordName, useRouter } from 'vue-router';
import { useAppStore } from '@/store'; import { useAppStore } from '@/store';
import { getGenerateId } from '@/utils';
/** /**
* *
@ -71,11 +72,27 @@ export default function useOpenNewPage() {
// 等待新标签页加载完成后发送消息 // 等待新标签页加载完成后发送消息
if (newTab) { if (newTab) {
let timeInterval: NodeJS.Timeout;
const eventId = `${name as string}-${getGenerateId()}`;
newTab.onload = () => { newTab.onload = () => {
setTimeout(() => { timeInterval = setInterval(() => {
newTab.postMessage(JSON.stringify(params), window.location.origin); newTab.postMessage(
}, 300); 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);
}
});
} }
} }

View File

@ -26,6 +26,7 @@
} from '@/api/modules/api-test/management'; } from '@/api/modules/api-test/management';
import { reportCaseDetail } from '@/api/modules/api-test/report'; import { reportCaseDetail } from '@/api/modules/api-test/report';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import { characterLimit } from '@/utils';
import exportPDF from '@/utils/exportPdf'; import exportPDF from '@/utils/exportPdf';
import { ReportDetail } from '@/models/apiTest/report'; import { ReportDetail } from '@/models/apiTest/report';
@ -45,7 +46,9 @@
nextTick(async () => { nextTick(async () => {
await exportPDF(reportStepDetail.value?.name || '', 'report-detail'); await exportPDF(reportStepDetail.value?.name || '', 'report-detail');
loading.value = false; loading.value = false;
Message.success(t('report.detail.exportPdfSuccess')); Message.success(
t('report.detail.exportPdfSuccess', { name: characterLimit(reportStepDetail.value?.name, 50) })
);
}); });
}, 500); }, 500);
} catch (error) { } catch (error) {
@ -98,10 +101,12 @@
if (event.origin !== window.location.origin) { if (event.origin !== window.location.origin) {
return; return;
} }
const { data, eventId } = JSON.parse(event.data);
//
window.opener.postMessage(eventId, window.location.origin);
// id // id
const batchParams = event.data; initBatchIds(data);
initBatchIds(batchParams); logExport(data);
logExport(batchParams);
}); });
if (route.query.id) { if (route.query.id) {
initReportDetail(); initReportDetail();

View File

@ -26,6 +26,7 @@
logScenarioReportExport, logScenarioReportExport,
} from '@/api/modules/api-test/scenario'; } from '@/api/modules/api-test/scenario';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import { characterLimit } from '@/utils';
import exportPDF from '@/utils/exportPdf'; import exportPDF from '@/utils/exportPdf';
import { ReportDetail } from '@/models/apiTest/report'; import { ReportDetail } from '@/models/apiTest/report';
@ -46,7 +47,9 @@
await nextTick(async () => { await nextTick(async () => {
await exportPDF(reportStepDetail.value?.name || '', 'report-detail'); await exportPDF(reportStepDetail.value?.name || '', 'report-detail');
loading.value = false; loading.value = false;
Message.success(t('report.detail.exportPdfSuccess')); Message.success(
t('report.detail.exportPdfSuccess', { name: characterLimit(reportStepDetail.value?.name, 50) })
);
resolve(true); resolve(true);
}); });
}, 500); // TODO: pdf 500ms }, 500); // TODO: pdf 500ms
@ -101,10 +104,12 @@
if (event.origin !== window.location.origin) { if (event.origin !== window.location.origin) {
return; return;
} }
const { data, eventId } = JSON.parse(event.data);
//
window.opener.postMessage(eventId, window.location.origin);
// id // id
const batchParams = event.data; initBatchIds(data);
initBatchIds(batchParams); logExport(data);
logExport(batchParams);
}); });
if (route.query.id) { if (route.query.id) {
initReportDetail(); initReportDetail();

View File

@ -139,10 +139,10 @@ export default {
'system.config.auth.callbackUrlRequired': '回调地址不能为空', 'system.config.auth.callbackUrlRequired': '回调地址不能为空',
'system.config.auth.authUrl': '授权端地址', 'system.config.auth.authUrl': '授权端地址',
'system.config.auth.authUrlRequired': '授权端地址不能为空', 'system.config.auth.authUrlRequired': '授权端地址不能为空',
'system.config.auth.tokenUrl': 'Token 端地址', 'system.config.auth.tokenUrl': 'Token 端地址',
'system.config.auth.tokenUrlRequired': 'Token 端地址不能为空', 'system.config.auth.tokenUrlRequired': 'Token 端地址不能为空',
'system.config.auth.userInfoUrl': '用户信息端地址', 'system.config.auth.userInfoUrl': '用户信息端地址',
'system.config.auth.userInfoUrlRequired': '用户信息端地址不能为空', 'system.config.auth.userInfoUrlRequired': '用户信息端地址不能为空',
'system.config.auth.clientId': '客户端 ID', 'system.config.auth.clientId': '客户端 ID',
'system.config.auth.clientIdRequired': '客户端 ID不能为空', 'system.config.auth.clientIdRequired': '客户端 ID不能为空',
'system.config.auth.clientIdPlaceholder': '例如metersphere', 'system.config.auth.clientIdPlaceholder': '例如metersphere',

View File

@ -830,10 +830,12 @@
if (event.origin !== window.location.origin) { if (event.origin !== window.location.origin) {
return; return;
} }
const { data, eventId } = JSON.parse(event.data);
//
window.opener.postMessage(eventId, window.location.origin);
// id // id
const batchParams = event.data; initBatchIds(data);
initBatchIds(batchParams); logExport(data);
logExport(batchParams);
}); });
if (reportId.value) { if (reportId.value) {
getDetail(); getDetail();