diff --git a/packages/form/src/Form.vue b/packages/form/src/Form.vue index a750a753..d3a73b04 100644 --- a/packages/form/src/Form.vue +++ b/packages/form/src/Form.vue @@ -22,7 +22,11 @@ :step-active="stepActive" :size="size" @change="changeHandler" - > + > + + @@ -37,12 +41,22 @@ import { setValueByKeyPath } from '@tmagic/utils'; import Container from './containers/Container.vue'; import { getConfig } from './utils/config'; import { initValue } from './utils/form'; -import type { ChangeRecord, ContainerChangeEventData, FormConfig, FormState, FormValue, ValidateError } from './schema'; +import type { + ChangeRecord, + ContainerChangeEventData, + FormConfig, + FormSlots, + FormState, + FormValue, + ValidateError, +} from './schema'; defineOptions({ name: 'MForm', }); +defineSlots(); + const props = withDefaults( defineProps<{ /** 表单配置 */ diff --git a/packages/form/src/containers/Container.vue b/packages/form/src/containers/Container.vue index 7b2db891..9f0ac056 100644 --- a/packages/form/src/containers/Container.vue +++ b/packages/form/src/containers/Container.vue @@ -25,13 +25,15 @@ @@ -179,6 +189,7 @@ import type { ContainerChangeEventData, ContainerCommonConfig, FormItemConfig, + FormSlots, FormState, FormValue, ToolTipConfigType, @@ -192,6 +203,8 @@ defineOptions({ name: 'MFormContainer', }); +defineSlots(); + const props = withDefaults( defineProps<{ /** 表单值 */ diff --git a/packages/form/src/schema.ts b/packages/form/src/schema.ts index 60f3f942..c771644d 100644 --- a/packages/form/src/schema.ts +++ b/packages/form/src/schema.ts @@ -1,3 +1,5 @@ +import type { FormItemConfig } from '@tmagic/form-schema'; + export * from '@tmagic/form-schema'; export interface ValidateError { @@ -14,3 +16,22 @@ export interface ContainerChangeEventData { modifyKey?: string; changeRecords?: ChangeRecord[]; } + +/** 自定义 label slot 的作用域参数 */ +export interface FormLabelSlotProps { + /** 当前表单项配置 */ + config: FormItemConfig; + /** 经处理后的类型 */ + type: string; + /** 经 filterFunction 处理后的 label 文案 */ + text?: string; + /** 完整字段路径(包含父级前缀) */ + prop: string; + /** 经 filterFunction 处理后的最终禁用状态 */ + disabled?: boolean; +} + +/** Form / Container 暴露的具名 slot 定义 */ +export interface FormSlots { + label(_props: FormLabelSlotProps): any; +}