Skip to content

Commit ac20bd7

Browse files
feat: User input parameters and interface parameters support adjusting the order(#2103)
1 parent f7c0eed commit ac20bd7

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

ui/src/workflow/nodes/base-node/component/ApiInputFieldTable.vue

+31-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
<el-icon class="mr-4">
66
<Plus />
77
</el-icon>
8-
{{$t('common.add')}}
8+
{{ $t('common.add') }}
99
</el-button>
1010
</div>
1111
<el-table
1212
v-if="props.nodeModel.properties.api_input_field_list?.length > 0"
1313
:data="props.nodeModel.properties.api_input_field_list"
1414
class="mb-16"
15+
ref="tableRef"
16+
row-key="field"
1517
>
1618
<el-table-column prop="variable" :label="$t('dynamicsForm.paramForm.field.label')" />
1719
<el-table-column prop="default_value" :label="$t('dynamicsForm.default.label')" />
@@ -48,11 +50,13 @@
4850
<script setup lang="ts">
4951
import { onMounted, ref } from 'vue'
5052
import { set } from 'lodash'
53+
import Sortable from 'sortablejs'
5154
import ApiFieldFormDialog from './ApiFieldFormDialog.vue'
5255
import { MsgError } from '@/utils/message'
5356
import { t } from '@/locales'
54-
const props = defineProps<{ nodeModel: any }>()
5557
58+
const props = defineProps<{ nodeModel: any }>()
59+
const tableRef = ref()
5660
const currentIndex = ref(null)
5761
const ApiFieldFormDialogRef = ref()
5862
const inputFieldList = ref<any[]>([])
@@ -67,6 +71,7 @@ function openAddDialog(data?: any, index?: any) {
6771
function deleteField(index: any) {
6872
inputFieldList.value.splice(index, 1)
6973
props.nodeModel.graphModel.eventCenter.emit('refreshFieldList')
74+
onDragHandel()
7075
}
7176
7277
function refreshFieldList(data: any) {
@@ -92,6 +97,30 @@ function refreshFieldList(data: any) {
9297
currentIndex.value = null
9398
ApiFieldFormDialogRef.value.close()
9499
props.nodeModel.graphModel.eventCenter.emit('refreshFieldList')
100+
onDragHandel()
101+
}
102+
103+
function onDragHandel() {
104+
if (!tableRef.value) return
105+
106+
// 获取表格的 tbody DOM 元素
107+
const wrapper = tableRef.value.$el as HTMLElement
108+
const tbody = wrapper.querySelector('.el-table__body-wrapper tbody')
109+
if (!tbody) return
110+
// 初始化 Sortable
111+
Sortable.create(tbody, {
112+
animation: 150,
113+
ghostClass: 'ghost-row',
114+
onEnd: (evt) => {
115+
if (evt.oldIndex === undefined || evt.newIndex === undefined) return
116+
// 更新数据顺序
117+
const items = [...inputFieldList.value]
118+
const [movedItem] = items.splice(evt.oldIndex, 1)
119+
items.splice(evt.newIndex, 0, movedItem)
120+
inputFieldList.value = items
121+
props.nodeModel.graphModel.eventCenter.emit('refreshFieldList')
122+
}
123+
})
95124
}
96125
97126
onMounted(() => {

ui/src/workflow/nodes/base-node/component/UserInputFieldTable.vue

+5-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
:data="props.nodeModel.properties.user_input_field_list"
2323
class="mb-16"
2424
ref="tableRef"
25+
row-key="field"
2526
>
2627
<el-table-column prop="field" :label="$t('dynamicsForm.paramForm.field.label')" width="95">
2728
<template #default="{ row }">
@@ -132,7 +133,7 @@ function openChangeTitleDialog() {
132133
function deleteField(index: any) {
133134
inputFieldList.value.splice(index, 1)
134135
props.nodeModel.graphModel.eventCenter.emit('refreshFieldList')
135-
ondragHandel()
136+
onDragHandel()
136137
}
137138
138139
function refreshFieldList(data: any, index: any) {
@@ -157,7 +158,7 @@ function refreshFieldList(data: any, index: any) {
157158
}
158159
UserFieldFormDialogRef.value.close()
159160
props.nodeModel.graphModel.eventCenter.emit('refreshFieldList')
160-
ondragHandel()
161+
onDragHandel()
161162
}
162163
163164
function refreshFieldTitle(data: any) {
@@ -183,28 +184,24 @@ const getDefaultValue = (row: any) => {
183184
}
184185
}
185186
186-
function ondragHandel() {
187+
function onDragHandel() {
187188
if (!tableRef.value) return
188189
189190
// 获取表格的 tbody DOM 元素
190191
const wrapper = tableRef.value.$el as HTMLElement
191192
const tbody = wrapper.querySelector('.el-table__body-wrapper tbody')
192193
if (!tbody) return
193-
console.log(tbody)
194194
// 初始化 Sortable
195195
Sortable.create(tbody, {
196196
animation: 150,
197197
ghostClass: 'ghost-row',
198198
onEnd: (evt) => {
199199
if (evt.oldIndex === undefined || evt.newIndex === undefined) return
200-
console.log(inputFieldList.value)
201200
// 更新数据顺序
202201
const items = [...inputFieldList.value]
203202
const [movedItem] = items.splice(evt.oldIndex, 1)
204203
items.splice(evt.newIndex, 0, movedItem)
205204
inputFieldList.value = items
206-
console.log(inputFieldList.value)
207-
// set(props.nodeModel.properties, 'user_input_field_list', inputFieldList.value)
208205
props.nodeModel.graphModel.eventCenter.emit('refreshFieldList')
209206
}
210207
})
@@ -243,7 +240,7 @@ onMounted(() => {
243240
})
244241
set(props.nodeModel.properties, 'user_input_field_list', inputFieldList)
245242
set(props.nodeModel.properties, 'user_input_config', inputFieldConfig)
246-
ondragHandel()
243+
onDragHandel()
247244
})
248245
</script>
249246

0 commit comments

Comments
 (0)