fix: 修正日期区间拆解时数据为null时异常问题
parent
781f7c9cd1
commit
3a84c319dc
|
@ -56,8 +56,8 @@ const getdataSource = computed(() => {
|
|||
}, [] as TransferItem[])
|
||||
})
|
||||
const getTargetKeys = computed<string[]>(() => {
|
||||
if (unref(_targetKeys).length > 0)
|
||||
return unref(_targetKeys)
|
||||
// if (unref(_targetKeys).length > 0)
|
||||
// return unref(_targetKeys)
|
||||
|
||||
if (Array.isArray(props.value))
|
||||
return props.value
|
||||
|
|
|
@ -346,7 +346,8 @@ export function useFormEvents({
|
|||
}
|
||||
|
||||
async function validateFields(nameList?: NamePath[] | undefined) {
|
||||
return unref(formElRef)?.validateFields(nameList)
|
||||
const values = unref(formElRef)?.validateFields(nameList)
|
||||
return handleFormValues(values)
|
||||
}
|
||||
|
||||
async function validate(nameList?: NamePath[] | false | undefined) {
|
||||
|
@ -357,7 +358,8 @@ export function useFormEvents({
|
|||
else
|
||||
_nameList = nameList === Array.isArray(nameList) ? nameList : undefined
|
||||
|
||||
return await unref(formElRef)?.validate(_nameList)
|
||||
const values = await unref(formElRef)?.validate(_nameList)
|
||||
return handleFormValues(values)
|
||||
}
|
||||
|
||||
async function clearValidate(name?: string | string[]) {
|
||||
|
@ -383,8 +385,7 @@ export function useFormEvents({
|
|||
return
|
||||
try {
|
||||
const values = await validate()
|
||||
const res = handleFormValues(values)
|
||||
emit('submit', res)
|
||||
emit('submit', values)
|
||||
}
|
||||
catch (error: any) {
|
||||
if (error?.outOfDate === false && error?.errorFields)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { unref } from 'vue'
|
||||
import type { ComputedRef, Ref } from 'vue'
|
||||
import { cloneDeep, set } from 'lodash-es'
|
||||
import { cloneDeep, get, set, unset } from 'lodash-es'
|
||||
import type { FormProps, FormSchema } from '../types/form'
|
||||
import { dateUtil } from '@/utils/dateUtil'
|
||||
import { isArray, isFunction, isNullOrUnDef, isObject, isString } from '@/utils/is'
|
||||
import { isArray, isFunction, isNotEmpty, isNullOrUnDef, isObject, isString } from '@/utils/is'
|
||||
|
||||
interface UseFormValuesContext {
|
||||
defaultValueRef: Ref<any>
|
||||
|
@ -98,18 +98,22 @@ export function useFormValues({ defaultValueRef, getSchema, formModel, getProps
|
|||
continue
|
||||
|
||||
// If the value to be converted is empty, remove the field
|
||||
if (!values[field]) {
|
||||
Reflect.deleteProperty(values, field)
|
||||
if (!get(values, field)) {
|
||||
unset(values, field)
|
||||
continue
|
||||
}
|
||||
|
||||
const [startTime, endTime]: string[] = values[field]
|
||||
const [startTime, endTime]: string[] = get(values, field)
|
||||
|
||||
const [startTimeFormat, endTimeFormat] = Array.isArray(format) ? format : [format, format]
|
||||
|
||||
values[startTimeKey] = formatTime(startTime, startTimeFormat)
|
||||
values[endTimeKey] = formatTime(endTime, endTimeFormat)
|
||||
Reflect.deleteProperty(values, field)
|
||||
if (isNotEmpty(startTime))
|
||||
set(values, startTimeKey, formatTime(startTime, startTimeFormat))
|
||||
|
||||
if (isNotEmpty(endTime))
|
||||
set(values, endTimeKey, formatTime(endTime, endTimeFormat))
|
||||
|
||||
unset(values, field)
|
||||
}
|
||||
|
||||
return values
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { isNil } from 'lodash-es'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
const toString = Object.prototype.toString
|
||||
|
||||
|
@ -17,7 +19,14 @@ export function isObject(val: any): val is Record<any, any> {
|
|||
return val !== null && is(val, 'Object')
|
||||
}
|
||||
|
||||
export function isNotEmpty(val: any): boolean {
|
||||
return !isNil(val) && !isEmpty(val)
|
||||
}
|
||||
|
||||
export function isEmpty<T = unknown>(val: T): val is T {
|
||||
if (isNil(val))
|
||||
return true
|
||||
|
||||
if (isArray(val) || isString(val))
|
||||
return val.length === 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue