Files
iot-device-management-frontend/apps/web-antd/src/utils/date.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-04-04 15:58:04 +08:00
import dayjs from 'dayjs';
// TODO @芋艿:后续整理下
2025-04-04 15:58:04 +08:00
/** 时间段选择器拓展 */
2025-04-10 11:34:20 +08:00
export function getRangePickerDefaultProps() {
2025-04-04 15:58:04 +08:00
return {
showTime: {
format: 'HH:mm:ss',
defaultValue: [
dayjs('00:00:00', 'HH:mm:ss'),
dayjs('23:59:59', 'HH:mm:ss'),
],
},
valueFormat: 'YYYY-MM-DD HH:mm:ss',
format: 'YYYY-MM-DD HH:mm:ss',
2025-04-04 15:58:04 +08:00
placeholder: ['开始时间', '结束时间'],
2025-04-10 11:34:20 +08:00
// prettier-ignore
2025-04-04 15:58:04 +08:00
ranges: {
2025-04-10 11:34:20 +08:00
'今天': [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')],
},
2025-04-04 15:58:04 +08:00
transformDateFunc: (dates: any) => {
if (dates && dates.length === 2) {
return [dates.createTime[0], dates.createTime[1]].join(','); // 格式化为后台支持的时间格式
}
return {};
},
};
2025-04-10 11:34:20 +08:00
}