From fa17d969690ea322efc4fb9c6becc51a546014b3 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Fri, 18 Oct 2024 18:10:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=AB=98=E7=BA=A7=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=8C=BA=E5=88=86=E7=94=A8=E6=88=B7=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E5=92=8C=E6=8E=A5=E5=8F=A3=E4=BC=A0=E5=85=A5=E7=9A=84=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serializers/application_serializers.py | 2 +- ui/src/components/ai-chat/index.vue | 92 ++++++++++++- ui/src/views/application-overview/index.vue | 10 +- .../component/ApiFieldFormDialog.vue | 126 +++++++++++++++++ .../component/ApiInputFieldTable.vue | 122 ++++++++++++++++ ...FormDialog.vue => UserFieldFormDialog.vue} | 14 +- .../component/UserInputFieldTable.vue | 130 ++++++++++++++++++ ui/src/workflow/nodes/base-node/index.vue | 116 +++------------- ui/src/workflow/nodes/start-node/index.vue | 11 +- 9 files changed, 504 insertions(+), 119 deletions(-) create mode 100644 ui/src/workflow/nodes/base-node/component/ApiFieldFormDialog.vue create mode 100644 ui/src/workflow/nodes/base-node/component/ApiInputFieldTable.vue rename ui/src/workflow/nodes/base-node/component/{FieldFormDialog.vue => UserFieldFormDialog.vue} (91%) create mode 100644 ui/src/workflow/nodes/base-node/component/UserInputFieldTable.vue diff --git a/apps/application/serializers/application_serializers.py b/apps/application/serializers/application_serializers.py index 9a68a3e1b..005740b00 100644 --- a/apps/application/serializers/application_serializers.py +++ b/apps/application/serializers/application_serializers.py @@ -264,7 +264,7 @@ class ApplicationSerializer(serializers.Serializer): if work_flow is not None: for node in work_flow.get('nodes', []): if node['id'] == 'base-node': - input_field_list = node.get('properties', {}).get('input_field_list', []) + input_field_list = node.get('properties', {}).get('api_input_field_list', node.get('properties', {}).get('input_field_list', [])) if input_field_list is not None: for field in input_field_list: if field['assignment_method'] == 'api_input' and field['variable'] in params: diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index e88a6e0b6..2c2801b32 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -364,8 +364,47 @@ function handleInputFieldList() { props.data.work_flow?.nodes ?.filter((v: any) => v.id === 'base-node') .map((v: any) => { - inputFieldList.value = v.properties.input_field_list - ? v.properties.input_field_list + inputFieldList.value = v.properties.user_input_field_list + ? v.properties.user_input_field_list + .map((v: any) => { + switch (v.type) { + case 'input': + return { + field: v.variable, + input_type: 'TextInput', + label: v.name, + default_value: default_value[v.variable], + required: v.is_required + } + case 'select': + return { + field: v.variable, + input_type: 'SingleSelect', + label: v.name, + default_value: default_value[v.variable], + required: v.is_required, + option_list: v.optionList.map((o: any) => { + return { key: o, value: o } + }) + } + case 'date': + return { + field: v.variable, + input_type: 'DatePicker', + label: v.name, + default_value: default_value[v.variable], + required: v.is_required, + attrs: { + format: 'YYYY-MM-DD HH:mm:ss', + 'value-format': 'YYYY-MM-DD HH:mm:ss', + type: 'datetime' + } + } + default: + break + } + }) + : v.properties.input_field_list ? v.properties.input_field_list .filter((v: any) => v.assignment_method === 'user_input') .map((v: any) => { switch (v.type) { @@ -405,9 +444,50 @@ function handleInputFieldList() { break } }) - : [] - apiInputFieldList.value = v.properties.input_field_list - ? v.properties.input_field_list + : [] + + apiInputFieldList.value = v.properties.api_input_field_list + ? v.properties.api_input_field_list + .map((v: any) => { + switch (v.type) { + case 'input': + return { + field: v.variable, + input_type: 'TextInput', + label: v.variable, + default_value: default_value[v.variable], + required: v.is_required + } + case 'select': + return { + field: v.variable, + input_type: 'SingleSelect', + label: v.variable, + default_value: default_value[v.variable], + required: v.is_required, + option_list: v.optionList.map((o: any) => { + return { key: o, value: o } + }) + } + case 'date': + return { + field: v.variable, + input_type: 'DatePicker', + label: v.variable, + default_value: default_value[v.variable], + required: v.is_required, + attrs: { + format: 'YYYY-MM-DD HH:mm:ss', + 'value-format': 'YYYY-MM-DD HH:mm:ss', + type: 'datetime' + } + } + default: + break + } + }) + : v.properties.input_field_list + ? v.properties.input_field_list .filter((v: any) => v.assignment_method === 'api_input') .map((v: any) => { switch (v.type) { @@ -447,7 +527,7 @@ function handleInputFieldList() { break } }) - : [] + : [] }) } diff --git a/ui/src/views/application-overview/index.vue b/ui/src/views/application-overview/index.vue index ed576232a..186fa4390 100644 --- a/ui/src/views/application-overview/index.vue +++ b/ui/src/views/application-overview/index.vue @@ -342,7 +342,15 @@ function getDetail() { detail.value.work_flow?.nodes ?.filter((v: any) => v.id === 'base-node') .map((v: any) => { - apiInputParams.value = v.properties.input_field_list + apiInputParams.value = v.properties.api_input_field_list + ? v.properties.api_input_field_list + .map((v: any) => { + return { + name: v.variable, + value: v.default_value + } + }) + : v.properties.input_field_list ? v.properties.input_field_list .filter((v: any) => v.assignment_method === 'api_input') .map((v: any) => { diff --git a/ui/src/workflow/nodes/base-node/component/ApiFieldFormDialog.vue b/ui/src/workflow/nodes/base-node/component/ApiFieldFormDialog.vue new file mode 100644 index 000000000..d57d59d98 --- /dev/null +++ b/ui/src/workflow/nodes/base-node/component/ApiFieldFormDialog.vue @@ -0,0 +1,126 @@ + + + diff --git a/ui/src/workflow/nodes/base-node/component/ApiInputFieldTable.vue b/ui/src/workflow/nodes/base-node/component/ApiInputFieldTable.vue new file mode 100644 index 000000000..b9ec6d5d3 --- /dev/null +++ b/ui/src/workflow/nodes/base-node/component/ApiInputFieldTable.vue @@ -0,0 +1,122 @@ + + + + + + \ No newline at end of file diff --git a/ui/src/workflow/nodes/base-node/component/FieldFormDialog.vue b/ui/src/workflow/nodes/base-node/component/UserFieldFormDialog.vue similarity index 91% rename from ui/src/workflow/nodes/base-node/component/FieldFormDialog.vue rename to ui/src/workflow/nodes/base-node/component/UserFieldFormDialog.vue index 331a9d457..9ac58f798 100644 --- a/ui/src/workflow/nodes/base-node/component/FieldFormDialog.vue +++ b/ui/src/workflow/nodes/base-node/component/UserFieldFormDialog.vue @@ -1,6 +1,6 @@