feat: expose custom auto form slot

This commit is contained in:
zernonia 2024-04-20 11:00:54 +08:00
parent baa83ecec8
commit 9769d10209

View File

@ -45,6 +45,20 @@ const shapes = computed(() => {
return val
})
const fields = computed(() => {
// @ts-expect-error ignore {} not assignable to object
const val: { [key in keyof z.infer<T>]: { shape: Shape, fieldName: string, config: ConfigItem } } = {}
for (const key in shapes.value) {
const shape = shapes.value[key]
val[key as keyof z.infer<T>] = {
shape,
config: props.fieldConfig?.[key] as ConfigItem,
fieldName: key,
}
}
return val
})
const formComponent = computed(() => props.form ? 'form' : Form)
const formComponentProps = computed(() => {
if (props.form) {
@ -68,6 +82,7 @@ const formComponentProps = computed(() => {
:is="formComponent"
v-bind="formComponentProps"
>
<slot name="customAutoForm" :fields="fields">
<template v-for="(shape, key) of shapes" :key="key">
<slot
:shape="shape"
@ -82,6 +97,7 @@ const formComponentProps = computed(() => {
/>
</slot>
</template>
</slot>
<slot :shapes="shapes" />
</component>