Skip to content

Commit 518202a

Browse files
perf: Form node support adjusting the order (#2533)
1 parent f1a1c40 commit 518202a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function refreshFieldList(data: any) {
100100
onDragHandle()
101101
}
102102
103+
// 表格排序拖拽
103104
function onDragHandle() {
104105
if (!tableRef.value) return
105106

ui/src/workflow/nodes/form-node/index.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
class="border"
7070
v-if="form_data.form_field_list.length > 0"
7171
:data="form_data.form_field_list"
72+
ref="tableRef"
73+
row-key="field"
7274
>
7375
<el-table-column
7476
prop="field"
@@ -151,9 +153,11 @@ import { ref, onMounted, computed } from 'vue'
151153
import { input_type_list } from '@/components/dynamics-form/constructor/data'
152154
import { MsgError } from '@/utils/message'
153155
import { set, cloneDeep } from 'lodash'
156+
import Sortable from 'sortablejs'
154157
import { t } from '@/locales'
155158
const props = defineProps<{ nodeModel: any }>()
156159
const formNodeFormRef = ref<FormInstance>()
160+
const tableRef = ref()
157161
const editFormField = (form_field_data: any, field_index: number) => {
158162
const _value = form_data.value.form_field_list.map((item: any, index: number) => {
159163
if (field_index === index) {
@@ -185,6 +189,7 @@ const sync_form_field_list = () => {
185189
]
186190
set(props.nodeModel.properties.config, 'fields', fields)
187191
props.nodeModel.clear_next_node_field(false)
192+
onDragHandle()
188193
}
189194
const addFormCollectRef = ref<InstanceType<typeof AddFormCollect>>()
190195
const editFormCollectRef = ref<InstanceType<typeof EditFormCollect>>()
@@ -243,6 +248,30 @@ const validate = () => {
243248
function submitDialog(val: string) {
244249
set(props.nodeModel.properties.node_data, 'form_content_format', val)
245250
}
251+
252+
// 表格排序拖拽
253+
function onDragHandle() {
254+
if (!tableRef.value) return
255+
256+
// 获取表格的 tbody DOM 元素
257+
const wrapper = tableRef.value.$el as HTMLElement
258+
const tbody = wrapper.querySelector('.el-table__body-wrapper tbody')
259+
if (!tbody) return
260+
// 初始化 Sortable
261+
Sortable.create(tbody as HTMLElement, {
262+
animation: 150,
263+
ghostClass: 'ghost-row',
264+
onEnd: (evt) => {
265+
if (evt.oldIndex === undefined || evt.newIndex === undefined) return
266+
// 更新数据顺序
267+
const items = [...form_data.value.form_field_list]
268+
const [movedItem] = items.splice(evt.oldIndex, 1)
269+
items.splice(evt.newIndex, 0, movedItem)
270+
form_data.value.form_field_list = items
271+
sync_form_field_list()
272+
}
273+
})
274+
}
246275
onMounted(() => {
247276
set(props.nodeModel, 'validate', validate)
248277
sync_form_field_list()

0 commit comments

Comments
 (0)