feat: 为VbenFormProps添加componentEvents,使VbenForm支持自定义组件的自定义事件,简单实现后续优化

pull/50/head^2
chenminjie 2024-11-26 20:14:31 +08:00
parent 2c209d15f2
commit 73e1ae0a4e
2 changed files with 14 additions and 0 deletions

View File

@ -28,6 +28,7 @@ interface Props extends FormSchema {}
const {
commonComponentProps,
component,
componentEvents,
componentProps,
dependencies,
description,
@ -159,6 +160,12 @@ const computedProps = computed(() => {
};
});
const computedEvents = computed(() => {
return isFunction(componentEvents)
? componentEvents(values.value, formApi!)
: componentEvents;
});
watch(
() => computedProps.value?.autofocus,
(value) => {
@ -315,6 +322,7 @@ function autofocus() {
'border-destructive focus:border-destructive hover:border-destructive/80 focus:shadow-[0_0_0_2px_rgba(255,38,5,0.06)]':
isInValid,
}"
v-on="computedEvents"
v-bind="createComponentProps(slotProps)"
:disabled="shouldDisabled"
>

View File

@ -128,6 +128,10 @@ export interface FormItemDependencies {
triggerFields: string[];
}
type ComponentEvents = {
[K: string]: (...args: any[]) => void;
} & Record<string, any>;
type ComponentProps =
| ((
value: Partial<Record<string, any>>,
@ -217,6 +221,8 @@ export interface FormSchema<
> extends FormCommonConfig {
/** 组件 */
component: Component | T;
/** 组件事件 */
componentEvents?: ComponentEvents;
/** 组件参数 */
componentProps?: ComponentProps;
/** 默认值 */