Commit 0bb3b7f90d6ef08cd8f171a474f92bd0562ac961
Committed by
GitHub
1 parent
87ee7cd2
fix: 修复频繁调用_setDefaultValue方法,设置初始值的时候,多次调用失效的问题 (#2431)
Co-authored-by: huangwentao <huangwentao@dianchu.com>
Showing
1 changed file
with
12 additions
and
2 deletions
src/components/Form/src/hooks/useFormEvents.ts
... | ... | @@ -2,7 +2,15 @@ import type { ComputedRef, Ref } from 'vue'; |
2 | 2 | import type { FormProps, FormSchema, FormActionType } from '../types/form'; |
3 | 3 | import type { NamePath } from 'ant-design-vue/lib/form/interface'; |
4 | 4 | import { unref, toRaw, nextTick } from 'vue'; |
5 | -import { isArray, isFunction, isObject, isString, isDef, isNullOrUnDef } from '/@/utils/is'; | |
5 | +import { | |
6 | + isArray, | |
7 | + isFunction, | |
8 | + isObject, | |
9 | + isString, | |
10 | + isDef, | |
11 | + isNullOrUnDef, | |
12 | + isEmpty, | |
13 | +} from '/@/utils/is'; | |
6 | 14 | import { deepMerge } from '/@/utils'; |
7 | 15 | import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper'; |
8 | 16 | import { dateUtil } from '/@/utils/dateUtil'; |
... | ... | @@ -237,7 +245,9 @@ export function useFormEvents({ |
237 | 245 | Reflect.has(item, 'field') && |
238 | 246 | item.field && |
239 | 247 | !isNullOrUnDef(item.defaultValue) && |
240 | - !(item.field in currentFieldsValue) | |
248 | + (!(item.field in currentFieldsValue) || | |
249 | + isNullOrUnDef(currentFieldsValue[item.field]) || | |
250 | + isEmpty(currentFieldsValue[item.field])) | |
241 | 251 | ) { |
242 | 252 | obj[item.field] = item.defaultValue; |
243 | 253 | } |
... | ... |