1
- import { list , save , del } from '@/services/api/table' ;
1
+ import { list , save , del , resort } from '@/services/api/table' ;
2
2
import { PlusOutlined } from '@ant-design/icons' ;
3
3
import type { ActionType , ProColumns } from '@ant-design/pro-components' ;
4
- import { ModalForm , PageContainer , ProFormSelect , ProFormText , ProTable } from '@ant-design/pro-components' ;
4
+ import { ModalForm , PageContainer , ProFormSelect , ProFormText , ProFormDigit } from '@ant-design/pro-components' ;
5
5
import { Button , Form , message , Popconfirm } from 'antd' ;
6
- import { MyTable } from 'coding-components ' ;
6
+ import { MyTable } from './MyTable ' ;
7
7
import React , { useRef , useState } from 'react' ;
8
8
9
9
const TablePage : React . FC = ( ) => {
@@ -50,20 +50,24 @@ const TablePage: React.FC = () => {
50
50
dataIndex : 'id' ,
51
51
sorter : true ,
52
52
search : false ,
53
+ width : 100 ,
53
54
} ,
54
55
{
55
56
title : "服务名称" ,
56
57
dataIndex : 'name' ,
57
58
sorter : true ,
59
+ width : 100 ,
58
60
} ,
59
61
{
60
62
title : "地址" ,
61
63
dataIndex : 'url' ,
62
64
search : false ,
65
+ width : 100 ,
63
66
} ,
64
67
{
65
68
title : "状态" ,
66
69
dataIndex : 'state' ,
70
+ width : 100 ,
67
71
filters : [
68
72
{
69
73
text : '禁用' ,
@@ -85,10 +89,17 @@ const TablePage: React.FC = () => {
85
89
} ,
86
90
} ,
87
91
} ,
92
+ {
93
+ title : "排序" ,
94
+ dataIndex : 'sort' ,
95
+ search : false ,
96
+ width : 100 ,
97
+ } ,
88
98
{
89
99
title : "操作" ,
90
100
dataIndex : 'option' ,
91
101
valueType : 'option' ,
102
+ width : 100 ,
92
103
render : ( _ , record ) => [
93
104
< a
94
105
key = "config"
@@ -123,9 +134,23 @@ const TablePage: React.FC = () => {
123
134
return (
124
135
< PageContainer >
125
136
< MyTable
137
+ sortable = { true }
138
+ dragSortKey = "id"
139
+ onDragSortEnd = {
140
+ async ( beforeIndex : number , afterIndex : number , oldDataSource : any [ ] , newDataSource : any [ ] , rowKey : string ) => {
141
+ console . log ( beforeIndex , afterIndex , oldDataSource , newDataSource , rowKey ) ;
142
+ const beforeId = oldDataSource [ beforeIndex ] [ rowKey ] ;
143
+ const afterId = oldDataSource [ afterIndex ] [ rowKey ] ;
144
+ const body = {
145
+ beforeId : beforeId ,
146
+ afterId : afterId ,
147
+ } ;
148
+ resort ( body )
149
+ }
150
+ }
126
151
headerTitle = "服务节点配置"
127
152
actionRef = { actionRef }
128
- rowKey = "key "
153
+ rowKey = "id "
129
154
toolBarRender = { ( ) => [
130
155
< Button
131
156
type = "primary"
@@ -138,7 +163,6 @@ const TablePage: React.FC = () => {
138
163
</ Button > ,
139
164
] }
140
165
request = { async ( params , sort , filter ) => {
141
- console . log ( params , sort , filter ) ;
142
166
const res = await list ( {
143
167
...params ,
144
168
sort : Buffer . from ( JSON . stringify ( sort ) ) . toString ( 'base64' ) ,
@@ -225,6 +249,18 @@ const TablePage: React.FC = () => {
225
249
] }
226
250
name = "state"
227
251
/>
252
+
253
+ < ProFormDigit
254
+ label = "排序"
255
+ rules = { [
256
+ {
257
+ required : true ,
258
+ message : "请输入排序" ,
259
+ } ,
260
+ ] }
261
+ placeholder = "请输入排序"
262
+ name = "sort" />
263
+
228
264
</ ModalForm >
229
265
230
266
</ PageContainer >
0 commit comments