From f97f541f308ee9fbd54e92d0b5d86f9897d121d7 Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 27 Apr 2023 12:57:17 +0800 Subject: [PATCH] fix: use form --- src/components/Form/src/hooks/useAdvanced.ts | 3 +-- src/components/Form/src/hooks/useFormEvents.ts | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/Form/src/hooks/useAdvanced.ts b/src/components/Form/src/hooks/useAdvanced.ts index a80d264a..18c422ef 100644 --- a/src/components/Form/src/hooks/useAdvanced.ts +++ b/src/components/Form/src/hooks/useAdvanced.ts @@ -1,8 +1,7 @@ import type { ColEx } from '../types' import type { AdvanceState } from '../types/hooks' -import { ComputedRef, getCurrentInstance, Ref, shallowReactive } from 'vue' +import { ComputedRef, getCurrentInstance, Ref, shallowReactive, computed, unref, watch } from 'vue' import type { FormProps, FormSchema } from '../types/form' -import { computed, unref, watch } from 'vue' import { isBoolean, isFunction, isNumber, isObject } from '@/utils/is' import { useBreakpoint } from '@/hooks/event/useBreakpoint' import { useDebounceFn } from '@vueuse/core' diff --git a/src/components/Form/src/hooks/useFormEvents.ts b/src/components/Form/src/hooks/useFormEvents.ts index 661ca161..c195aa2c 100644 --- a/src/components/Form/src/hooks/useFormEvents.ts +++ b/src/components/Form/src/hooks/useFormEvents.ts @@ -6,7 +6,7 @@ import { isArray, isFunction, isObject, isString, isDef, isNullOrUnDef, isEmpty import { deepMerge } from '@/utils' import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper' import { dateUtil } from '@/utils/dateUtil' -import { cloneDeep, set, uniqBy } from 'lodash-es' +import { cloneDeep, set, uniqBy, get } from 'lodash-es' import { error } from '@/utils/log' interface UseFormActionContext { @@ -35,7 +35,7 @@ function tryConstructArray(field: string, values: Recordable = {}): any[] | unde set(result, index, values[k.trim()]) }) - return result.length ? result : undefined + return result.filter(Boolean).length ? result : undefined } } } @@ -104,9 +104,8 @@ export function useFormEvents({ const validKeys: string[] = [] fields.forEach((key) => { const schema = unref(getSchema).find((item) => item.field === key) - let value = values[key] - - const hasKey = Reflect.has(values, key) + let value = get(values, key) + const hasKey = !!get(values, key) value = handleInputNumberValue(schema?.component, value) const { componentProps } = schema || {} @@ -157,6 +156,7 @@ export function useFormEvents({ }) validateFields(validKeys).catch((_) => {}) } + /** * @description: Delete based on field name */