From 12d2c502485d1ff1dd0bf7ff312f3c101448077f Mon Sep 17 00:00:00 2001 From: zhongzm Date: Mon, 22 Sep 2025 15:44:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E6=AD=A3mos=E5=92=8Ccct=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/perfManage/overview/index.vue | 42 +++++++++++++++---------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/views/perfManage/overview/index.vue b/src/views/perfManage/overview/index.vue index 546d2b15..4111bf91 100644 --- a/src/views/perfManage/overview/index.vue +++ b/src/views/perfManage/overview/index.vue @@ -399,8 +399,8 @@ async function fetchMosData(neId: string) { console.log('MOS数据响应:', res) if (res.code === 1 && Array.isArray(res.data)) { - // 使用24小时数据补全功能 - mosData.value = generate24HourTimeSeries(res.data, 'mosAvg') + // 使用当天0点到现在的数据补全功能 + mosData.value = generateTodayTimeSeries(res.data, 'mosAvg') console.log('MOS数据加载完成:', mosData.value) // 更新MOS图表 @@ -441,8 +441,8 @@ async function fetchCctData(neId: string) { console.log('CCT数据响应:', res) if (res.code === 1 && Array.isArray(res.data)) { - // 使用24小时数据补全功能 - cctData.value = generate24HourTimeSeries(res.data, 'cctAvg') + // 使用当天0点到现在的数据补全功能 + cctData.value = generateTodayTimeSeries(res.data, 'cctAvg') console.log('CCT数据加载完成:', cctData.value) // 更新CCT图表 @@ -2125,25 +2125,35 @@ function calculateMosCctTimeDifference(latestData: any, previousData: any) { } } -// 生成24小时完整时间序列数据(用于MOS/CCT数据补全) -function generate24HourTimeSeries(rawData: any[], dataField: string) { +// 生成当天0点到现在的完整时间序列数据(用于MOS/CCT数据补全) +function generateTodayTimeSeries(rawData: any[], dataField: string) { if (!rawData || rawData.length === 0) { - // 如果没有数据,返回24个0值 - return Array.from({ length: 24 }, (_, i) => ({ - timeGroup: Math.floor(Date.now() / 1000) - (23 - i) * 3600, + // 如果没有数据,返回当天0点到现在的0值数据点 + const now = new Date() + const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0) + const hoursFromStart = Math.floor((now.getTime() - todayStart.getTime()) / (1000 * 60 * 60)) + + return Array.from({ length: hoursFromStart + 1 }, (_, i) => ({ + timeGroup: Math.floor(todayStart.getTime() / 1000) + i * 3600, [dataField]: 0 })) } - // 获取当前时间(秒级时间戳) - const now = Math.floor(Date.now() / 1000) + // 获取当前时间和当天0点 + const now = new Date() + const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0) + const todayStartTimestamp = Math.floor(todayStart.getTime() / 1000) + const nowTimestamp = Math.floor(now.getTime() / 1000) - // 生成过去24小时的完整时间点(每小时一个点) - const timePoints = Array.from({ length: 24 }, (_, i) => { - const hourTimestamp = now - (23 - i) * 3600 + // 计算从当天0点到现在的小时数 + const hoursFromStart = Math.floor((nowTimestamp - todayStartTimestamp) / 3600) + + // 生成当天0点到现在的完整时间点(每小时一个点) + const timePoints = Array.from({ length: hoursFromStart + 1 }, (_, i) => { + const hourTimestamp = todayStartTimestamp + i * 3600 return { timestamp: hourTimestamp, - hourStart: Math.floor(hourTimestamp / 3600) * 3600 // 整点时间 + hourStart: hourTimestamp // 已经是整点时间 } }) @@ -2155,7 +2165,7 @@ function generate24HourTimeSeries(rawData: any[], dataField: string) { dataMap.set(hourStart, item) }) - // 补全24小时数据 + // 补全当天数据 const completeData = timePoints.map(({ hourStart }) => { const existingData = dataMap.get(hourStart) if (existingData) {