Skip to content

Commit 596b137

Browse files
feat: function field form support sort
1 parent e7c3169 commit 596b137

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

ui/src/views/function-lib/component/FunctionFormDrawer.vue

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
<el-icon class="mr-4"><Plus /></el-icon> {{ $t('common.add') }}
117117
</el-button>
118118
</div>
119-
<el-table :data="form.init_field_list" class="mb-16">
119+
<el-table ref="initFieldTableRef" :data="form.init_field_list" class="mb-16">
120120
<el-table-column prop="field" :label="$t('dynamicsForm.paramForm.field.label')">
121121
<template #default="{ row }">
122122
<span :title="row.field" class="ellipsis-1">{{ row.field }}</span>
@@ -188,7 +188,7 @@
188188
</el-button>
189189
</div>
190190

191-
<el-table :data="form.input_field_list" class="mb-16">
191+
<el-table ref="inputFieldTableRef" :data="form.input_field_list" class="mb-16">
192192
<el-table-column
193193
prop="name"
194194
:label="$t('views.functionLib.functionForm.form.paramName.label')"
@@ -280,7 +280,7 @@
280280
</template>
281281

282282
<script setup lang="ts">
283-
import { ref, reactive, watch } from 'vue'
283+
import { ref, reactive, watch, nextTick } from 'vue'
284284
import FieldFormDialog from './FieldFormDialog.vue'
285285
import FunctionDebugDrawer from './FunctionDebugDrawer.vue'
286286
import type { functionLibData } from '@/api/type/function-lib'
@@ -293,6 +293,7 @@ import { t } from '@/locales'
293293
import UserFieldFormDialog from '@/workflow/nodes/base-node/component/UserFieldFormDialog.vue'
294294
import { isAppIcon } from '@/utils/application'
295295
import EditAvatarDialog from './EditAvatarDialog.vue'
296+
import Sortable from 'sortablejs'
296297
297298
const props = defineProps({
298299
title: String
@@ -303,6 +304,8 @@ const FieldFormDialogRef = ref()
303304
const FunctionDebugDrawerRef = ref()
304305
const UserFieldFormDialogRef = ref()
305306
const EditAvatarDialogRef = ref()
307+
const initFieldTableRef = ref()
308+
const inputFieldTableRef = ref()
306309
307310
const FormRef = ref()
308311
@@ -358,6 +361,40 @@ const rules = reactive({
358361
]
359362
})
360363
364+
function onDragHandle() {
365+
// For init_field_list table
366+
if (initFieldTableRef.value) {
367+
const el = initFieldTableRef.value.$el.querySelector('.el-table__body-wrapper tbody')
368+
Sortable.create(el, {
369+
animation: 150,
370+
ghostClass: 'sortable-ghost',
371+
onEnd: ({ newIndex, oldIndex }) => {
372+
if (newIndex === undefined || oldIndex === undefined) return
373+
if (newIndex !== oldIndex) {
374+
const item = form.value.init_field_list?.splice(oldIndex, 1)[0]
375+
form.value.init_field_list?.splice(newIndex, 0, item)
376+
}
377+
}
378+
})
379+
}
380+
381+
// For input_field_list table
382+
if (inputFieldTableRef.value) {
383+
const el = inputFieldTableRef.value.$el.querySelector('.el-table__body-wrapper tbody')
384+
Sortable.create(el, {
385+
animation: 150,
386+
ghostClass: 'sortable-ghost',
387+
onEnd: ({ newIndex, oldIndex }) => {
388+
if (newIndex === undefined || oldIndex === undefined) return
389+
if (newIndex !== oldIndex) {
390+
const item = form.value.input_field_list?.splice(oldIndex, 1)[0]
391+
form.value.input_field_list?.splice(newIndex, 0, item)
392+
}
393+
}
394+
})
395+
}
396+
}
397+
361398
function submitCodemirrorEditor(val: string) {
362399
form.value.code = val
363400
}
@@ -471,6 +508,9 @@ const open = (data: any) => {
471508
visible.value = true
472509
setTimeout(() => {
473510
showEditor.value = true
511+
nextTick(() => {
512+
onDragHandle()
513+
})
474514
}, 100)
475515
}
476516

0 commit comments

Comments
 (0)