From a5bef7d279f1e3a8553b3b5bb0363aa87cee9f0c Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 6 May 2025 23:24:14 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20utils=20=E7=BB=9F=E4=B8=80=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/utils/index.ts | 4 ++ apps/web-antd/src/utils/rangePickerProps.ts | 41 +++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 apps/web-antd/src/utils/index.ts create mode 100644 apps/web-antd/src/utils/rangePickerProps.ts diff --git a/apps/web-antd/src/utils/index.ts b/apps/web-antd/src/utils/index.ts new file mode 100644 index 00000000..9dc13ef1 --- /dev/null +++ b/apps/web-antd/src/utils/index.ts @@ -0,0 +1,4 @@ +export * from './constants'; +export * from './dict'; +export * from './rangePickerProps'; +export * from './validator'; diff --git a/apps/web-antd/src/utils/rangePickerProps.ts b/apps/web-antd/src/utils/rangePickerProps.ts new file mode 100644 index 00000000..164e6ecb --- /dev/null +++ b/apps/web-antd/src/utils/rangePickerProps.ts @@ -0,0 +1,41 @@ +import dayjs from 'dayjs'; + +/** 时间段选择器拓展 */ +export function getRangePickerDefaultProps() { + return { + format: 'YYYY-MM-DD HH:mm:ss', + placeholder: ['开始时间', '结束时间'], + ranges: { + 今天: [dayjs().startOf('day'), dayjs().endOf('day')], + '最近 7 天': [ + dayjs().subtract(7, 'day').startOf('day'), + dayjs().endOf('day'), + ], + '最近 30 天': [ + dayjs().subtract(30, 'day').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')], + }, + showTime: { + defaultValue: [ + dayjs('00:00:00', 'HH:mm:ss'), + dayjs('23:59:59', 'HH:mm:ss'), + ], + format: 'HH:mm:ss', + }, + transformDateFunc: (dates: any) => { + if (dates && dates.length === 2) { + // 格式化为后台支持的时间格式 + return [dates.createTime[0], dates.createTime[1]].join(','); + } + return {}; + }, + valueFormat: 'YYYY-MM-DD HH:mm:ss', + }; +}