fix(接口测试): 修复导出大的测试报告出现空白页问题

This commit is contained in:
fit2-zhao 2023-02-06 09:38:47 +08:00 committed by fit2-zhao
parent c391cc57e4
commit 664bf2711d
4 changed files with 52 additions and 35 deletions

View File

@ -26,6 +26,7 @@
"fit2cloud-ui": "^1.8.0", "fit2cloud-ui": "^1.8.0",
"html2canvas": "^1.0.0-rc.7", "html2canvas": "^1.0.0-rc.7",
"js-base64": "^3.4.4", "js-base64": "^3.4.4",
"js-file-download": "^0.4.12",
"jsencrypt": "^3.1.0", "jsencrypt": "^3.1.0",
"json-bigint": "^1.0.0", "json-bigint": "^1.0.0",
"json-schema-faker": "^0.5.0-rcv.32", "json-schema-faker": "^0.5.0-rcv.32",
@ -50,6 +51,7 @@
"pdfjs-dist": "2.5.207", "pdfjs-dist": "2.5.207",
"pinia": "^2.0.14", "pinia": "^2.0.14",
"pinia-plugin-persistedstate": "^1.6.3", "pinia-plugin-persistedstate": "^1.6.3",
"print-js": "^1.6.0",
"sha.js": "^2.4.11", "sha.js": "^2.4.11",
"vue": "^2.7.3", "vue": "^2.7.3",
"vue-calendar-heatmap": "^0.8.4", "vue-calendar-heatmap": "^0.8.4",
@ -66,8 +68,7 @@
"vue2-ace-editor": "0.0.15", "vue2-ace-editor": "0.0.15",
"vuedraggable": "^2.24.3", "vuedraggable": "^2.24.3",
"xml-js": "^1.6.11", "xml-js": "^1.6.11",
"yan-progress": "^1.0.3", "yan-progress": "^1.0.3"
"js-file-download": "^0.4.12"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.16", "@babel/core": "^7.12.16",

View File

