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:
parent
bdc17c8340
commit
ac1c3a9db7
|
@ -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'
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue