mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-11-30 22:42:09 +08:00
feat(form): fieldset中checkbox新增name,trueValue,falseValue配置
This commit is contained in:
parent
630301bce2
commit
51e9732894
@ -2,10 +2,10 @@
|
|||||||
<fieldset v-if="name ? model[name] : model" class="m-fieldset" :style="show ? 'padding: 15px' : 'border: 0'">
|
<fieldset v-if="name ? model[name] : model" class="m-fieldset" :style="show ? 'padding: 15px' : 'border: 0'">
|
||||||
<component v-if="name && config.checkbox" :is="!show ? 'div' : 'legend'">
|
<component v-if="name && config.checkbox" :is="!show ? 'div' : 'legend'">
|
||||||
<TMagicCheckbox
|
<TMagicCheckbox
|
||||||
:model-value="model[name].value"
|
:model-value="(name ? model[name] : model)[checkboxName]"
|
||||||
:prop="`${prop}${prop ? '.' : ''}${config.name}.value`"
|
:prop="`${prop}${prop ? '.' : ''}${config.name}.${checkboxName}`"
|
||||||
:true-value="1"
|
:true-value="checkboxTrueValue"
|
||||||
:false-value="0"
|
:false-value="checkboxFalseValue"
|
||||||
@update:modelValue="valueChangeHandler"
|
@update:modelValue="valueChangeHandler"
|
||||||
><span v-html="config.legend"></span><span v-if="config.extra" v-html="config.extra" class="m-form-tip"></span
|
><span v-html="config.legend"></span><span v-if="config.extra" v-html="config.extra" class="m-form-tip"></span
|
||||||
></TMagicCheckbox>
|
></TMagicCheckbox>
|
||||||
@ -99,9 +99,33 @@ const mForm = inject<FormState | undefined>('mForm');
|
|||||||
|
|
||||||
const name = computed(() => props.config.name || '');
|
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(() => {
|
const show = computed(() => {
|
||||||
if (props.config.expand && name.value) {
|
if (props.config.expand && checkboxName.value) {
|
||||||
return props.model[name.value]?.value;
|
return (name.value ? props.model[name.value] : props.model)?.[checkboxName.value] === checkboxTrueValue.value;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -114,7 +138,7 @@ const lWidth = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const valueChangeHandler = (value: number | boolean) => {
|
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);
|
const changeHandler = (v: any, eventData: ContainerChangeEventData) => emit('change', v, eventData);
|
||||||
|
|||||||
@ -90,8 +90,13 @@ const setValue = (mForm: FormState | undefined, value: FormValue, initValue: For
|
|||||||
|
|
||||||
// 如果fieldset配置checkbox,checkbox的值保存在value中
|
// 如果fieldset配置checkbox,checkbox的值保存在value中
|
||||||
if (type === 'fieldset' && checkbox) {
|
if (type === 'fieldset' && checkbox) {
|
||||||
if (typeof value[name] === 'object') {
|
const checkboxName = typeof checkbox === 'object' && typeof checkbox.name === 'string' ? checkbox.name : 'value';
|
||||||
value[name].value = typeof initValue[name] === 'object' ? initValue[name].value || 0 : 0;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user