Files
aiot-platform-ui/apps/web-antd/src/utils/rangePickerProps.ts

60 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-05-06 23:38:20 +08:00
import type { Dayjs } from 'dayjs';
2025-05-06 23:24:14 +08:00
import dayjs from 'dayjs';
2025-05-06 23:44:30 +08:00
import { $t } from '#/locales';
2025-05-06 23:24:14 +08:00
/** 时间段选择器拓展 */
export function getRangePickerDefaultProps() {
return {
format: 'YYYY-MM-DD HH:mm:ss',
2025-05-06 23:44:30 +08:00
placeholder: [
$t('utils.rangePicker.beginTime'),
$t('utils.rangePicker.endTime'),
],
2025-05-06 23:24:14 +08:00
ranges: {
2025-05-06 23:44:30 +08:00
[$t('utils.rangePicker.today')]: () =>
2025-05-06 23:38:20 +08:00
[dayjs().startOf('day'), dayjs().endOf('day')] as [Dayjs, Dayjs],
2025-05-06 23:44:30 +08:00
[$t('utils.rangePicker.last7Days')]: () =>
2025-05-06 23:38:20 +08:00
[dayjs().subtract(7, 'day').startOf('day'), dayjs().endOf('day')] as [
Dayjs,
Dayjs,
],
2025-05-06 23:44:30 +08:00
[$t('utils.rangePicker.last30Days')]: () =>
2025-05-06 23:38:20 +08:00
[dayjs().subtract(30, 'day').startOf('day'), dayjs().endOf('day')] as [
Dayjs,
Dayjs,
],
2025-05-06 23:44:30 +08:00
[$t('utils.rangePicker.yesterday')]: () =>
2025-05-06 23:38:20 +08:00
[
dayjs().subtract(1, 'day').startOf('day'),
dayjs().subtract(1, 'day').endOf('day'),
] as [Dayjs, Dayjs],
2025-05-06 23:44:30 +08:00
[$t('utils.rangePicker.thisWeek')]: () =>
2025-05-06 23:38:20 +08:00
[dayjs().startOf('week'), dayjs().endOf('day')] as [Dayjs, Dayjs],
2025-05-06 23:44:30 +08:00
[$t('utils.rangePicker.thisMonth')]: () =>
2025-05-06 23:38:20 +08:00
[dayjs().startOf('month'), dayjs().endOf('day')] as [Dayjs, Dayjs],
2025-05-06 23:44:30 +08:00
[$t('utils.rangePicker.lastWeek')]: () =>
[dayjs().subtract(1, 'week').startOf('day'), dayjs().endOf('day')] as [
Dayjs,
Dayjs,
],
2025-05-06 23:24:14 +08:00
},
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',
};
}