!764 针对 iothome 页面上次codereview的优化

Merge pull request !764 from alwayssuper/feature/iot
This commit is contained in:
芋道源码
2025-06-14 07:00:25 +00:00
committed by Gitee
8 changed files with 775 additions and 457 deletions

View File

@@ -330,3 +330,30 @@ export function getDateRange(
dayjs(endDate).endOf('d').format('YYYY-MM-DD HH:mm:ss')
]
}
/**
* 获取指定小时前的时间戳
* @param hours 小时数
* @returns 返回指定小时前的时间戳(毫秒)
*/
export function getHoursAgo(hours: number): number {
return dayjs().subtract(hours, 'hour').valueOf()
}
/**
* 获取标准时间范围的时间戳
* @param range 时间范围,支持 '8h' | '24h' | '7d'
* @returns 返回开始时间戳(毫秒)
*/
export function getTimeRangeStart(range: '8h' | '24h' | '7d'): number {
switch (range) {
case '8h':
return getHoursAgo(8)
case '24h':
return getHoursAgo(24)
case '7d':
return dayjs().subtract(7, 'day').valueOf()
default:
return dayjs().valueOf()
}
}