1
1
import React from "react" ;
2
- import { ActionType , ProColumns , ProForm , ProTable } from "@ant-design/pro-components" ;
3
- import { Button , ColorPicker , Modal , Popconfirm , Space } from "antd" ;
2
+ import { ActionType , ModalForm , ProColumns , ProForm , ProFormText , ProTable } from "@ant-design/pro-components" ;
3
+ import { Button , ColorPicker , Popconfirm , Space } from "antd" ;
4
4
import FlowUtils from "@/components/flow/utils" ;
5
5
import ScriptModal from "@/components/flow/nodes/panel/ScriptModal" ;
6
6
import { EyeOutlined } from "@ant-design/icons" ;
7
7
import FlowContext from "@/components/flow/domain/FlowContext" ;
8
- import Form , { FormAction } from "@/components/form" ;
9
8
import FormInput from "@/components/form/input" ;
10
9
import ValidateUtils from "@/components/form/utils" ;
11
10
import FormSelect from "@/components/form/select" ;
@@ -19,9 +18,9 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
19
18
20
19
const actionRef = React . useRef < ActionType > ( ) ;
21
20
22
- const formAction = React . useRef < FormAction > ( null ) ;
21
+ const [ form ] = ProForm . useForm ( ) ;
22
+ const [ groovyForm ] = ProForm . useForm ( ) ;
23
23
24
- const groovyFormAction = React . useRef < FormAction > ( null ) ;
25
24
26
25
const [ visible , setVisible ] = React . useState ( false ) ;
27
26
@@ -72,8 +71,8 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
72
71
< a
73
72
key = { "edit" }
74
73
onClick = { ( ) => {
75
- groovyFormAction . current ?. reset ( ) ;
76
- groovyFormAction . current ? .setFieldsValue ( record ) ;
74
+ groovyForm . resetFields ( ) ;
75
+ form . setFieldsValue ( record ) ;
77
76
setType ( record . type ) ;
78
77
setVisible ( true ) ;
79
78
} }
@@ -115,113 +114,120 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
115
114
< Button
116
115
type = { "primary" }
117
116
onClick = { ( ) => {
118
- groovyFormAction . current ?. reset ( ) ;
117
+ groovyForm . resetFields ( ) ;
119
118
setVisible ( true ) ;
120
119
} }
121
120
> 添加按钮</ Button >
122
121
]
123
122
} }
124
123
/>
125
124
126
- < Modal
125
+ < ModalForm
127
126
title = { "添加节点按钮" }
128
127
open = { visible }
129
- onCancel = { ( ) => { setVisible ( false ) } }
130
- onOk = { ( ) => {
131
- const values = formAction . current ?. getFieldsValue ( ) ;
132
- flowContext . getFlowPanelContext ( ) ?. updateButton ( props . id , values ) ;
128
+ form = { form }
129
+ onFinish = { async ( values ) => {
130
+ flowContext . getFlowPanelContext ( ) ?. updateButton ( props . id , values as any ) ;
133
131
setVisible ( false ) ;
134
132
actionRef . current ?. reload ( ) ;
135
133
} }
136
- destroyOnClose = { true }
134
+ modalProps = { {
135
+ onCancel : ( ) => {
136
+ setVisible ( false ) ;
137
+ } ,
138
+ onClose :( ) => {
139
+ setVisible ( false ) ;
140
+ } ,
141
+ destroyOnClose :true
142
+ } }
137
143
>
138
- < Form
139
- actionRef = { formAction }
140
- layout = { "vertical" }
141
- >
142
- < FormInput
143
- name = { "id" }
144
- hidden = { true }
145
- />
146
-
147
- < FormInput
148
- name = { "name" }
149
- label = { "按钮名称" }
150
- placeholder = { "请输入按钮名称" }
151
- required = { true }
152
- validateFunction = { ValidateUtils . validateNotEmpty }
153
- />
154
-
155
- < FormColor
156
- name = { [ "style" , "background" ] }
157
- label = { "按钮颜色" }
158
- placeholder = { "请输入按钮颜色" }
159
- required = { true }
160
- validateFunction = { ValidateUtils . validateNotEmpty }
161
- />
162
-
163
- < FormSelect
164
- name = { "type" }
165
- label = { (
166
- < Space >
167
- 按钮类型
168
-
169
- { type === 'CUSTOM' && (
170
- < EyeOutlined
171
- onClick = { ( ) => {
172
- groovyFormAction . current ?. reset ( ) ;
173
- const script = groovyFormAction . current ?. getFieldValue ( 'groovy' ) || 'def run(content){\n //你的代码 \n return content.createMessageResult(\'我是自定义标题\');\n}' ;
174
- groovyFormAction . current ?. setFieldsValue ( {
175
- 'script' : script
176
- } ) ;
177
- setScriptVisible ( ! scriptVisible ) ;
178
- } } />
179
- ) }
180
-
181
- </ Space >
182
- ) }
183
- placeholder = { "请输入按钮类型" }
184
- required = { true }
185
- options = { flowContext . getFlowPanelContext ( ) ?. getButtonEventOptions ( ) }
186
- onChange = { ( value : string ) => {
187
- setType ( value ) ;
188
- } }
189
- />
190
-
191
- { type === 'VIEW' && (
192
- < FormInput
193
- name = { "eventKey" }
194
- label = { "事件Key" }
195
- help = { "事件Key用于流程Form的事件触发" }
196
- required = { true }
197
- />
144
+ < FormInput
145
+ name = { "id" }
146
+ hidden = { true }
147
+ />
148
+
149
+ < ProFormText
150
+ name = { "name" }
151
+ label = { "按钮名称" }
152
+ placeholder = { "请输入按钮名称" }
153
+ required = { true }
154
+ rules = { [
155
+ {
156
+ required : true ,
157
+ message : '请输入按钮名称' ,
158
+ } ,
159
+ ] }
160
+ />
161
+
162
+ < FormColor
163
+ name = { [ "style" , "background" ] }
164
+ label = { "按钮颜色" }
165
+ placeholder = { "请输入按钮颜色" }
166
+ required = { true }
167
+ validateFunction = { ValidateUtils . validateNotEmpty }
168
+ />
169
+
170
+ < FormSelect
171
+ name = { "type" }
172
+ label = { (
173
+ < Space >
174
+ 按钮类型
175
+
176
+ { type === 'CUSTOM' && (
177
+ < EyeOutlined
178
+ onClick = { ( ) => {
179
+ groovyForm . resetFields ( ) ;
180
+ const script = form . getFieldValue ( 'groovy' ) || 'def run(content){\n //你的代码 \n return content.createMessageResult(\'我是自定义标题\');\n}' ;
181
+ groovyForm . setFieldsValue ( {
182
+ 'script' : script
183
+ } ) ;
184
+ setScriptVisible ( ! scriptVisible ) ;
185
+ } } />
186
+ ) }
187
+
188
+ </ Space >
198
189
) }
190
+ placeholder = { "请输入按钮类型" }
191
+ required = { true }
192
+ options = { flowContext . getFlowPanelContext ( ) ?. getButtonEventOptions ( ) }
193
+ onChange = { ( value : string ) => {
194
+ setType ( value ) ;
195
+ } }
196
+ />
199
197
198
+ { type === 'VIEW' && (
200
199
< FormInput
201
- name = { "groovy" }
202
- hidden = { true }
200
+ name = { "eventKey" }
201
+ label = { "事件Key" }
202
+ help = { "事件Key用于流程Form的事件触发" }
203
+ required = { true }
203
204
/>
205
+ ) }
204
206
205
- < FormInput
206
- name = { "order" }
207
- label = { "排序" }
208
- inputType = { "number" }
209
- placeholder = { "请输入排序" }
210
- />
207
+ < FormInput
208
+ name = { "groovy" }
209
+ hidden = { true }
210
+ />
211
211
212
- </ Form >
212
+ < FormInput
213
+ name = { "order" }
214
+ label = { "排序" }
215
+ inputType = { "number" }
216
+ placeholder = { "请输入排序" }
217
+ />
213
218
214
219
< ScriptModal
215
220
onFinish = { ( values ) => {
216
- groovyFormAction . current ?. setFieldsValue ( {
221
+ console . log ( 'values' , values ) ;
222
+ form . setFieldsValue ( {
217
223
'groovy' : values . script
218
224
} ) ;
219
225
} }
220
- formAction = { groovyFormAction }
226
+ form = { groovyForm }
221
227
setVisible = { setScriptVisible }
222
228
visible = { scriptVisible } />
223
229
224
- </ Modal >
230
+ </ ModalForm >
225
231
</ >
226
232
)
227
233
}
0 commit comments