Skip to content

Commit d7d6b38

Browse files
authored
[elsa] 智能编排表单节点默认值根据类型渲染为不同的输入形式增强 (#83)
1 parent 23c63e8 commit d7d6b38

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

framework/elsa/fit-elsa-react/src/components/intelligentForm/FormItemRenderType.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export const FormItemRenderType = ({itemId, propValue, disabled, onChange, type}
4040
];
4141
case DATA_TYPES.STRING:
4242
return [
43-
{value: RENDER_TYPE.RADIO, label: RENDER_TYPE.RADIO},
4443
{value: RENDER_TYPE.INPUT, label: RENDER_TYPE.INPUT},
44+
{value: RENDER_TYPE.RADIO, label: RENDER_TYPE.RADIO},
4545
];
4646
default:
4747
return [];

framework/elsa/fit-elsa-react/src/components/intelligentForm/FormItemSelectValue.jsx

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*--------------------------------------------------------------------------------------------*/
66

77
import PropTypes from 'prop-types';
8-
import {Col, Form, Row} from 'antd';
8+
import {Col, Form, InputNumber, Row, Switch} from 'antd';
99
import {useTranslation} from 'react-i18next';
1010
import {JadeInput} from '@/components/common/JadeInput.jsx';
1111
import {DATA_TYPES, FROM_TYPE} from '@/common/Consts.js';
@@ -64,6 +64,47 @@ export const FormItemSelectValue = ({item, shapeStatus, onChange, label, inputRe
6464
}, {key: 'value', value: e.value}, {key: 'type', value: e.type}]);
6565
};
6666

67+
const renderInputValueComponent = (item) => {
68+
switch (item.type) {
69+
case DATA_TYPES.BOOLEAN:
70+
return <Switch
71+
disabled={shapeStatus.disabled}
72+
style={{marginLeft: '8px'}}
73+
onChange={(e) => onInputChange('value', e)}
74+
checked={item.value}/>;
75+
case DATA_TYPES.INTEGER:
76+
return <InputNumber
77+
className="jade-input"
78+
disabled={shapeStatus.disabled}
79+
step={1}
80+
precision={0}
81+
parser={(value) => value.replace(/[^\d-]/g, '')} // 只允许输入整数部分
82+
onChange={(e) => onInputChange('value', e)}
83+
stringMode
84+
value={item.value}
85+
/>;
86+
case DATA_TYPES.NUMBER:
87+
return <InputNumber
88+
className="jade-input"
89+
disabled={shapeStatus.disabled}
90+
step={1}
91+
onChange={(e) => onInputChange('value', e)}
92+
stringMode
93+
value={item.value}
94+
/>;
95+
case DATA_TYPES.STRING:
96+
default:
97+
return <JadeInput
98+
disabled={shapeStatus.disabled}
99+
className="jade-input"
100+
style={{borderRadius: '0px 8px 8px 0px'}}
101+
placeholder={t('plsEnter')}
102+
value={item.type === DATA_TYPES.ARRAY || item.type === DATA_TYPES.OBJECT ? JSON.stringify(item.value) : item.value}
103+
onChange={(e) => onInputChange('value', e)}
104+
/>;
105+
}
106+
};
107+
67108
/* 获取值field. */
68109
const getValueField = () => {
69110
if (item.from === FROM_TYPE.INPUT) {
@@ -76,14 +117,7 @@ export const FormItemSelectValue = ({item, shapeStatus, onChange, label, inputRe
76117
initialValue={item.type === DATA_TYPES.ARRAY || item.type === DATA_TYPES.OBJECT ? JSON.stringify(item.value) : item.value}
77118
validateTrigger='onBlur'
78119
>
79-
<JadeInput
80-
disabled={shapeStatus.disabled}
81-
className='jade-input'
82-
style={{borderRadius: '0px 8px 8px 0px'}}
83-
placeholder={t('plsEnter')}
84-
value={item.type === DATA_TYPES.ARRAY || item.type === DATA_TYPES.OBJECT ? JSON.stringify(item.value) : item.value}
85-
onChange={(e) => onInputChange('value', e)}
86-
/>
120+
{renderInputValueComponent(item)}
87121
</Form.Item>;
88122
} else if (item.from === FROM_TYPE.REFERENCE) {
89123
return <JadeReferenceTreeSelect

framework/elsa/fit-elsa-react/src/components/intelligentForm/IntelligentInputFormItem.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {FormItemName} from '@/components/intelligentForm/FormItemName.jsx';
99
import Type from '@/components/common/Type.jsx';
1010
import React from 'react';
1111
import {useTranslation} from 'react-i18next';
12-
import {useDispatch} from '@/components/DefaultRoot.jsx';
12+
import {useDispatch, useFormContext} from '@/components/DefaultRoot.jsx';
1313
import {FormItemRenderType} from '@/components/intelligentForm/FormItemRenderType.jsx';
1414
import {FormItemSelectValue} from '@/components/intelligentForm/FormItemSelectValue.jsx';
1515
import {RENDER_OPTIONS_TYPE} from '@/components/intelligentForm/Consts.js';
@@ -28,6 +28,7 @@ import {DATA_TYPES, FROM_TYPE} from '@/common/Consts.js';
2828
*/
2929
const _IntelligentInputFormItem = ({item, items, shapeStatus, output}) => {
3030
const dispatch = useDispatch();
31+
const form = useFormContext();
3132
const { t } = useTranslation();
3233

3334
/**
@@ -41,6 +42,8 @@ const _IntelligentInputFormItem = ({item, items, shapeStatus, output}) => {
4142
// 如果 type 是 'type',清空 renderType
4243
if (changes.has('type') && changes.get('type') !== item.type) {
4344
changes.set('renderType', undefined);
45+
changes.set('value', null);
46+
form.setFieldsValue({[`value-${item.id}`]: undefined});
4447
}
4548
dispatch({ type: 'updateParam', id: id, changes });
4649
};

0 commit comments

Comments
 (0)