perf(component): formItem: label支持函数渲染 (#3504)
* perf(component): formItem: label支持函数渲染 (cherry picked from commit abd6e2b1298712e58cc69cdaa55f44e3393b71a5) * perf(component): formItem: label支持函数渲染 * feat(component): formItem: label支持函数渲染 * perf(component): formItem: label支持函数渲染 (cherry picked from commit abd6e2b1298712e58cc69cdaa55f44e3393b71a5) perf(component): formItem: label支持函数渲染 feat(component): formItem: label支持函数渲染 * chore: update label type --------- Co-authored-by: likui628 <90845831+likui628@users.noreply.github.com>
This commit is contained in:
parent
b750fc9e51
commit
e6a7e4c4fc
|
|
@ -159,7 +159,6 @@
|
||||||
isShow = isShow && itemIsAdvanced;
|
isShow = isShow && itemIsAdvanced;
|
||||||
return { isShow, isIfShow };
|
return { isShow, isIfShow };
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRules(): ValidationRule[] {
|
function handleRules(): ValidationRule[] {
|
||||||
const {
|
const {
|
||||||
rules: defRules = [],
|
rules: defRules = [],
|
||||||
|
|
@ -179,7 +178,7 @@
|
||||||
const joinLabel = Reflect.has(props.schema, 'rulesMessageJoinLabel')
|
const joinLabel = Reflect.has(props.schema, 'rulesMessageJoinLabel')
|
||||||
? rulesMessageJoinLabel
|
? rulesMessageJoinLabel
|
||||||
: globalRulesMessageJoinLabel;
|
: globalRulesMessageJoinLabel;
|
||||||
const assertLabel = joinLabel ? label : '';
|
const assertLabel = joinLabel ? (isFunction(label) ? '' : label) : '';
|
||||||
const defaultMsg = component
|
const defaultMsg = component
|
||||||
? createPlaceholderMessage(component) + assertLabel
|
? createPlaceholderMessage(component) + assertLabel
|
||||||
: assertLabel;
|
: assertLabel;
|
||||||
|
|
@ -337,12 +336,13 @@
|
||||||
|
|
||||||
function renderLabelHelpMessage() {
|
function renderLabelHelpMessage() {
|
||||||
const { label, helpMessage, helpComponentProps, subLabel } = props.schema;
|
const { label, helpMessage, helpComponentProps, subLabel } = props.schema;
|
||||||
|
const getLabel = isFunction(label) ? label(unref(getValues)) : label;
|
||||||
const renderLabel = subLabel ? (
|
const renderLabel = subLabel ? (
|
||||||
<span>
|
<span>
|
||||||
{label} <span class="text-secondary">{subLabel}</span>
|
{getLabel} <span class="text-secondary">{subLabel}</span>
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
label
|
getLabel
|
||||||
);
|
);
|
||||||
const getHelpMessage = isFunction(helpMessage)
|
const getHelpMessage = isFunction(helpMessage)
|
||||||
? helpMessage(unref(getValues))
|
? helpMessage(unref(getValues))
|
||||||
|
|
@ -385,8 +385,8 @@
|
||||||
return slot
|
return slot
|
||||||
? getSlot(slots, slot, unref(getValues), opts)
|
? getSlot(slots, slot, unref(getValues), opts)
|
||||||
: render
|
: render
|
||||||
? render(unref(getValues), opts)
|
? render(unref(getValues), opts)
|
||||||
: renderComponent();
|
: renderComponent();
|
||||||
};
|
};
|
||||||
|
|
||||||
const showSuffix = !!suffix;
|
const showSuffix = !!suffix;
|
||||||
|
|
@ -437,8 +437,8 @@
|
||||||
return colSlot
|
return colSlot
|
||||||
? getSlot(slots, colSlot, values, opts)
|
? getSlot(slots, colSlot, values, opts)
|
||||||
: renderColContent
|
: renderColContent
|
||||||
? renderColContent(values, opts)
|
? renderColContent(values, opts)
|
||||||
: renderItem();
|
: renderItem();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ interface BaseFormSchema<T extends ComponentType = any> {
|
||||||
// Variable name bound to v-model Default value
|
// Variable name bound to v-model Default value
|
||||||
valueField?: string;
|
valueField?: string;
|
||||||
// Label name
|
// Label name
|
||||||
label?: string | VNode;
|
label?: string | VNode | ((renderCallbackParams: RenderCallbackParams) => string | VNode);
|
||||||
// Auxiliary text
|
// Auxiliary text
|
||||||
subLabel?: string;
|
subLabel?: string;
|
||||||
// Help text on the right side of the text
|
// Help text on the right side of the text
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,9 @@
|
||||||
{
|
{
|
||||||
field: 'field1',
|
field: 'field1',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
label: '字段1',
|
label: ({ model }) => {
|
||||||
|
return `字段1${model.field3 ? model.field3 : ''}`;
|
||||||
|
},
|
||||||
|
|
||||||
colProps: {
|
colProps: {
|
||||||
span: 8,
|
span: 8,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue