From 69cebe8f7ff03183773caf079956f4930eb6e7c5 Mon Sep 17 00:00:00 2001 From: wangdan-fit2cloud Date: Mon, 7 Apr 2025 17:57:11 +0800 Subject: [PATCH] feat: The workflow condition node supports drag and drop sorting --- ui/package.json | 4 +- ui/src/components/index.ts | 1 - .../workflow/nodes/condition-node/index.vue | 261 ++++++++++-------- 3 files changed, 146 insertions(+), 120 deletions(-) diff --git a/ui/package.json b/ui/package.json index 861163bd6d5..cee7a41c8fd 100644 --- a/ui/package.json +++ b/ui/package.json @@ -50,9 +50,11 @@ "vue-clipboard3": "^2.0.0", "vue-codemirror": "^6.1.1", "vue-demi": "latest", + "vue-draggable-plus": "^0.6.0", "vue-i18n": "^9.13.1", "vue-router": "^4.2.4", - "vue3-menus": "^1.1.2" + "vue3-menus": "^1.1.2", + "vuedraggable": "^4.1.0" }, "devDependencies": { "@rushstack/eslint-patch": "^1.3.2", diff --git a/ui/src/components/index.ts b/ui/src/components/index.ts index 4cf9df91329..5fe7bf8194c 100644 --- a/ui/src/components/index.ts +++ b/ui/src/components/index.ts @@ -25,7 +25,6 @@ import LogoIcon from './logo/LogoIcon.vue' import SendIcon from './logo/SendIcon.vue' import CodemirrorEditor from './codemirror-editor/index.vue' import ModelSelect from './model-select/index.vue' - export default { install(app: App) { app.component(AppIcon.name, AppIcon) diff --git a/ui/src/workflow/nodes/condition-node/index.vue b/ui/src/workflow/nodes/condition-node/index.vue index fdda27de243..a775c83eb66 100644 --- a/ui/src/workflow/nodes/condition-node/index.vue +++ b/ui/src/workflow/nodes/condition-node/index.vue @@ -8,130 +8,144 @@ ref="ConditionNodeFormRef" @submit.prevent > - + {{ $t('views.applicationWorkflow.nodes.conditionNode.addBranch') }} @@ -147,6 +161,7 @@ import type { FormInstance } from 'element-plus' import { ref, computed, onMounted, nextTick } from 'vue' import { randomId } from '@/utils/utils' import { compareList } from '@/workflow/common/data' +import { type DraggableEvent, type UseDraggableReturn, VueDraggable } from 'vue-draggable-plus' const props = defineProps<{ nodeModel: any }>() const form = { @@ -223,6 +238,16 @@ const validate = () => { }) } +function onEnd(evt: DraggableEvent) { + const { oldIndex, newIndex, clonedData } = evt + if (oldIndex === undefined || newIndex === undefined) return + const list = cloneDeep(props.nodeModel.properties.node_data.branch) + + list[newIndex].type = list[oldIndex].type + list[oldIndex].type = clonedData.type // 恢复原始 type + set(props.nodeModel.properties.node_data, 'branch', list) +} + function addBranch() { const list = cloneDeep(props.nodeModel.properties.node_data.branch) const obj = {