diff --git a/packages/core/components/Form/src/hooks/useFormValues.ts b/packages/core/components/Form/src/hooks/useFormValues.ts index ba1404715a90d25e47c4234c65caab4a499ba37e..2da93ce8b2dff031886f4a2adf46ffc13cc9a094 100644 --- a/packages/core/components/Form/src/hooks/useFormValues.ts +++ b/packages/core/components/Form/src/hooks/useFormValues.ts @@ -8,7 +8,7 @@ import { dateUtil } from '@jeesite/core/utils/dateUtil'; import { unref } from 'vue'; import type { Ref, ComputedRef } from 'vue'; import type { FormProps, FormSchema } from '../types/form'; -import { set } from 'lodash-es'; +import { isNil, set } from 'lodash-es'; interface UseFormValuesContext { defaultValueRef: Ref; @@ -82,10 +82,20 @@ export function useFormValues({ defaultValueRef, getSchema, formModel, getProps const schemas = unref(getSchema); const obj: Recordable = {}; schemas.forEach((item) => { - const { defaultValue = '' } = item; - if (!isNullOrUnDef(defaultValue)) { + const { defaultValue, componentProps = {} } = item; + // Add a type assertion to allow defaultValue on componentProps + const props = componentProps as { defaultValue?: any }; + if (!isNil(defaultValue)) { obj[item.field] = defaultValue; - formModel[item.field] = defaultValue; + if (formModel[item.field] === undefined) { + formModel[item.field] = defaultValue; + } + } + if (!isNil(props.defaultValue)) { + obj[item.field] = props.defaultValue; + if (formModel[item.field] === undefined) { + formModel[item.field] = props.defaultValue; + } } }); defaultValueRef.value = obj;