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 { 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);
}
});
}
}

View File

@ -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();

View File

@ -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();

View File

@ -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',

View File

@ -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();