From ac1c3a9db788018978477fb352ac46467ea10ec6 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 6 Dec 2024 15:58:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BB=93=E6=9E=9C=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【【接口测试】github#29194,【接口测试】sql语句,从text切换到table,没显示数据。】 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036654 Signed-off-by: fit2-zhao --- .../report/components/ResponseText.vue | 12 ++-- .../report/components/SqlResultTable.vue | 53 +++++++++++------- .../components/response/ResponseResult.vue | 4 +- .../components/response/SqlResultTable.vue | 56 +++++++++++-------- 4 files changed, 72 insertions(+), 53 deletions(-) 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, + }); + } }, }, };