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