From 2423aeab640b218712717b0329f881f8add654dc Mon Sep 17 00:00:00 2001 From: wangxiaoer5200 <38752239+wangxiaoer5200@users.noreply.github.com> Date: Tue, 28 Dec 2021 18:46:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E6=9F=90=E4=BA=9Binput=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8Cclose=20#1519=20(#1526)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: bingguo --- src/components/Form/src/helper.ts | 2 ++ src/components/Form/src/hooks/useFormEvents.ts | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Form/src/helper.ts b/src/components/Form/src/helper.ts index 5a4595ac..d0727f38 100644 --- a/src/components/Form/src/helper.ts +++ b/src/components/Form/src/helper.ts @@ -70,3 +70,5 @@ export function handleInputNumberValue(component?: ComponentType, val?: any) { * 时间字段 */ export const dateItemType = genType(); + +export const defaultValueComponents = ['Input', 'InputPassword', 'InputSearch', 'InputTextArea']; diff --git a/src/components/Form/src/hooks/useFormEvents.ts b/src/components/Form/src/hooks/useFormEvents.ts index be012382..1d80120c 100644 --- a/src/components/Form/src/hooks/useFormEvents.ts +++ b/src/components/Form/src/hooks/useFormEvents.ts @@ -4,7 +4,7 @@ import type { NamePath } from 'ant-design-vue/lib/form/interface'; import { unref, toRaw, nextTick } from 'vue'; import { isArray, isFunction, isObject, isString } from '/@/utils/is'; import { deepMerge } from '/@/utils'; -import { dateItemType, handleInputNumberValue } from '../helper'; +import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper'; import { dateUtil } from '/@/utils/dateUtil'; import { cloneDeep, uniqBy } from 'lodash-es'; import { error } from '/@/utils/log'; @@ -37,7 +37,9 @@ export function useFormEvents({ if (!formEl) return; Object.keys(formModel).forEach((key) => { - formModel[key] = defaultValueRef.value[key]; + const schema = unref(getSchema).find((item) => item.field === key); + const isInput = schema?.component && defaultValueComponents.includes(schema.component); + formModel[key] = isInput ? defaultValueRef.value[key] || '' : defaultValueRef.value[key]; }); nextTick(() => clearValidate()); -- GitLab