fix(项目管理): 环境响应体问题修复

This commit is contained in:
xinxin.wu 2024-03-12 12:08:06 +08:00 committed by Craftsman
parent 100ff999fb
commit 8ac2f5ad5d
3 changed files with 97 additions and 51 deletions

View File

@ -16,7 +16,7 @@
:columns="jsonPathColumns"
:scroll="{ minWidth: '700px' }"
:default-param-item="jsonPathDefaultParamItem"
@change="(data) => handleChange(data, ResponseBodyAssertionType.JSON_PATH)"
@change="(data:any[],isInit?: boolean) => handleChange(data, ResponseBodyAssertionType.JSON_PATH,isInit)"
@more-action-select="(e,r)=> handleExtractParamMoreActionSelect(e,r as ExpressionConfig)"
>
<template #expression="{ record, rowIndex }">
@ -88,13 +88,7 @@
<!-- xPath开始 -->
<div v-if="activeTab === ResponseBodyAssertionType.XPATH" class="mt-[16px]">
<div class="text-[var(--color-text-1)]">{{ t('ms.assertion.responseContentType') }}</div>
<a-radio-group
v-model="activeResponseFormat"
class="mb-[16px] mt-[16px]"
type="button"
size="small"
@change="(value: string | number | boolean)=>changeHandler(value,ResponseBodyAssertionType.XPATH)"
>
<a-radio-group v-model="activeResponseFormat" class="mb-[16px] mt-[16px]" type="button" size="small">
<a-radio key="XML" value="XML">XML</a-radio>
<a-radio key="HTML" value="HTML">HTML</a-radio>
</a-radio-group>
@ -481,33 +475,40 @@
expression: '',
condition: '',
expectedValue: '',
valid: true,
enable: true,
moreSettingPopoverVisible: false,
disable: true,
};
const handleChange = (data: any[], type: string) => {
const handleChange = (data: any[], type: string, isInit?: boolean) => {
switch (type) {
case ResponseBodyAssertionType.JSON_PATH:
if (data.length > 1) {
data.splice(data.length - 1, 1);
}
condition.value.jsonPathAssertion.assertions = data;
emit('change', { ...defaultParamItem, ...condition.value, assertionBodyType: activeTab.value });
if (!isInit) {
emit('change', { ...condition.value, assertionBodyType: activeTab.value });
}
break;
case ResponseBodyAssertionType.XPATH:
condition.value.xpathAssertion.assertions = data;
emit('change', {
...defaultParamItem,
...condition.value,
assertionBodyType: activeTab.value,
responseFormat: activeResponseFormat.value,
});
if (!isInit) {
emit('change', {
...defaultParamItem,
...condition.value,
assertionBodyType: activeTab.value,
responseFormat: activeResponseFormat.value,
});
}
break;
case ResponseBodyAssertionType.DOCUMENT:
condition.value.documentAssertion.jsonAssertion = data;
break;
case ResponseBodyAssertionType.REGEX:
condition.value.regexAssertion.assertions = data;
emit('change', { ...defaultParamItem, ...condition.value, assertionBodyType: activeTab.value });
if (!isInit) {
emit('change', { ...defaultParamItem, ...condition.value, assertionBodyType: activeTab.value });
}
break;
default:
break;
@ -627,17 +628,17 @@
* 提取参数表格-应用更多设置
*/
function applyMoreSetting(record: ExpressionConfig) {
// condition.value.extractParams = condition.value.extractParams?.map((e) => {
// if (e.id === activeRecord.value.id) {
// record.moreSettingPopoverVisible = false;
// return {
// ...activeRecord.value,
// moreSettingPopoverVisible: false,
// } as any; // TOOD:
// }
// return e;
// });
// emit('change');
condition.value.jsonPathAssertion.assertions = condition.value.jsonPathAssertion.assertions?.map((e) => {
if (e.id === activeRecord.value.id) {
record.moreSettingPopoverVisible = false;
return {
...activeRecord.value,
moreSettingPopoverVisible: false,
} as any; // TOOD:
}
return e;
});
handleChange(condition.value.assertion, condition.value.assertion);
}
/**
@ -655,30 +656,81 @@
});
fastExtractionVisible.value = false;
nextTick(() => {
extractParamsTableRef.value?.addTableLine(
condition.value.jsonPathAssertion.assertions?.findIndex((e) => e.id === activeRecord.value.id) || 0
);
if (activeTab.value === ResponseBodyAssertionType.JSON_PATH) {
extractParamsTableRef.value?.addTableLine(
condition.value.jsonPathAssertion.assertions?.findIndex((e) => e.id === activeRecord.value.id) || 0
);
}
if (activeTab.value === ResponseBodyAssertionType.XPATH) {
extractParamsTableRef.value?.addTableLine(
condition.value.xpathAssertion.assertions?.findIndex((e) => e.id === activeRecord.value.id) || 0
);
}
if (activeTab.value === ResponseBodyAssertionType.REGEX) {
extractParamsTableRef.value?.addTableLine(
condition.value.xpathAssertion.regexAssertion?.findIndex((e) => e.id === activeRecord.value.id) || 0
);
}
});
emit('change', { ...condition.value });
}
function copyItem(record) {
switch (activeTab.value) {
case ResponseBodyAssertionType.JSON_PATH:
const index = condition.value.jsonPathAssertion.assertions.findIndex((item) => item.id === record.id);
if (index > -1) {
condition.value.jsonPathAssertion.assertions.splice(index, 0, {
...record,
id: new Date().getTime().toString(),
});
emit('change', { ...condition.value, assertionBodyType: activeTab.value });
}
break;
case ResponseBodyAssertionType.XPATH:
condition.value.xpathAssertion.assertions.push({
...record,
id: new Date().getTime().toString(),
});
emit('change', {
...defaultParamItem,
...condition.value,
assertionBodyType: activeTab.value,
responseFormat: activeResponseFormat.value,
});
break;
case ResponseBodyAssertionType.DOCUMENT:
condition.value.documentAssertion.jsonAssertion.push({
...record,
id: new Date().getTime().toString(),
});
break;
case ResponseBodyAssertionType.REGEX:
condition.value.regexAssertion.assertions.push({
...record,
id: new Date().getTime().toString(),
});
emit('change', { ...defaultParamItem, ...condition.value, assertionBodyType: activeTab.value });
break;
default:
break;
}
}
/**
* 处理提取参数表格更多操作
*/
function handleExtractParamMoreActionSelect(event: ActionsItem, record: ExpressionConfig) {
activeRecord.value = { ...record };
if (event.eventTag === 'copy') {
emit('copy');
copyItem(record);
} else if (event.eventTag === 'setting') {
record.moreSettingPopoverVisible = true;
}
}
/**
* 复制列表项
*/
function copyListItem() {}
/**
* 删除列表项
*/
@ -785,10 +837,4 @@
const handleScriptChange = (data: ExecuteConditionProcessor) => {
condition.value.script = data;
};
// XML
function changeHandler(value: string | number | boolean, type: string) {
if (value === condition.value.responseFormat) {
handleChange([], type);
}
}
</script>

View File

@ -290,9 +290,9 @@
responseFormat: 'XML',
assertions: [],
},
// regexAssertion: {
// assertions: [],
// },
regexAssertion: {
assertions: [],
},
bodyAssertionDataByType: {},
});
break;

View File

@ -358,7 +358,7 @@
<div class="flex flex-row items-center" :class="{ 'justify-end': columnConfig.align === 'right' }">
<a-switch
v-if="columnConfig.hasDisable"
v-model:model-value="record.disable"
v-model:model-value="record.enable"
size="small"
type="line"
class="mr-[8px]"