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

View File

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

View File

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