diff --git a/packages/form/src/containers/Fieldset.vue b/packages/form/src/containers/Fieldset.vue index 5d2cc617..1290582f 100644 --- a/packages/form/src/containers/Fieldset.vue +++ b/packages/form/src/containers/Fieldset.vue @@ -2,10 +2,10 @@
@@ -99,9 +99,33 @@ const mForm = inject('mForm'); const name = computed(() => props.config.name || ''); +const checkboxName = computed(() => { + if (typeof props.config.checkbox === 'object' && typeof props.config.checkbox.name === 'string') { + return props.config.checkbox.name; + } + + return 'value'; +}); + +const checkboxTrueValue = computed(() => { + if (typeof props.config.checkbox === 'object' && typeof props.config.checkbox.trueValue !== 'undefined') { + return props.config.checkbox.trueValue; + } + + return 1; +}); + +const checkboxFalseValue = computed(() => { + if (typeof props.config.checkbox === 'object' && typeof props.config.checkbox.falseValue !== 'undefined') { + return props.config.checkbox.falseValue; + } + + return 0; +}); + const show = computed(() => { - if (props.config.expand && name.value) { - return props.model[name.value]?.value; + if (props.config.expand && checkboxName.value) { + return (name.value ? props.model[name.value] : props.model)?.[checkboxName.value] === checkboxTrueValue.value; } return true; }); @@ -114,7 +138,7 @@ const lWidth = computed(() => { }); const valueChangeHandler = (value: number | boolean) => { - emit('change', value, { modifyKey: 'value' }); + emit('change', value, { modifyKey: checkboxName.value }); }; const changeHandler = (v: any, eventData: ContainerChangeEventData) => emit('change', v, eventData); diff --git a/packages/form/src/utils/form.ts b/packages/form/src/utils/form.ts index 67b29b6c..b763b704 100644 --- a/packages/form/src/utils/form.ts +++ b/packages/form/src/utils/form.ts @@ -90,8 +90,13 @@ const setValue = (mForm: FormState | undefined, value: FormValue, initValue: For // 如果fieldset配置checkbox,checkbox的值保存在value中 if (type === 'fieldset' && checkbox) { - if (typeof value[name] === 'object') { - value[name].value = typeof initValue[name] === 'object' ? initValue[name].value || 0 : 0; + const checkboxName = typeof checkbox === 'object' && typeof checkbox.name === 'string' ? checkbox.name : 'value'; + const checkboxFalseValue = + typeof checkbox === 'object' && typeof checkbox.falseValue !== 'undefined' ? checkbox.falseValue : 0; + + if (name && typeof value[name] === 'object') { + value[name][checkboxName] = + typeof initValue[name] === 'object' ? initValue[name][checkboxName] || checkboxFalseValue : checkboxFalseValue; } } };