fix: form setValues not support `dayjs` and `Date` value (#5064)

* fix: setFormValues not support  `dayjs object` value

* fix: setFormValues not support `Date` value

* chore: remove console log
pull/58/MERGE
Netfan 2024-12-07 11:09:55 +08:00 committed by GitHub
parent 68ab73bdb5
commit b75a8e6a2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -16,3 +16,11 @@ export function formatDate(time: number | string, format = 'YYYY-MM-DD') {
export function formatDateTime(time: number | string) {
return formatDate(time, 'YYYY-MM-DD HH:mm:ss');
}
export function isDate(value: any): value is Date {
return value instanceof Date;
}
export function isDayjsObject(value: any): value is dayjs.Dayjs {
return dayjs.isDayjs(value);
}

View File

@ -14,6 +14,8 @@ import { Store } from '@vben-core/shared/store';
import {
bindMethods,
createMerge,
isDate,
isDayjsObject,
isFunction,
isObject,
mergeWithArrayOverride,
@ -252,10 +254,19 @@ export class FormApi {
return;
}
/**
* object
* antddayjs
* element-plusDate
*
*/
const fieldMergeFn = createMerge((obj, key, value) => {
if (key in obj) {
obj[key] =
!Array.isArray(obj[key]) && isObject(obj[key])
!Array.isArray(obj[key]) &&
isObject(obj[key]) &&
!isDayjsObject(obj[key]) &&
!isDate(obj[key])
? fieldMergeFn(obj[key], value)
: value;
}