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