5
5
<el-icon class =" mr-4" >
6
6
<Plus />
7
7
</el-icon >
8
- {{ $t('common.add')}}
8
+ {{ $t('common.add') }}
9
9
</el-button >
10
10
</div >
11
11
<el-table
12
12
v-if =" props.nodeModel.properties.api_input_field_list?.length > 0"
13
13
:data =" props.nodeModel.properties.api_input_field_list"
14
14
class =" mb-16"
15
+ ref =" tableRef"
16
+ row-key =" field"
15
17
>
16
18
<el-table-column prop =" variable" :label =" $t('dynamicsForm.paramForm.field.label')" />
17
19
<el-table-column prop =" default_value" :label =" $t('dynamicsForm.default.label')" />
48
50
<script setup lang="ts">
49
51
import { onMounted , ref } from ' vue'
50
52
import { set } from ' lodash'
53
+ import Sortable from ' sortablejs'
51
54
import ApiFieldFormDialog from ' ./ApiFieldFormDialog.vue'
52
55
import { MsgError } from ' @/utils/message'
53
56
import { t } from ' @/locales'
54
- const props = defineProps <{ nodeModel: any }>()
55
57
58
+ const props = defineProps <{ nodeModel: any }>()
59
+ const tableRef = ref ()
56
60
const currentIndex = ref (null )
57
61
const ApiFieldFormDialogRef = ref ()
58
62
const inputFieldList = ref <any []>([])
@@ -67,6 +71,7 @@ function openAddDialog(data?: any, index?: any) {
67
71
function deleteField(index : any ) {
68
72
inputFieldList .value .splice (index , 1 )
69
73
props .nodeModel .graphModel .eventCenter .emit (' refreshFieldList' )
74
+ onDragHandel ()
70
75
}
71
76
72
77
function refreshFieldList(data : any ) {
@@ -92,6 +97,30 @@ function refreshFieldList(data: any) {
92
97
currentIndex .value = null
93
98
ApiFieldFormDialogRef .value .close ()
94
99
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
+ })
95
124
}
96
125
97
126
onMounted (() => {
0 commit comments