From 5c7134f6918f336d628ab1f000a92fa08c36e71b Mon Sep 17 00:00:00 2001 From: zhanghao <774378400@qq.com> Date: Wed, 15 Apr 2026 15:30:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/flow.js | 2 +- src/views/flow/components/ParamsDrawer.vue | 168 +++++++++++---------- src/views/flow/index.vue | 30 ++-- src/views/flow/nodes/function/loop.js | 68 +++++---- src/views/flow/nodes/function/loop.vue | 12 +- 5 files changed, 150 insertions(+), 130 deletions(-) diff --git a/src/utils/flow.js b/src/utils/flow.js index fb1372f..28268d5 100644 --- a/src/utils/flow.js +++ b/src/utils/flow.js @@ -109,7 +109,7 @@ export const recursiveFilter = (data, id, type = ['loop', 'customGroup'], result data.forEach((item) => { if (type.includes(item.type) && item.children && item.children.includes(id)) { result.push(item) - recursiveFilter(data, item.id, result) + recursiveFilter(data, item.id, type, result) } }); return result diff --git a/src/views/flow/components/ParamsDrawer.vue b/src/views/flow/components/ParamsDrawer.vue index 86831a9..4fe3502 100644 --- a/src/views/flow/components/ParamsDrawer.vue +++ b/src/views/flow/components/ParamsDrawer.vue @@ -3,11 +3,30 @@ v-model="props.drawer" custom-class="custom-drawer-header" class="no-header-margin" - :title="props.data.properties?.name || '参数配置'" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false" > +
@@ -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(() => { })