44 * Licensed under the MIT License. See License.txt in the project root for license information.
55 *--------------------------------------------------------------------------------------------*/
66
7- import { useLayoutEffect , useState } from 'react' ;
8- import { Button , Collapse } from 'antd' ;
9- import { DeleteOutlined , PlusOutlined } from '@ant-design/icons' ;
10- import { useConfigContext , useDispatch , useShapeContext } from '@/components/DefaultRoot.jsx' ;
11- import { v4 as uuidv4 } from 'uuid' ;
7+ import { Radio } from 'antd' ;
8+ import { useDispatch } from '@/components/DefaultRoot.jsx' ;
129import PropTypes from 'prop-types' ;
10+ import SimpleFormWrapper from '@/components/intelligentForm/SimpleFormWrapper.jsx' ;
11+ import ManualCheckFormWrapper from '@/components/manualCheck/ManualCheckFormWrapper.jsx' ;
1312import { useTranslation } from 'react-i18next' ;
14- import { InvokeOutput } from '@/components/common/InvokeOutput.jsx' ;
15- import { IntelligentInputFormItem } from '@/components/intelligentForm/IntelligentInputFormItem.jsx' ;
16- import { JadeCollapse } from '@/components/common/JadeCollapse.jsx' ;
17-
18- const { Panel} = Collapse ;
13+ import { FORM_TYPE } from '@/components/intelligentForm/Consts.js' ;
1914
2015IntelligentFormWrapper . propTypes = {
2116 data : PropTypes . object . isRequired ,
@@ -32,111 +27,34 @@ IntelligentFormWrapper.propTypes = {
3227export default function IntelligentFormWrapper ( { data, shapeStatus} ) {
3328 const { t} = useTranslation ( ) ;
3429 const dispatch = useDispatch ( ) ;
35- const shape = useShapeContext ( ) ;
36- const isConfig = useConfigContext ( ) ;
37- const items = data . converter . entity . inputParams . find (
38- ( item ) => item . name === 'schema'
39- ) ?. value . parameters ;
40- const output = data . converter . entity . outputParams . find ( ( item ) => item . name === 'output' ) ;
41-
42- // items中所有初始都为打开状态
43- const [ openItems , setOpenItems ] = useState ( ( ) => {
44- return isConfig ? items . map ( item => item . id ) : [ ] ;
45- } ) ;
46-
47- // 智能表单节点使用JadeInput,但输出的地方外层需要套一个output,在此处把output注册
48- useLayoutEffect ( ( ) => {
49- shape . page . registerObservable ( {
50- nodeId : shape . id ,
51- observableId : output . id ,
52- value : output . name ,
53- type : output . type ,
54- parentId : undefined ,
55- } ) ;
56- } , [ ] ) ;
5730
58- const outputDataConvert = ( items ) => {
59- const outputData = JSON . parse ( JSON . stringify ( data . converter . entity . outputParams ) ) ; // 手动深度拷贝
60- const outputItem = outputData . find ( ( item ) => item . name === 'output' ) ;
61- if ( outputItem ) {
62- outputItem . value = [ ...items ] ; // 创建新数组
63- }
64- return outputData ;
65- } ;
66-
67- // 添加新元素到 items 数组中,并将其 key 添加到当前展开的面板数组中
68- const addItem = ( ) => {
69- // 智能表单节点入参最大数量为30
70- if ( items . length < 30 ) {
71- const newItemId = 'input_' + uuidv4 ( ) ;
72- if ( isConfig ) {
73- setOpenItems ( [ ...openItems , newItemId ] ) ; // 将新元素 key 添加到 openItems 数组中
74- }
75- dispatch ( { type : 'addParam' , id : newItemId } ) ;
76- }
31+ const changeFormType = ( e ) => {
32+ dispatch ( { type : 'changeFormType' , value : e . target . value } ) ;
7733 } ;
7834
79- const renderAddInputIcon = ( ) => {
80- return ( < >
81- < Button disabled = { shapeStatus . disabled }
82- type = 'text'
83- className = 'icon-button jade-start-add-icon'
84- onClick = { addItem } >
85- < PlusOutlined />
86- </ Button >
87- </ > ) ;
88- } ;
89-
90- const renderDeleteIcon = ( item ) => {
91- return ( < >
92- < Button
93- disabled = { shapeStatus . disabled }
94- type = 'text'
95- className = 'icon-button start-node-delete-icon-button'
96- onClick = { ( ) => handleDelete ( item . id ) } >
97- < DeleteOutlined />
98- </ Button >
99- </ > ) ;
100- } ;
101-
102- const handleDelete = ( itemId ) => {
103- const updatedOpenItems = openItems . filter ( ( key ) => key !== itemId ) ;
104- setOpenItems ( updatedOpenItems ) ;
105- dispatch ( { type : 'deleteParam' , id : itemId } ) ;
35+ const getFormTypeOptions = ( ) => {
36+ return [ { label : t ( 'orchestration' ) , value : FORM_TYPE . ORCHESTRATION } , { label : t ( 'manual' ) , value : FORM_TYPE . MANUAL } ] ;
10637 } ;
10738
10839 return ( < >
10940 < div >
110- < div style = { { display : 'flex' , alignItems : 'center' , marginBottom : '8px' , paddingLeft : '8px' , paddingRight : '4px' , height : '32px' } } >
111- < div className = 'jade-panel-header-font' > { t ( 'formItem' ) } </ div >
112- { renderAddInputIcon ( ) }
41+ < div style = { { fontSize : '16px' , fontFamily : 'Huawei Sans' , fontWeight : 400 , display : 'flex' , paddingBottom : '8px' } } >
42+ < span > { t ( 'type' ) } </ span >
43+ < Radio . Group
44+ value = { data . formType }
45+ onChange = { changeFormType }
46+ options = { getFormTypeOptions ( ) }
47+ buttonStyle = "solid"
48+ style = { { fontFamily : 'Huawei Sans' , paddingLeft : '8px' } }
49+ />
11350 </ div >
114- < JadeCollapse
115- activeKey = { openItems }
116- onChange = { ( keys ) => setOpenItems ( keys ) }
117- style = { { backgroundColor : 'transparent' } } >
118- {
119- items . map ( ( item ) => (
120- < Panel
121- key = { item . id }
122- header = {
123- < div className = "panel-header" >
124- < span className = "jade-panel-header-font" > { item . name } </ span > { /* 显示Name值的元素 */ }
125- { renderDeleteIcon ( item ) }
126- </ div >
127- }
128- className = "jade-panel"
129- style = { { marginBottom : 8 , borderRadius : '8px' , width : '100%' } }
130- forceRender
131- >
132- < div className = { 'jade-custom-panel-content' } >
133- < IntelligentInputFormItem item = { item } items = { items } shapeStatus = { shapeStatus } output = { output } />
134- </ div >
135- </ Panel >
136- ) )
137- }
138- </ JadeCollapse >
139- < InvokeOutput outputData = { outputDataConvert ( items ) } isObservableTree = { false } />
51+ {
52+ data . formType === FORM_TYPE . ORCHESTRATION ? (
53+ < SimpleFormWrapper data = { data } shapeStatus = { shapeStatus } />
54+ ) : (
55+ < ManualCheckFormWrapper data = { data } shapeStatus = { shapeStatus } />
56+ )
57+ }
14058 </ div >
14159 </ > ) ;
14260}
0 commit comments