From 8030b547955c72b8e1b10e72cd773c2ac6a63b0b Mon Sep 17 00:00:00 2001 From: xingyu Date: Mon, 4 Sep 2023 14:27:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(Form):=20=E4=B8=BAfieldMapToTime=E7=9A=84?= =?UTF-8?q?=E6=98=A0=E5=B0=84=E7=B1=BB=E5=9E=8B=E5=A2=9E=E5=8A=A0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=88=B3=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Form/src/hooks/useFormValues.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/Form/src/hooks/useFormValues.ts b/src/components/Form/src/hooks/useFormValues.ts index ca4cf3a..7e54fa3 100644 --- a/src/components/Form/src/hooks/useFormValues.ts +++ b/src/components/Form/src/hooks/useFormValues.ts @@ -107,14 +107,24 @@ export function useFormValues({ defaultValueRef, getSchema, formModel, getProps const [startTimeFormat, endTimeFormat] = Array.isArray(format) ? format : [format, format] - values[startTimeKey] = dateUtil(startTime).format(startTimeFormat) - values[endTimeKey] = dateUtil(endTime).format(endTimeFormat) + values[startTimeKey] = formatTime(startTime, startTimeFormat) + values[endTimeKey] = formatTime(endTime, endTimeFormat) Reflect.deleteProperty(values, field) } return values } + function formatTime(time: string, format: string) { + if (format === 'timestamp') + return dateUtil(time).unix() + + else if (format === 'timestampStartDay') + return dateUtil(time).startOf('day').unix() + + return dateUtil(time).format(format) + } + function initDefault() { const schemas = unref(getSchema) const obj: Recordable = {}