@@ -787,7 +806,6 @@
-
@@ -818,7 +836,7 @@
@@ -887,7 +905,7 @@
:options="quoteOptions"
placeholder="请选择"
@visible-change="
- (visible) => visibleChange(visible, index, property.quote)
+ (visible) => visibleChange(visible, index, property.quote, 'httpBody')
"
@change="(value) => cascaderChange(value, index, 'httpBody')"
/>
@@ -931,6 +949,11 @@ const props = defineProps({
const emits = defineEmits(['close'])
+const deleteNode = () => {
+ lf.deleteNode(props.data.id);
+ emits('close')
+}
+
const formData = reactive({
inputParams: [],
nodeParams: [],
@@ -955,28 +978,25 @@ const confirm = async () => {
ElMessage.error('JSON中存在错误,请修正后再保存!');
return;
}
- } else {
-
}
const nodeParams = []
nodeParams.push({ name: "config", type: "input", input: "", children: httpNodeData.value.config, disabled: true, required: true })
- console.log('httpNodeData.value:', httpNodeData.value)
if (httpNodeData.value?.headers?.length > 0) {
nodeParams.push({ name: "headers", type: "input", input: "", children: httpNodeData.value.headers, disabled: true, required: true })
}
if (httpNodeData.value?.params?.length > 0) {
nodeParams.push({ name: "params", type: "input", input: "", children: httpNodeData.value.params, disabled: true, required: true })
}
- if (httpNodeData.value.body.type !== 'none') {
- const bodyObj = {
- name: "body", type: "input", input: "", children: [
- { name: 'bodyType', type: "input", input: "json", disabled: true },
- { name: 'json', type: "input", input: editorInstance.getValue() || '' },
- { name: 'formData', type: "input", input: "", children: httpNodeData.value.body.formData }
- ]
- }
- nodeParams.push(bodyObj)
+
+ const bodyObj = {
+ name: "body", type: "input", input: "", children: [
+ { name: 'bodyType', type: "input", input: httpNodeData.value.body.type, disabled: true },
+ { name: 'json', type: "input", input: httpNodeData.value.body.type === 'json' ? editorInstance.getValue() : '' },
+ { name: 'formData', type: "input", input: "", children: httpNodeData.value.body.formData }
+ ]
}
+ nodeParams.push(bodyObj)
+
lf.setProperties(props.data.id, {
...props.data.properties,
nodeParams
@@ -1078,14 +1098,32 @@ const handleDelete = (index) => {
};
const quoteOptions = ref([]);
-const handleTypeChange = (index) => {
- if (formData.nodeParams[index].type === "input") {
- formData.nodeParams[index].quote = "";
+const handleTypeChange = (index, type = 'default') => {
+ if (type === 'default') {
+ if (formData.nodeParams[index].type === "input") {
+ formData.nodeParams[index].quote = "";
+ } else {
+ formData.nodeParams[index].input = "";
+ const option = getInput(props.data.id);
+ if (option) {
+ quoteOptions.value = option;
+ }
+ }
} else {
- formData.nodeParams[index].input = "";
- const option = getInput(props.model.id);
- if (option) {
- quoteOptions.value = option;
+ const bodyItem = formData.nodeParams.find(item => item.name === 'body');
+ if (bodyItem) {
+ const formDataItem = bodyItem.children.find(child => child.name === 'formData');
+ if (formDataItem) {
+ if (formDataItem.children[index].type === "input") {
+ formDataItem.children[index].quote = "";
+ } else {
+ formDataItem.children[index].input = "";
+ const option = getInput(props.data.id);
+ if (option) {
+ quoteOptions.value = option;
+ }
+ }
+ }
}
}
};
@@ -1097,12 +1135,12 @@ const cascaderChange = (value, index, type = 'default') => {
formData.nodeParams[index].quote = value;
formData.nodeParams[index].quoteType = selectedOptions[0].data.type;
} else {
- formData.nodeParams.find(item => item.name === 'body').children.find(child => child.name === 'formData').children[index].quote = value;
- formData.nodeParams.find(item => item.name === 'body').children.find(child => child.name === 'formData').children[index].quoteType = selectedOptions[0].data.type;
+ httpNodeData.value.body.formData[index].quote = value;
+ httpNodeData.value.body.formData[index].quoteType = selectedOptions[0].data.type;
}
};
-const visibleChange = (value, index, quote) => {
+const visibleChange = (value, index, quote = '', type = 'default') => {
if (value) {
const option = getInput(props.data.id);
if (option) {
@@ -1113,15 +1151,21 @@ const visibleChange = (value, index, quote) => {
// 等待DOM更新后再设置值,确保新options已生效
setTimeout(() => {
// 如果当前有选中值,重新设置一次以触发重新匹配
- if (currentValue.length) {
- formData.nodeParams[index].quote = [];
- // 确保响应式更新
- setTimeout(() => {
- formData.nodeParams[index].quote = currentValue;
- }, 0);
+ if (currentValue.length > 0) {
+ if (type === 'default') {
+ formData.nodeParams[index].quote = [];
+ // 确保响应式更新
+ setTimeout(() => {
+ formData.nodeParams[index].quote = currentValue;
+ }, 0);
+ } else {
+ httpNodeData.value.body.formData[index].quote = [];
+ // 确保响应式更新
+ setTimeout(() => {
+ httpNodeData.value.body.formData[index].quote = currentValue;
+ }, 0);
+ }
}
- // 手动触发级联选择器的重新渲染
- // cascaderRefs.value[index].updatePopper();
}, 0);
}
}
@@ -1207,45 +1251,7 @@ watch(
}
);
-const httpMethodOptions = () => {
- return [{
- value: 'POST',
- label: 'POST'
- }, {
- value: 'GET',
- label: 'GET'
- }, {
- value: 'PUT',
- label: 'PUT'
- }, {
- value: 'DELETE',
- label: 'DELETE'
- }, {
- value: 'PATCH',
- label: 'PATCH'
- }]
-}
-
-const httpNodeData = ref({
- // config: [
- // { name: "url", type: "input", input: "", disabled: true, required: true },
- // { name: "method", type: "input", input: "POST", componentType: 'select', selectOptions: httpMethodOptions(), disabled: true },
- // { name: "timeout", type: "input", input: "10000", componentType: 'number', disabled: true }
- // ],
- // headers: [
- // { name: "", type: "input", input: ""}
- // ],
- // params: [
- // { name: "", type: "input", input: ""}
- // ],
- // body: {
- // type: 'json',
- // json: '{}',
- // formData: [
- // { name: "", type: "input", input: ""}
- // ]
- // }
-});
+const httpNodeData = ref({});
const addHttpNodeFormItem = (e, type) => {
e.stopPropagation();
@@ -1268,9 +1274,6 @@ const handleHttpNodeDelete = (type, index) => {
} else {
httpNodeData.value[type].splice(index, 1);
}
- // nextTick(() => {
- // dynamicForm.value?.clearValidate()
- // });
};
watch(
@@ -1300,15 +1303,14 @@ watch(
} else if (props.data.type === 'http') {
const nodeParams = JSON.parse(JSON.stringify(props.data.properties.nodeParams || []))
const transformedData = transformHttpNodeData(nodeParams);
- console.log('transformedData', transformedData);
httpNodeData.value = transformedData;
- if (transformedData.body.type === 'json') {
+ console.log('httpNodeData', httpNodeData.value);
+ if (httpNodeData.value.body.type === 'json') {
setTimeout(() => {
if (editorInstance) {
- setValue(transformedData.body.json || '{}')
+ setValue(httpNodeData.value.body.json || '{}')
}
}, 100)
-
}
}
},
@@ -1323,6 +1325,12 @@ onUnmounted(() => {
})