From 89d7a19f3f533fcc0c605548857c915fdd4d488a Mon Sep 17 00:00:00 2001 From: invalid w Date: Sun, 3 Sep 2023 16:22:02 +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=20(#2996)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为fieldMapToTime的第三个参数增加 timestamp 和 timestampStartDay 选项 timestamp的作用: 将映射的时间格式转为时间戳 timestampStartDay的作用: 将映射的时间格式转为当天0点开始的时间戳 --- src/components/Form/src/hooks/useFormValues.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/Form/src/hooks/useFormValues.ts b/src/components/Form/src/hooks/useFormValues.ts index ffa0ff06..4317287e 100644 --- a/src/components/Form/src/hooks/useFormValues.ts +++ b/src/components/Form/src/hooks/useFormValues.ts @@ -115,14 +115,23 @@ export function useFormValues({ 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 = {};