Commit 2423aeab640b218712717b0329f881f8add654dc

Authored by wangxiaoer5200
Committed by GitHub
1 parent 1a431422

fix: 修复表单重置某些input类型组件不生效问题,close #1519 (#1526)

Co-authored-by: bingguo <bingguo@gaoding.com>
src/components/Form/src/helper.ts
... ... @@ -70,3 +70,5 @@ export function handleInputNumberValue(component?: ComponentType, val?: any) {
70 70 * 时间字段
71 71 */
72 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 &#39;ant-design-vue/lib/form/interface&#39;;
4 4 import { unref, toRaw, nextTick } from 'vue';
5 5 import { isArray, isFunction, isObject, isString } from '/@/utils/is';
6 6 import { deepMerge } from '/@/utils';
7   -import { dateItemType, handleInputNumberValue } from '../helper';
  7 +import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper';
8 8 import { dateUtil } from '/@/utils/dateUtil';
9 9 import { cloneDeep, uniqBy } from 'lodash-es';
10 10 import { error } from '/@/utils/log';
... ... @@ -37,7 +37,9 @@ export function useFormEvents({
37 37 if (!formEl) return;
38 38  
39 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 44 nextTick(() => clearValidate());
43 45  
... ...