refactor: 迁移 time.ts

pull/79/MERGE
xingyu4j 2025-04-23 17:30:39 +08:00
parent dccb846bb0
commit 26c2638146
3 changed files with 48 additions and 0 deletions

View File

@ -1,3 +1,4 @@
// 迁移至 packages/@core/base/shared/src/utils/time.ts
import dayjs from 'dayjs'; import dayjs from 'dayjs';
/** 时间段选择器拓展 */ /** 时间段选择器拓展 */

View File

@ -8,6 +8,7 @@ export * from './letter';
export * from './merge'; export * from './merge';
export * from './nprogress'; export * from './nprogress';
export * from './state-handler'; export * from './state-handler';
export * from './time';
export * from './to'; export * from './to';
export * from './tree'; export * from './tree';
export * from './unique'; export * from './unique';

View File

@ -0,0 +1,46 @@
import dayjs from 'dayjs';
/** 时间段选择器拓展 */
export function rangePickerExtend() {
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 {};
},
// 如果需要10位时间戳秒级可以使用 valueFormat: 'X'
valueFormat: 'YYYY-MM-DD HH:mm:ss',
};
}