fix(接口测试): 断言排序&筛选

This commit is contained in:
baiqi 2024-11-14 17:28:18 +08:00 committed by Craftsman
parent 8914f05c93
commit 8efc5f5207
1 changed files with 16 additions and 7 deletions

View File

@ -130,28 +130,37 @@
width: 300,
},
];
const tableData = ref(props.requestResult?.responseResult.assertions);
const tableData = ref(props.requestResult?.responseResult.assertions || []);
const isTableFiltered = ref<boolean>(false);
function handleFilterChange(dataIndex: string, value: string[] | (string | number | boolean)[] | undefined) {
if (value && value.length > 0) {
tableData.value = props.requestResult?.responseResult.assertions.filter((item) => {
isTableFiltered.value = true;
tableData.value =
props.requestResult?.responseResult.assertions.filter((item) => {
return (value as boolean[]).includes(item.pass);
});
}) || [];
} else {
tableData.value = props.requestResult?.responseResult.assertions;
isTableFiltered.value = false;
tableData.value = props.requestResult?.responseResult.assertions || [];
}
}
function handleSortChange(sorter: { [key: string]: string }) {
if (Object.keys(sorter).length > 0) {
const dataIndex = Object.keys(sorter)[0] as keyof ResponseAssertionTableItem;
const copyArray = [...(props.requestResult?.responseResult.assertions || [])];
const copyArray = isTableFiltered.value
? [...tableData.value]
: [...(props.requestResult?.responseResult.assertions || [])];
tableData.value = copyArray.sort((a, b) => {
const sortResult = a[dataIndex] > b[dataIndex] ? -1 : 1;
return sorter[dataIndex] === 'asc' ? sortResult : -sortResult;
});
} else {
tableData.value = props.requestResult?.responseResult.assertions;
tableData.value = isTableFiltered.value
? [...tableData.value]
: props.requestResult?.responseResult.assertions || [];
}
}
</script>