From 6f7e03af4f2c10daf9f68f349feadcb89cc79373 Mon Sep 17 00:00:00 2001 From: "841322557@qq.com" <841322557@qq.com> Date: Wed, 11 Jun 2025 16:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=20=E5=9C=A8componentProps?= =?UTF-8?q?=E4=BC=A0=E9=80=92defaultValue=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Form/src/hooks/useFormValues.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/core/components/Form/src/hooks/useFormValues.ts b/packages/core/components/Form/src/hooks/useFormValues.ts index ba14047..2da93ce 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; -- Gitee