fix(接口测试): 修复结果格式化切换失败问题

【【接口测试】github#29194,【接口测试】sql语句,从text切换到table,没显示数据。】
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036654

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2024-12-06 15:58:42 +08:00 committed by Craftsman
parent bdc17c8340
commit ac1c3a9db7
4 changed files with 72 additions and 53 deletions

View File

@ -6,10 +6,10 @@
:label="$t('api_test.definition.request.response_body')"
name="body"
class="pane">
<ms-sql-result-table v-if="isSqlType && !response.contentType" :body="response.body" />
<ms-sql-result-table v-if="isSqlType" :body="response.body" />
<el-row v-else-if="isPicture && activeName === 'body'">
<el-col :span="24">
<el-image :src="srcUrl" fit="contain" style="width: 100%;height: 100%;"></el-image>
<el-image :src="srcUrl" fit="contain" style="width: 100%; height: 100%"></el-image>
</el-col>
</el-row>
<ms-code-edit v-else :mode="mode" :read-only="true" :data="response.body" :modes="modes" ref="codeEdit" />
@ -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'
);
},
},
};

View File

@ -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,
});
}
},
},
};

View File

@ -2,9 +2,7 @@
<div class="text-container" v-if="responseResult">
<el-tabs v-model="activeName" v-show="isActive">
<el-tab-pane :label="$t('api_test.definition.request.response_body')" name="body" class="pane">
<ms-sql-result-table
v-if="isSqlType && activeName === 'body' && !responseResult.contentType"
:body="responseResult.body" />
<ms-sql-result-table v-if="isSqlType && activeName === 'body'" :body="responseResult.body" />
<ms-code-edit
v-if="!isSqlType && isMsCodeEditShow && activeName === 'body' && !isPicture"
:mode="mode"

View File

@ -56,37 +56,45 @@ export default {
this.getTableData(rowArray);
},
getTableData(rowArray) {
let titles;
let result = [];
if (!Array.isArray(rowArray) || rowArray.length === 0) {
console.warn('Invalid input: rowArray should be a non-empty array.');
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) {
//
const remainingRows = rowArray.slice(i);
this.getTableData(colArray.length === 1 && colArray[0] === '' ? remainingRows.slice(1) : remainingRows);
break;
} 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 {
let item = {};
for (let j = 0; j < colArray.length; j++) {
item[titles[j]] = colArray[j] ? colArray[j] : '';
}
//
if (result.length < 100) {
result.push(item);
}
//
const item = titles.reduce((acc, title, index) => {
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,
});
}
},
},
};