diff --git a/framework/sdk-parent/frontend/src/plugins/request.js b/framework/sdk-parent/frontend/src/plugins/request.js index 008262491f..18831e52ee 100644 --- a/framework/sdk-parent/frontend/src/plugins/request.js +++ b/framework/sdk-parent/frontend/src/plugins/request.js @@ -225,10 +225,17 @@ export function downloadFile(method, url, data, fileName, processHandler) { fileName = fileName.replaceAll("\"", ""); _downloadFile(fileName, res.data); resolve(); - }) - .catch((e) => { - $error(e.message); - reject(e); + }).catch((e) => { + // 报错后,将 blob 格式转成字符串,打印错误信息 + let reader = new FileReader(); + reader.readAsText(e.response.data, 'utf-8'); + reader.onload = function (e) { + if (reader.result) { + let info = JSON.parse(reader.result); + reject(info); + $error(info.message); + } + } }); }); } diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index fba562c7c1..580db9be99 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -1724,6 +1724,7 @@ public class TestCaseService { buildExportCustomField(customSelectValueMap, customNameMap, t, data, textFields); buildExportOtherField(data, t, otherHeaders); + this.validateExportTextField(t); if (CollectionUtils.isNotEmpty(stepDescList)) { // 如果有多条步骤则添加多条数据,之后合并单元格 buildExportMergeData(rowMergeInfo, list, stepDescList, stepResultList, data); @@ -1734,6 +1735,21 @@ public class TestCaseService { return list; } + private void validateExportTextField(TestCaseDTO data) { + List textValues= Arrays.asList(data.getPrerequisite(), data.getStepDescription(), data.getExpectedResult(), data.getRemark()); + for (String textValue : textValues) { + validateExportText(data.getName(), textValue); + } + } + + private void validateExportText(String name, String textValue) { + // poi 导出的单个单元格最大字符数量为 32767 ,这里添加校验提示 + int maxLength = 32767; + if (textValue.length() > maxLength) { + MSException.throwException(String.format(Translator.get("case_export_text_validate_tip"), name, maxLength)); + } + } + private void buildExportOtherField(TestCaseExcelData data, TestCaseDTO t, List otherHeaders) { if (CollectionUtils.isEmpty(otherHeaders)) { return; @@ -1800,6 +1816,7 @@ public class TestCaseService { String id = field.getFieldId(); if (textFields.contains(id)) { map.put(customNameMap.get(id), field.getTextValue()); + this.validateExportText(data.getName(), field.getTextValue()); continue; } if (StringUtils.isNotBlank(field.getValue())) { diff --git a/test-track/backend/src/main/resources/i18n/messages_en_US.properties b/test-track/backend/src/main/resources/i18n/messages_en_US.properties index 24db32dd8f..b1ab169c00 100644 --- a/test-track/backend/src/main/resources/i18n/messages_en_US.properties +++ b/test-track/backend/src/main/resources/i18n/messages_en_US.properties @@ -230,4 +230,5 @@ test_case_review_status_re_review=ReReview api_status_fake_error=FakeError serial=Serial parallel=Parallel -rerun_warning=The connection is abnormal, please check the environment configuration \ No newline at end of file +rerun_warning=The connection is abnormal, please check the environment configuration +case_export_text_validate_tip=Use case %s contains extremely long text, currently supported up to %s! diff --git a/test-track/backend/src/main/resources/i18n/messages_zh_CN.properties b/test-track/backend/src/main/resources/i18n/messages_zh_CN.properties index d152ff8528..c38cee9091 100644 --- a/test-track/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/test-track/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -202,3 +202,4 @@ api_status_fake_error=误报 serial=串行 parallel=并行 rerun_warning=连接异常,请检查环境配置 +case_export_text_validate_tip=用例 %s 包含超长文本,目前支持最大长度为 %s ! diff --git a/test-track/backend/src/main/resources/i18n/messages_zh_TW.properties b/test-track/backend/src/main/resources/i18n/messages_zh_TW.properties index 909d29a499..bdc2d16f41 100644 --- a/test-track/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/test-track/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -202,3 +202,4 @@ api_status_fake_error=誤報 serial=串行 parallel=並行 rerun_warning=連接異常,請檢查環境配置 +case_export_text_validate_tip=用例 %s 包含超長文本,目前支持最大長度為 %s ! diff --git a/test-track/frontend/src/business/case/components/TestCaseList.vue b/test-track/frontend/src/business/case/components/TestCaseList.vue index a04dfbeb3a..dfd437f7e3 100644 --- a/test-track/frontend/src/business/case/components/TestCaseList.vue +++ b/test-track/frontend/src/business/case/components/TestCaseList.vue @@ -314,6 +314,7 @@ import TestCaseReviewStatusTableItem from "@/business/common/tableItems/TestCase import RelateDemand from "@/business/case/components/RelateDemand"; import TestPlanCaseStatusTableItem from "@/business/common/tableItems/TestPlanCaseStatusTableItem"; import { + fileDownloadPost, generateColumnKey, getCustomFieldValueForTrack, getProjectMemberOption @@ -1052,45 +1053,26 @@ export default { } let param = buildBatchParam(this, this.$refs.table.selectIds); Object.assign(param, fieldParam); - let config = {}; - let fileNameSuffix = ""; + let fileNameSuffix; + let url; if (exportType === 'xmind') { - config = { - url: '/test/case/export/testcase/xmind', - method: 'post', - responseType: 'blob', - data: param - }; + url = '/test/case/export/testcase/xmind'; fileNameSuffix = ".xmind"; } else { - config = { - url: '/test/case/export/testcase', - method: 'post', - responseType: 'blob', - data: param - }; + url = '/test/case/export/testcase' fileNameSuffix = ".xlsx"; } this.loading = true; store.isTestCaseExporting = true; - - this.$request(config).then(response => { - this.loading = false; - const filename = "Metersphere_case_" + this.projectName + fileNameSuffix; - const blob = new Blob([response.data]); - if ("download" in document.createElement("a")) { - let aTag = document.createElement('a'); - aTag.download = filename; - aTag.href = URL.createObjectURL(blob); - aTag.click(); - URL.revokeObjectURL(aTag.href); + fileDownloadPost(url, param, "Metersphere_case_" + this.projectName + fileNameSuffix) + .then(() => { + this.loading = false; this.$emit('closeExport'); - } else { - navigator.msSaveBlob(blob, filename); - this.$emit('closeExport'); - } - store.isTestCaseExporting = false; - }); + store.isTestCaseExporting = false; + }).catch(() => { + this.loading = false; + store.isTestCaseExporting = false; + }); }, batchEdit(form) { let ids = this.$refs.table.selectIds;