refactor(接口测试): 优化场景报告导出样式

--bug=1018154 --user=王孝刚 【接口测试】接口场景测试报告导出样式优化
https://www.tapd.cn/55049933/s/1271480
This commit is contained in:
wxg0103 2022-10-21 19:04:12 +08:00 committed by wxg0103
parent 00b62ec307
commit 68e0a06916
1 changed files with 21 additions and 7 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<ms-container v-loading="loading"> <ms-container v-loading="loading || reportExportVisible">
<ms-main-container class="api-report-content"> <ms-main-container class="api-report-content">
<el-card class="report-body"> <el-card class="report-body">
<section class="report-container" v-if="this.report.testId"> <section class="report-container" v-if="this.report.testId">
@ -98,7 +98,7 @@
:title="report.name" :title="report.name"
:content="content" :content="content"
:report="report" :report="report"
:total-time="totalTime"/> :total-time="totalTime" class="ms-copy-bottom"/>
</main> </main>
</section> </section>
</el-card> </el-card>
@ -119,7 +119,7 @@ import MsApiReportExport from "./ApiReportExport";
import MsApiReportViewHeader from "./ApiReportViewHeader"; import MsApiReportViewHeader from "./ApiReportViewHeader";
import {RequestFactory} from "../../definition/model/ApiTestModel"; import {RequestFactory} from "../../definition/model/ApiTestModel";
import {getCurrentProjectID} from "metersphere-frontend/src/utils/token"; import {getCurrentProjectID} from "metersphere-frontend/src/utils/token";
import {getUUID, windowPrint} from "metersphere-frontend/src/utils"; import {exportPdf, getUUID} from "metersphere-frontend/src/utils";
import {hasLicense} from "metersphere-frontend/src/utils/permission"; import {hasLicense} from "metersphere-frontend/src/utils/permission";
import { import {
getScenarioReport, getScenarioReport,
@ -129,6 +129,7 @@ import {
} from "../../../api/scenario-report"; } from "../../../api/scenario-report";
import {STEP} from "../../automation/scenario/Setting"; import {STEP} from "../../automation/scenario/Setting";
import MsCodeEdit from "metersphere-frontend/src/components/MsCodeEdit"; import MsCodeEdit from "metersphere-frontend/src/components/MsCodeEdit";
import html2canvas from "html2canvas";
export default { export default {
name: "MsApiReport", name: "MsApiReport",
@ -672,7 +673,7 @@ export default {
} else { } else {
if (this.fullTreeNodes) { if (this.fullTreeNodes) {
this.fullTreeNodes.forEach(item => { this.fullTreeNodes.forEach(item => {
if (item.type === "scenario" || item.type === "UiScenario") { if (item.type === "scenario") {
let scenario = {name: item.label, requestResults: []}; let scenario = {name: item.label, requestResults: []};
if (this.content.scenarios && this.content.scenarios.length > 0) { if (this.content.scenarios && this.content.scenarios.length > 0) {
this.content.scenarios.push(scenario); this.content.scenarios.push(scenario);
@ -687,9 +688,15 @@ export default {
} }
this.reportExportVisible = true; this.reportExportVisible = true;
let reset = this.exportReportReset; let reset = this.exportReportReset;
let name = this.report.name;
this.$nextTick(() => { this.$nextTick(() => {
windowPrint('apiTestReport', 0.57); setTimeout(() => {
reset(); let promise = html2canvas(document.getElementById("apiTestReport"), {scale: 2});
Promise.all([promise]).then(function (canvas) {
exportPdf(name || "scenario-report", canvas);
reset();
});
}, 1000);
}); });
}, },
handleSave() { handleSave() {
@ -711,7 +718,8 @@ export default {
}); });
}, },
exportReportReset() { exportReportReset() {
this.$router.go(0); this.reportExportVisible = false;
this.loading = false;
}, },
handleProjectChange() { handleProjectChange() {
this.$router.push('/api/automation/report'); this.$router.push('/api/automation/report');
@ -794,4 +802,10 @@ export default {
.report-body { .report-body {
min-width: 750px !important; min-width: 750px !important;
} }
.ms-copy-bottom {
position: absolute;
bottom: 0;
}
</style> </style>