From 25c25ead580138a33c66e5249d553bdf9c80153c Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 4 Apr 2025 15:58:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=B6=E9=97=B4=E6=AE=B5=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8=E6=8B=93=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/utils/TimeUtils.ts | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 apps/web-antd/src/utils/TimeUtils.ts diff --git a/apps/web-antd/src/utils/TimeUtils.ts b/apps/web-antd/src/utils/TimeUtils.ts new file mode 100644 index 000000000..3d3ab4554 --- /dev/null +++ b/apps/web-antd/src/utils/TimeUtils.ts @@ -0,0 +1,46 @@ +import dayjs from 'dayjs'; + +/** 时间段选择器拓展 */ +export const rangePickerExtend = () => { + return { + showTime: { + format: 'HH:mm:ss', + defaultValue: [ + dayjs('00:00:00', 'HH:mm:ss'), + dayjs('23:59:59', 'HH:mm:ss'), + ], + }, + // 如果需要10位时间戳(秒级)可以使用 valueFormat: 'X' + valueFormat: 'YYYY-MM-DD HH:mm:ss', + format: 'YYYY-MM-DD HH:mm:ss', // 显示格式 + placeholder: ['开始时间', '结束时间'], + ranges: { + 今天: [dayjs().startOf('day'), dayjs().endOf('day')], + + 昨天: [ + dayjs().subtract(1, 'day').startOf('day'), + dayjs().subtract(1, 'day').endOf('day'), + ], + + 本周: [dayjs().startOf('week'), dayjs().endOf('day')], + + 本月: [dayjs().startOf('month'), dayjs().endOf('day')], + + 最近7天: [ + dayjs().subtract(7, 'day').startOf('day'), + dayjs().endOf('day'), + ], + + 最近30天: [ + dayjs().subtract(30, 'day').startOf('day'), + dayjs().endOf('day'), + ], + }, + transformDateFunc: (dates: any) => { + if (dates && dates.length === 2) { + return [dates.createTime[0], dates.createTime[1]].join(','); // 格式化为后台支持的时间格式 + } + return {}; + }, + }; +};