修正日期区间拆解时数据为null时异常问题/修正validate|validateFields时,未将对象型数据进行转换 (#3096)
* fix: 修正日期区间拆解时数据为null时异常问题 * fix: 修正validate|validateFields时,未将对象型数据进行转换
This commit is contained in:
parent
c315aa9801
commit
a3b9ff04f9
|
|
@ -340,7 +340,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) {
|
||||
|
|
@ -350,7 +351,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[]) {
|
||||
|
|
@ -375,8 +377,7 @@ export function useFormEvents({
|
|||
if (!formEl) 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) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { isArray, isFunction, isObject, isString, isNullOrUnDef } from '/@/utils/is';
|
||||
import { isArray, isFunction, isNotEmpty, isObject, isString, isNullOrUnDef } from '/@/utils/is';
|
||||
import { dateUtil } from '/@/utils/dateUtil';
|
||||
import { unref } from 'vue';
|
||||
import type { Ref, ComputedRef } from 'vue';
|
||||
import type { FormProps, FormSchema } from '../types/form';
|
||||
import { cloneDeep, set } from 'lodash-es';
|
||||
import { cloneDeep, get, set, unset } from 'lodash-es';
|
||||
|
||||
interface UseFormValuesContext {
|
||||
defaultValueRef: Ref<any>;
|
||||
|
|
@ -106,18 +106,22 @@ export function useFormValues({
|
|||
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,4 @@
|
|||
import { isNil } from 'lodash-es';
|
||||
const toString = Object.prototype.toString;
|
||||
|
||||
export function is(val: unknown, type: string) {
|
||||
|
|
@ -16,7 +17,15 @@ 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;
|
||||
}
|
||||
|
|
@ -36,6 +45,8 @@ export function isDate(val: unknown): val is Date {
|
|||
return is(val, 'Date');
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function isNull(val: unknown): val is null {
|
||||
return val === null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue