Skip to content

Commit a125ed4

Browse files
authored
[frontend] 修复switch类型inputparam的默认值设置问题 (#508)
1 parent 76b85a8 commit a125ed4

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

frontend/src/pages/chatPreview/components/send-editor/components/conversation-configuration.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const ConversationConfiguration = ({ appInfo, updateUserContext, chatRunning, is
109109
/>
110110
);
111111
case 'switch':
112-
return <Switch onChange={updateData} checked={!!value}/>;
112+
return <Switch onChange={updateData} />;
113113
case 'dropdown':
114114
return (
115115
<Select
@@ -195,7 +195,9 @@ const ConversationConfiguration = ({ appInfo, updateUserContext, chatRunning, is
195195
const preItem = preConfigurationList.current.find(it => it.name === item.name);
196196
const isChangeType = preItem?.type !== item.type;
197197
if (item.type === 'Boolean') {
198-
form.setFieldValue(item.name, isChangeType ? false : (form.getFieldValue(item.name) || false));
198+
const existingValue = form.getFieldValue(item.name);
199+
const defaultValue = item.value ?? false;
200+
form.setFieldValue(item.name, isChangeType ? defaultValue : (existingValue ?? defaultValue));
199201
} else {
200202
form.setFieldValue(item.name, isChangeType ? null : ((isInputEmpty(form.getFieldValue(item.name)) ? null : form.getFieldValue(item.name))));
201203
}
@@ -264,24 +266,33 @@ const ConversationConfiguration = ({ appInfo, updateUserContext, chatRunning, is
264266
<>
265267
<div className='configuration-header'>
266268
<span className='configuration-title'>{t('conversationConfiguration')}</span>
267-
<img src={CloseImg} alt="" onClick={() => setOpen(false)} />
269+
<img src={CloseImg} alt='' onClick={() => setOpen(false)} />
268270
</div>
269271
<div className='configuration-content'>
270-
{
271-
configurationList?.length > 0 ? <Form form={form} autoComplete='off'>
272-
{
273-
configurationList.map(config =>
274-
<Form.Item
275-
key={config.id}
276-
name={config.name}
277-
label={config.displayName || ' '}
278-
className={config.isRequired ? 'is-required' : ''}>
279-
{getConfigurationItem({...config, value: form.getFieldValue(config.value)})}
280-
</Form.Item>
281-
)
282-
}
283-
</Form> : <Empty description={t('noData')}></Empty>
284-
}
272+
{configurationList?.length > 0 ? (
273+
<Form
274+
form={form}
275+
autoComplete='off'
276+
>
277+
{configurationList.map((config) => (
278+
<Form.Item
279+
key={config.id}
280+
name={config.name}
281+
label={config.displayName || ' '}
282+
className={config.isRequired ? 'is-required' : ''}
283+
valuePropName={
284+
config.type === 'Boolean' || config.appearance?.displayType === 'switch'
285+
? 'checked'
286+
: 'value'
287+
}
288+
>
289+
{getConfigurationItem({ ...config, value: form.getFieldValue(config.name) })}
290+
</Form.Item>
291+
))}
292+
</Form>
293+
) : (
294+
<Empty description={t('noData')}></Empty>
295+
)}
285296
</div>
286297
</>
287298
);

frontend/src/pages/configForm/configUi/components/add-input-param.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ const InputParamModal = (props) => {
115115
}
116116

117117
setShowModal(false);
118-
form.resetFields();
119118
onSubmit(transformed);
120119
} catch (error) {
121120
console.log('验证失败:', error);
@@ -124,7 +123,6 @@ const InputParamModal = (props) => {
124123

125124
const handleCancel = () => {
126125
setShowModal(false);
127-
form.resetFields();
128126
};
129127

130128
const handleFieldTypeChange = (value) => {
@@ -264,7 +262,12 @@ const InputParamModal = (props) => {
264262
case 'switch':
265263
return (
266264
<>
267-
<Form.Item label={t('defaultValue')} name='defaultValue'>
265+
<Form.Item
266+
label={t('defaultValue')}
267+
name='defaultValue'
268+
valuePropName="checked"
269+
initialValue={false}
270+
>
268271
<Switch />
269272
</Form.Item>
270273
</>
@@ -374,7 +377,7 @@ const InputParamModal = (props) => {
374377

375378
return (
376379
<Modal
377-
title={mode === 'edit' ? '编辑变量' : '添加变量'}
380+
title={mode === 'edit' ? t('editParamField') : t('addParamField')}
378381
open={showModal}
379382
onCancel={handleCancel}
380383
width={480}

0 commit comments

Comments
 (0)