Skip to content

Commit

Permalink
perf(component): formItem: label支持函数渲染 (vbenjs#3504)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and WitMiao committed Jan 23, 2024
1 parent 99c8190 commit 79b3914
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/components/Form/src/components/FormItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
isShow = isShow && itemIsAdvanced;
return { isShow, isIfShow };
}
function handleRules(): ValidationRule[] {
const {
rules: defRules = [],
Expand All @@ -179,7 +178,7 @@
const joinLabel = Reflect.has(props.schema, 'rulesMessageJoinLabel')
? rulesMessageJoinLabel
: globalRulesMessageJoinLabel;
const assertLabel = joinLabel ? label : '';
const assertLabel = joinLabel ? (isFunction(label) ? '' : label) : '';
const defaultMsg = component
? createPlaceholderMessage(component) + assertLabel
: assertLabel;
Expand Down Expand Up @@ -337,12 +336,13 @@
function renderLabelHelpMessage() {
const { label, helpMessage, helpComponentProps, subLabel } = props.schema;
const getLabel = isFunction(label) ? label(unref(getValues)) : label;
const renderLabel = subLabel ? (
<span>
{label} <span class="text-secondary">{subLabel}</span>
{getLabel} <span class="text-secondary">{subLabel}</span>
</span>
) : (
label
getLabel
);
const getHelpMessage = isFunction(helpMessage)
? helpMessage(unref(getValues))
Expand Down Expand Up @@ -385,8 +385,8 @@
return slot
? getSlot(slots, slot, unref(getValues), opts)
: render
? render(unref(getValues), opts)
: renderComponent();
? render(unref(getValues), opts)
: renderComponent();
};
const showSuffix = !!suffix;
Expand Down Expand Up @@ -437,8 +437,8 @@
return colSlot
? getSlot(slots, colSlot, values, opts)
: renderColContent
? renderColContent(values, opts)
: renderItem();
? renderColContent(values, opts)
: renderItem();
};
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ interface BaseFormSchema<T extends ComponentType = any> {
// Variable name bound to v-model Default value
valueField?: string;
// Label name
label?: string | VNode;
label?: string | VNode | ((renderCallbackParams: RenderCallbackParams) => string | VNode);
// Auxiliary text
subLabel?: string;
// Help text on the right side of the text
Expand Down
4 changes: 3 additions & 1 deletion src/views/demo/form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@
{
field: 'field1',
component: 'Input',
label: '字段1',
label: ({ model }) => {
return `字段1${model.field3 ? model.field3 : ''}`;
},
colProps: {
span: 8,
Expand Down

0 comments on commit 79b3914

Please sign in to comment.