@@ -10,8 +10,10 @@ import {
1010 ProFormText ,
1111 ProTable
1212} from "@ant-design/pro-components" ;
13- import { Button , Popconfirm } from "antd" ;
13+ import { Button , ColorPicker , Popconfirm , Space } from "antd" ;
1414import FlowUtils from "@/components/Flow/utils" ;
15+ import ScriptModal from "@/components/Flow/panel/ScriptModal" ;
16+ import { EyeOutlined } from "@ant-design/icons" ;
1517
1618interface ButtonPanelProps {
1719 id : string ;
@@ -20,12 +22,36 @@ interface ButtonPanelProps {
2022const buttonEventOptions = [
2123 {
2224 label : "保存" ,
23- value : "save "
25+ value : "SAVE "
2426 } ,
2527 {
2628 label : "提交" ,
27- value : "submit"
28- }
29+ value : "SUBMIT"
30+ } ,
31+ {
32+ label : "指定人员提交" ,
33+ value : "SPECIFY_SUBMIT"
34+ } ,
35+ {
36+ label : "驳回" ,
37+ value : "REJECT"
38+ } ,
39+ {
40+ label : "转办" ,
41+ value : "TRANSFER"
42+ } ,
43+ {
44+ label : "撤销" ,
45+ value : "RECALL"
46+ } ,
47+ {
48+ label : "延期" ,
49+ value : "POSTPONED"
50+ } ,
51+ {
52+ label : "自定义" ,
53+ value : "CUSTOM"
54+ } ,
2955]
3056
3157
@@ -35,8 +61,14 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
3561
3662 const [ form ] = ProForm . useForm ( ) ;
3763
64+ const [ groovyForm ] = ProForm . useForm ( ) ;
65+
3866 const [ visible , setVisible ] = React . useState ( false ) ;
3967
68+ const [ scriptVisible , setScriptVisible ] = React . useState ( false ) ;
69+
70+ const [ type , setType ] = React . useState < string > ( ) ;
71+
4072 const columns = [
4173 {
4274 title : 'id' ,
@@ -51,17 +83,19 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
5183 } ,
5284 {
5385 title : '事件类型' ,
54- dataIndex : 'event ' ,
55- key : 'event ' ,
86+ dataIndex : 'type ' ,
87+ key : 'type ' ,
5688 render : ( value : string ) => {
5789 return buttonEventOptions . find ( ( item : any ) => item . value == value ) ?. label ;
5890 }
5991 } ,
6092 {
6193 title : '按钮颜色' ,
62- dataIndex : 'color' ,
63- valueType : 'color' ,
64- key : 'color' ,
94+ dataIndex : 'style' ,
95+ key : 'style' ,
96+ render : ( _ : any , record : any ) => {
97+ return < ColorPicker value = { record . style . color } disabled = { true } /> ;
98+ }
6599 } ,
66100 {
67101 title : '排序' ,
@@ -78,6 +112,7 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
78112 onClick = { ( ) => {
79113 form . resetFields ( ) ;
80114 form . setFieldsValue ( record ) ;
115+ setType ( record . type ) ;
81116 setVisible ( true ) ;
82117 } }
83118 >
@@ -141,15 +176,16 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
141176 } }
142177 onFinish = { async ( values ) => {
143178 FlowUtils . updateButton ( props . id , values ) ;
144- actionRef . current ?. reload ( ) ;
145179 setVisible ( false ) ;
180+ actionRef . current ?. reload ( ) ;
146181 } }
147182 >
148183 < ProFormText
149184 name = { "id" }
150185 hidden = { true }
151186 />
152187
188+
153189 < ProFormText
154190 name = { "name" }
155191 label = { "按钮名称" }
@@ -162,40 +198,86 @@ const ButtonPanel: React.FC<ButtonPanelProps> = (props) => {
162198 ] }
163199 />
164200
165- < ProFormSelect
166- name = { "event" }
167- label = { "按钮类型" }
168- placeholder = { "请输入按钮类型" }
201+ < ProFormColorPicker
202+ name = { "style" }
203+ label = { "按钮颜色" }
204+ normalize = { ( value ) => {
205+ return {
206+ color : value . toHexString ( )
207+ } ;
208+ } }
209+ getValueProps = { ( value ) => {
210+ const color = value ?. color ;
211+ if ( color ) {
212+ return {
213+ value : color
214+ }
215+ }
216+ return value ;
217+ } }
218+ placeholder = { "请选择按钮颜色" }
169219 rules = { [
170220 {
171221 required : true ,
172- message : '请输入按钮类型 '
222+ message : '请选择按钮颜色 '
173223 }
174224 ] }
175- options = { buttonEventOptions }
176225 />
177226
178- < ProFormColorPicker
179- name = { "color" }
180- label = { "按钮颜色" }
181- normalize = { ( value ) => {
182- return value . toHexString ( ) ;
183- } }
184- placeholder = { "请选择按钮颜色" }
227+ < ProFormSelect
228+ name = { "type" }
229+ label = { (
230+ < Space >
231+ 按钮类型
232+
233+ { type === 'CUSTOM' && (
234+ < EyeOutlined
235+ onClick = { ( ) => {
236+ groovyForm . resetFields ( ) ;
237+ const script = form . getFieldValue ( 'groovy' ) || 'def run(content){\n // 你的代码\n \n}' ;
238+ groovyForm . setFieldsValue ( {
239+ 'script' : script
240+ } ) ;
241+ setScriptVisible ( ! scriptVisible ) ;
242+ } } />
243+ ) }
244+
245+ </ Space >
246+ ) }
247+ placeholder = { "请输入按钮类型" }
185248 rules = { [
186249 {
187250 required : true ,
188- message : '请选择按钮颜色 '
251+ message : '请输入按钮类型 '
189252 }
190253 ] }
254+ options = { buttonEventOptions }
255+ onChange = { ( value :string ) => {
256+ setType ( value ) ;
257+ } }
191258 />
192259
260+ < ProFormText
261+ name = { "groovy" }
262+ hidden = { true }
263+ />
264+
265+ < ScriptModal
266+ onFinish = { ( values ) => {
267+ form . setFieldsValue ( {
268+ 'groovy' : values . script
269+ } ) ;
270+ } }
271+ form = { groovyForm }
272+ setVisible = { setScriptVisible }
273+ visible = { scriptVisible } />
274+
193275 < ProFormDigit
194276 name = { "order" }
195277 label = { "排序" }
196278 min = { 0 }
197279 fieldProps = { {
198- step :1
280+ step : 1
199281 } }
200282 placeholder = { "请输入排序" }
201283 rules = { [
0 commit comments