Commit 2423aeab640b218712717b0329f881f8add654dc
Committed by
GitHub
1 parent
1a431422
fix: 修复表单重置某些input类型组件不生效问题,close #1519 (#1526)
Co-authored-by: bingguo <bingguo@gaoding.com>
Showing
2 changed files
with
6 additions
and
2 deletions
src/components/Form/src/helper.ts
@@ -70,3 +70,5 @@ export function handleInputNumberValue(component?: ComponentType, val?: any) { | @@ -70,3 +70,5 @@ export function handleInputNumberValue(component?: ComponentType, val?: any) { | ||
70 | * 时间字段 | 70 | * 时间字段 |
71 | */ | 71 | */ |
72 | export const dateItemType = genType(); | 72 | export const dateItemType = genType(); |
73 | + | ||
74 | +export const defaultValueComponents = ['Input', 'InputPassword', 'InputSearch', 'InputTextArea']; |
src/components/Form/src/hooks/useFormEvents.ts
@@ -4,7 +4,7 @@ import type { NamePath } from 'ant-design-vue/lib/form/interface'; | @@ -4,7 +4,7 @@ import type { NamePath } from 'ant-design-vue/lib/form/interface'; | ||
4 | import { unref, toRaw, nextTick } from 'vue'; | 4 | import { unref, toRaw, nextTick } from 'vue'; |
5 | import { isArray, isFunction, isObject, isString } from '/@/utils/is'; | 5 | import { isArray, isFunction, isObject, isString } from '/@/utils/is'; |
6 | import { deepMerge } from '/@/utils'; | 6 | import { deepMerge } from '/@/utils'; |
7 | -import { dateItemType, handleInputNumberValue } from '../helper'; | 7 | +import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper'; |
8 | import { dateUtil } from '/@/utils/dateUtil'; | 8 | import { dateUtil } from '/@/utils/dateUtil'; |
9 | import { cloneDeep, uniqBy } from 'lodash-es'; | 9 | import { cloneDeep, uniqBy } from 'lodash-es'; |
10 | import { error } from '/@/utils/log'; | 10 | import { error } from '/@/utils/log'; |
@@ -37,7 +37,9 @@ export function useFormEvents({ | @@ -37,7 +37,9 @@ export function useFormEvents({ | ||
37 | if (!formEl) return; | 37 | if (!formEl) return; |
38 | 38 | ||
39 | Object.keys(formModel).forEach((key) => { | 39 | Object.keys(formModel).forEach((key) => { |
40 | - formModel[key] = defaultValueRef.value[key]; | 40 | + const schema = unref(getSchema).find((item) => item.field === key); |
41 | + const isInput = schema?.component && defaultValueComponents.includes(schema.component); | ||
42 | + formModel[key] = isInput ? defaultValueRef.value[key] || '' : defaultValueRef.value[key]; | ||
41 | }); | 43 | }); |
42 | nextTick(() => clearValidate()); | 44 | nextTick(() => clearValidate()); |
43 | 45 |