Parcourir la source

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

Co-authored-by: bingguo <bingguo@gaoding.com>
wangxiaoer5200 il y a 3 ans
Parent
commit
2423aeab64

+ 2 - 0
src/components/Form/src/helper.ts

@@ -70,3 +70,5 @@ export function handleInputNumberValue(component?: ComponentType, val?: any) {
  * 时间字段
  * 时间字段
  */
  */
 export const dateItemType = genType();
 export const dateItemType = genType();
+
+export const defaultValueComponents = ['Input', 'InputPassword', 'InputSearch', 'InputTextArea'];

+ 4 - 2
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 { unref, toRaw, nextTick } from 'vue';
 import { isArray, isFunction, isObject, isString } from '/@/utils/is';
 import { isArray, isFunction, isObject, isString } from '/@/utils/is';
 import { deepMerge } from '/@/utils';
 import { deepMerge } from '/@/utils';
-import { dateItemType, handleInputNumberValue } from '../helper';
+import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper';
 import { dateUtil } from '/@/utils/dateUtil';
 import { dateUtil } from '/@/utils/dateUtil';
 import { cloneDeep, uniqBy } from 'lodash-es';
 import { cloneDeep, uniqBy } from 'lodash-es';
 import { error } from '/@/utils/log';
 import { error } from '/@/utils/log';
@@ -37,7 +37,9 @@ export function useFormEvents({
     if (!formEl) return;
     if (!formEl) return;
 
 
     Object.keys(formModel).forEach((key) => {
     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());
     nextTick(() => clearValidate());