diff --git a/api-test/frontend/src/business/automation/report/components/ResponseText.vue b/api-test/frontend/src/business/automation/report/components/ResponseText.vue index 7014ed49f1..f7af605248 100644 --- a/api-test/frontend/src/business/automation/report/components/ResponseText.vue +++ b/api-test/frontend/src/business/automation/report/components/ResponseText.vue @@ -6,10 +6,10 @@ :label="$t('api_test.definition.request.response_body')" name="body" class="pane"> - + - + @@ -99,7 +99,7 @@ export default { 'image/webp', 'image/svg+xml', 'image/apng', - 'image/avif' + 'image/avif', ], srcUrl: '', }; @@ -122,7 +122,7 @@ export default { this.mode = BODY_FORMAT.JSON; } if (this.response.contentType && this.contentType.includes(this.response.contentType)) { - this.modes.push('picture') + this.modes.push('picture'); this.srcUrl = 'data:' + this.response.contentType + ';base64,' + this.response.imageUrl; } if (this.response && this.response.contentType) { @@ -148,7 +148,9 @@ export default { ); }, isPicture() { - return this.response.contentType && this.contentType.includes(this.response.contentType) && this.mode === 'picture'; + return ( + this.response.contentType && this.contentType.includes(this.response.contentType) && this.mode === 'picture' + ); }, }, }; diff --git a/api-test/frontend/src/business/automation/report/components/SqlResultTable.vue b/api-test/frontend/src/business/automation/report/components/SqlResultTable.vue index 84bf5dfacb..92e3fbd1d8 100644 --- a/api-test/frontend/src/business/automation/report/components/SqlResultTable.vue +++ b/api-test/frontend/src/business/automation/report/components/SqlResultTable.vue @@ -63,35 +63,46 @@ export default { }, methods: { getTableData(rowArray) { - let titles; - let result = []; + if (!Array.isArray(rowArray) || rowArray.length === 0) { + console.warn('Input is not a valid array or is empty.'); + return; + } + + let titles = []; + const result = []; + for (let i = 0; i < rowArray.length; i++) { - let colArray = rowArray[i].split('\t'); + const colArray = rowArray[i].split('\t'); + if (i === 0) { + // 第一行为标题 titles = colArray; - } else { - if (colArray.length != titles.length) { - // 创建新的表 - if (colArray.length === 1 && colArray[0] === '') { - this.getTableData(rowArray.slice(i + 1)); - } else { - this.getTableData(rowArray.slice(i)); - } - break; + } else if (colArray.length !== titles.length) { + // 如果当前行与标题列数不一致,递归解析剩余数据 + const remainingRows = rowArray.slice(i); + if (colArray.length === 1 && colArray[0] === '') { + this.getTableData(remainingRows.slice(1)); // 跳过空行 } else { - let item = {}; - for (let j = 0; j < colArray.length; j++) { - item[titles[j]] = colArray[j] ? colArray[j] : ''; - } - result.push(item); + this.getTableData(remainingRows); } + break; + } else { + // 构造数据对象 + const item = titles.reduce((obj, title, index) => { + obj[title] = colArray[index] || ''; + return obj; + }, {}); + result.push(item); } } - this.tables.splice(0, 0, { - titles: titles, - tableData: result, - }); + if (titles.length > 0) { + // 插入到 tables 数组的开头 + this.tables.unshift({ + titles, + tableData: result, + }); + } }, }, }; diff --git a/api-test/frontend/src/business/definition/components/response/ResponseResult.vue b/api-test/frontend/src/business/definition/components/response/ResponseResult.vue index 8dc146f82a..b458c1148c 100644 --- a/api-test/frontend/src/business/definition/components/response/ResponseResult.vue +++ b/api-test/frontend/src/business/definition/components/response/ResponseResult.vue @@ -2,9 +2,7 @@
- + { + acc[title] = colArray[index] || ''; + return acc; + }, {}); + + // 限制表格行数不超过 100 行 + if (result.length < 100) { + result.push(item); } } } - this.tables.splice(0, 0, { - titles: titles, - tableData: result, - }); + + if (titles.length > 0 && result.length > 0) { + this.tables.unshift({ + titles, + tableData: result, + }); + } }, }, };