diff --git a/src/views/iot/historyData/HistorySingleDeviceDialog.vue b/src/views/iot/historyData/HistorySingleDeviceDialog.vue index 7e0e7e3e..5056053e 100644 --- a/src/views/iot/historyData/HistorySingleDeviceDialog.vue +++ b/src/views/iot/historyData/HistorySingleDeviceDialog.vue @@ -103,6 +103,23 @@ const recordGroups = ref([]) const collectionTimeRange = ref([]) +const formatDateTime = (date: Date) => { + const pad = (value: number) => String(value).padStart(2, '0') + const y = date.getFullYear() + const m = pad(date.getMonth() + 1) + const d = pad(date.getDate()) + const h = pad(date.getHours()) + const mi = pad(date.getMinutes()) + const s = pad(date.getSeconds()) + return `${y}-${m}-${d} ${h}:${mi}:${s}` +} + +const buildLastHoursRange = (hours: number) => { + const end = new Date() + const start = new Date(end.getTime() - hours * 60 * 60 * 1000) + return [formatDateTime(start), formatDateTime(end)] +} + const toGroupMap = (value: any): Record => { if (!value || typeof value !== 'object' || Array.isArray(value)) { return {} @@ -206,6 +223,7 @@ watch( if (!visible) { return } + collectionTimeRange.value = buildLastHoursRange(4) fetchHistory() } )