@@ -15,6 +15,7 @@ import { Store } from '@vben-core/shared/store';
1515import {
1616 bindMethods ,
1717 createMerge ,
18+ formatDate ,
1819 isDate ,
1920 isDayjsObject ,
2021 isFunction ,
@@ -94,7 +95,7 @@ export class FormApi {
9495
9596 async getValues ( ) {
9697 const form = await this . getForm ( ) ;
97- return form . values ;
98+ return this . handleRangeTimeValue ( form . values ) ;
9899 }
99100
100101 async isFieldValid ( fieldName : string ) {
@@ -117,12 +118,11 @@ export class FormApi {
117118 try {
118119 const results = await Promise . all (
119120 chain . map ( async ( api ) => {
120- const form = await api . getForm ( ) ;
121121 const validateResult = await api . validate ( ) ;
122122 if ( ! validateResult . valid ) {
123123 return ;
124124 }
125- const rawValues = toRaw ( form . values || { } ) ;
125+ const rawValues = toRaw ( ( await api . getValues ( ) ) || { } ) ;
126126 return rawValues ;
127127 } ) ,
128128 ) ;
@@ -147,7 +147,9 @@ export class FormApi {
147147 if ( ! this . isMounted ) {
148148 Object . assign ( this . form , formActions ) ;
149149 this . stateHandler . setConditionTrue ( ) ;
150- this . setLatestSubmissionValues ( { ...toRaw ( this . form . values ) } ) ;
150+ this . setLatestSubmissionValues ( {
151+ ...toRaw ( this . handleRangeTimeValue ( this . form . values ) ) ,
152+ } ) ;
151153 this . isMounted = true ;
152154 }
153155 }
@@ -253,7 +255,7 @@ export class FormApi {
253255 e ?. stopPropagation ( ) ;
254256 const form = await this . getForm ( ) ;
255257 await form . submitForm ( ) ;
256- const rawValues = toRaw ( form . values || { } ) ;
258+ const rawValues = toRaw ( await this . getValues ( ) ) ;
257259 await this . state ?. handleSubmit ?.( rawValues ) ;
258260
259261 return rawValues ;
@@ -342,6 +344,48 @@ export class FormApi {
342344 return this . form ;
343345 }
344346
347+ private handleRangeTimeValue = ( originValues : Record < string , any > ) => {
348+ const values = { ...originValues } ;
349+ const fieldMappingTime = this . state ?. fieldMappingTime ;
350+
351+ if ( ! fieldMappingTime || ! Array . isArray ( fieldMappingTime ) ) {
352+ return values ;
353+ }
354+
355+ fieldMappingTime . forEach (
356+ ( [ field , [ startTimeKey , endTimeKey ] , format = 'YYYY-MM-DD' ] ) => {
357+ if ( startTimeKey && endTimeKey && values [ field ] === null ) {
358+ Reflect . deleteProperty ( values , startTimeKey ) ;
359+ Reflect . deleteProperty ( values , endTimeKey ) ;
360+ // delete values[startTimeKey];
361+ // delete values[endTimeKey];
362+ }
363+
364+ if ( ! values [ field ] ) {
365+ Reflect . deleteProperty ( values , field ) ;
366+ // delete values[field];
367+ return ;
368+ }
369+
370+ const [ startTime , endTime ] = values [ field ] ;
371+ const [ startTimeFormat , endTimeFormat ] = Array . isArray ( format )
372+ ? format
373+ : [ format , format ] ;
374+
375+ values [ startTimeKey ] = startTime
376+ ? formatDate ( startTime , startTimeFormat )
377+ : undefined ;
378+ values [ endTimeKey ] = endTime
379+ ? formatDate ( endTime , endTimeFormat )
380+ : undefined ;
381+
382+ // delete values[field];
383+ Reflect . deleteProperty ( values , field ) ;
384+ } ,
385+ ) ;
386+ return values ;
387+ } ;
388+
345389 private updateState ( ) {
346390 const currentSchema = this . state ?. schema ?? [ ] ;
347391 const prevSchema = this . prevState ?. schema ?? [ ] ;
0 commit comments