Skip to content

Commit

Permalink
feat(Form): 为fieldMapToTime的映射类型增加时间戳转换 (#2996)
Browse files Browse the repository at this point in the history
为fieldMapToTime的第三个参数增加 timestamp 和 timestampStartDay 选项

timestamp的作用: 将映射的时间格式转为时间戳

timestampStartDay的作用: 将映射的时间格式转为当天0点开始的时间戳
  • Loading branch information
wangjue666 committed Sep 3, 2023
1 parent a9017da commit 89d7a19
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Form/src/hooks/useFormValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit 89d7a19

Please sign in to comment.