@ -130,6 +130,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 print from 'print-js';
export default { export default {
name: 'MsApiReport', name: 'MsApiReport',
@ -708,11 +709,27 @@ export default {
name = this.encodeSearchKey(name); name = this.encodeSearchKey(name);
this.$nextTick(() => { this.$nextTick(() => {
setTimeout(() => { setTimeout(() => {
downloadPDF(document.getElementById('apiTestReport'), name || 'scenario-report'); this.printHTML();
reset(); reset();
}, 5000); }, 5000);
}); });
}, },
printHTML() {
function closeFuc() {
location.reload();
}
print({
printable: 'apiTestReport',
type: 'html',
maxWidth: 1200,
documentTitle: '',
scanStyles: true,
header: '',
targetStyles: ['*'], // 使HTML/
onPrintDialogClose: closeFuc,
});
},
// //
encodeSearchKey(key) { encodeSearchKey(key) {
const encodeArr = [ const encodeArr = [

View File

@ -53,12 +53,12 @@
{{ request.passAssertions + ' / ' + request.totalAssertions }} {{ request.passAssertions + ' / ' + request.totalAssertions }}
</api-report-request-header-item> </api-report-request-header-item>
<api-report-request-header-item :title="$t('api_report.response_code')" style="width: 300px"> <api-report-request-header-item :title="$t('api_report.response_code')" style="width: 200px">
{{ request.responseResult.responseCode }} {{ request.responseResult.responseCode }}
</api-report-request-header-item> </api-report-request-header-item>
<api-report-request-header-item :title="$t('api_report.result')" style="width: 50px"> <api-report-request-header-item :title="$t('api_report.result')" style="width: 50px">
<el-tag v-if="request.unexecute">{{ $t('api_test.home_page.detail_card.unexecute') }} </el-tag> <el-tag v-if="request.unexecute">Pending </el-tag>
<el-tag v-else-if="!request.success && request.status && request.status === 'PENDING'">Pending </el-tag> <el-tag v-else-if="!request.success && request.status && request.status === 'PENDING'">Pending </el-tag>
<el-tag v-else-if="request.errorCode" class="ms-test-error_code"> FakeError </el-tag> <el-tag v-else-if="request.errorCode" class="ms-test-error_code"> FakeError </el-tag>
<el-tag size="mini" type="success" v-else-if="request.success"> Success </el-tag> <el-tag size="mini" type="success" v-else-if="request.success"> Success </el-tag>
@ -122,7 +122,7 @@ export default {
.scenario-result { .scenario-result {
margin-top: 20px; margin-top: 20px;
margin-bottom: 20px; margin-bottom: 20px;
min-width: 1200px; min-width: 1000px;
} }
.method { .method {
@ -158,4 +158,11 @@ export default {
background-color: #fdf5ea; background-color: #fdf5ea;
border-color: #fdf5ea; border-color: #fdf5ea;
} }
:deep(.report-left) {
float: none;
}
:deep(.metric-box-total) {
min-width: 100px;
}
</style> </style>

View File

@ -5,47 +5,38 @@
<div class="title"> <div class="title">
{{ type }}- {{ title }} {{ type }}- {{ title }}
<span v-if="report && (report.endTime || report.createTime)"> <span v-if="report && (report.endTime || report.createTime)">
<span style="margin-left: 10px" <span style="margin-left: 10px">{{ $t("report.test_start_time") }}</span>
>{{ $t("report.test_start_time") }}</span
>
<span class="time"> {{ report.createTime | datetimeFormat }}</span> <span class="time"> {{ report.createTime | datetimeFormat }}</span>
<span style="margin-left: 10px" <span style="margin-left: 10px">{{ $t("report.test_end_time") }}</span>
>{{ $t("report.test_end_time") }}</span
>
<span class="time"> {{ report.endTime | datetimeFormat }}</span> <span class="time"> {{ report.endTime | datetimeFormat }}</span>
</span> </span>
</div> </div>
</div> </div>
<div class="report-right"> <div class="report-right">
<img class="logo" src="/assets/logo-MeterSphere.png" /> <img class="logo" src="/assets/logo-MeterSphere.png"/>
</div> </div>
</el-row> </el-row>
<el-row type="flex" style="margin-top: 5px"> <el-row type="flex" style="margin-top: 5px">
<el-col v-if="this.mode"> <el-col v-if="this.mode">
<div style="float: left"> <span> {{ $t("report.run_model") + ":" }} </span>
<span> {{ $t("report.run_model") + ":" }} </span> <span style="color: #61c550; ">
</div> {{ getModeName(this.mode) }}
<div style="color: #61c550; margin-left: 10px; float: left"> </span>
{{ getModeName(this.mode) }}
</div>
</el-col> </el-col>
<el-col v-if="this.poolName"> <el-col v-if="this.poolName">
<div style="float: left"> <span> {{ $t("load_test.select_resource_pool") + ":" }} </span>
<span> {{ $t("load_test.select_resource_pool") + ":" }} </span> <span style="color: #61c550; ">
</div> {{ this.poolName }}
<div style="color: #61c550; margin-left: 10px; float: left"> </span>
{{ this.poolName }}
</div>
</el-col> </el-col>
<el-col></el-col>
</el-row> </el-row>
<el-row v-if="showProjectEnv" type="flex" style="margin-top: 5px"> <el-row v-if="showProjectEnv" style="margin-top: 5px">
<span> {{ $t("commons.environment") + ":" }} </span> <el-col>
<div <span> {{ $t("commons.environment") + ":" }} </span>
v-for="(values, key) in projectEnvMap" <span
:key="key" v-for="(values, key) in projectEnvMap"
style="margin-right: 10px" :key="key"
> style="margin-right: 10px">
{{ key + ":" }} {{ key + ":" }}
<ms-tag <ms-tag
v-for="(item, index) in values" v-for="(item, index) in values"
@ -54,7 +45,8 @@
:content="item" :content="item"
style="margin-left: 2px" style="margin-left: 2px"
/> />
</div> </span>
</el-col>
</el-row> </el-row>
</div> </div>
</template> </template>
@ -64,7 +56,7 @@ import MsTag from "../MsTag";
export default { export default {
name: "MsReportTitle", name: "MsReportTitle",
components: { MsTag }, components: {MsTag},
props: { props: {
title: String, title: String,
type: String, type: String,