From b033caa832bf500aaa8ea9471639934bb62f22d5 Mon Sep 17 00:00:00 2001
From: fanluyan <754122931@qq.com>
Date: Wed, 14 May 2025 11:24:29 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=9F=E8=AE=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/request.js | 2 +-
.../photostatis/components/photoTimeList.vue | 111 +++++++++++++++---
src/views/reportData/photostatis/index.vue | 22 ++--
3 files changed, 105 insertions(+), 30 deletions(-)
diff --git a/src/utils/request.js b/src/utils/request.js
index c7d6a05..565e86d 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -8,7 +8,7 @@ const service = axios.create({
// baseURL: '',
// timeout: 5000
baseURL: "api", //把原来的项目地址,改成api,解决跨域问题
- timeout: 60000,
+ timeout: 600000,
});
service.interceptors.request.use((config) => {
diff --git a/src/views/reportData/photostatis/components/photoTimeList.vue b/src/views/reportData/photostatis/components/photoTimeList.vue
index 1d60397..caa8a7e 100644
--- a/src/views/reportData/photostatis/components/photoTimeList.vue
+++ b/src/views/reportData/photostatis/components/photoTimeList.vue
@@ -87,16 +87,20 @@ export default {
this.picloading = false;
});
},
- // 处理数据
+
processData() {
const channelPresetMap = {};
- // 遍历数据,按通道和预置位分组
this.picListData.forEach((photo) => {
const channel = photo.channnelname;
const presetId = photo.presetId;
- const hour = new Date(photo.photoTime).getHours();
- console.log("我是时间", hour);
+ const photoTime = new Date(photo.photoTime);
+
+ // 计算半小时段索引(0-47)
+ const hour = photoTime.getHours();
+ const minute = photoTime.getMinutes();
+ const halfHourIndex = hour * 2 + (minute >= 30 ? 1 : 0);
+
const key = `${channel}-${presetId}`;
if (!channelPresetMap[key]) {
@@ -104,12 +108,12 @@ export default {
channel: channel,
presetId: presetId,
totalCount: 0,
- hourlyData: new Array(24).fill(0),
+ hourlyData: new Array(48).fill(0), // 改为48个半小时段
};
}
channelPresetMap[key].totalCount++;
- channelPresetMap[key].hourlyData[hour]++;
+ channelPresetMap[key].hourlyData[halfHourIndex]++; // 更新对应半小时段
});
// 将数据按通道分组
@@ -123,7 +127,8 @@ export default {
channel: item.channel,
presetId: `预置位:${item.presetId}`,
totalCount: item.totalCount,
- anomalies: anomalies.join(", "),
+ // anomalies: anomalies.join(", "),
+ anomalies: anomalies.length > 0 ? anomalies.join(", ") : "正常",
};
});
});
@@ -144,25 +149,93 @@ export default {
.sort()
.map((channel) => grouped[channel]);
},
- // 检测异常时间点
+ // 修改后的 detectAnomalies 方法
detectAnomalies(hourlyData) {
const anomalies = [];
- const now = new Date(); // 获取当前时间
- const currentHour = now.getHours(); // 获取当前小时
-
- hourlyData.forEach((count, hour) => {
- // 只处理当前时间之前的小时数据
- if (hour <= currentHour) {
- if (count > 2) {
- anomalies.push(`${hour}:00 - 多${count - 2}张`);
- } else if (count < 2) {
- anomalies.push(`${hour}:00 - 少${2 - count}张`);
- }
+ const startTime = new Date(this.paramsData.starttime);
+ const endTime = new Date(this.paramsData.endtime);
+
+ // 生成时间范围内的所有半小时时间点(如 10:00, 10:30, 11:00)
+ const halfHourlyPoints = this.getHalfHourlyPoints(startTime, endTime);
+
+ halfHourlyPoints.forEach((timeStr) => {
+ // 将时间字符串(如 "10:00")转换为对应的半小时段索引(0-47)
+ const index = this.timeToHalfHourIndex(timeStr);
+ const count = hourlyData[index] || 0;
+
+ // 每半小时期望1张,检测多/少
+ if (count > 1) {
+ anomalies.push(`${timeStr} - 多${count - 1}张`);
+ } else if (count < 1) {
+ anomalies.push(`${timeStr} - 少${1 - count}张`);
}
});
return anomalies;
},
+ // 获取时间范围内的小时列表
+ getHoursInRange(startTime, endTime) {
+ const startHour = startTime.getHours();
+ const endHour = endTime.getHours();
+ const hours = [];
+
+ if (startTime <= endTime) {
+ // 同一天或结束时间大于等于开始时间
+ for (let h = startHour; h <= endHour; h++) {
+ hours.push(h);
+ }
+ } else {
+ // 跨天情况,添加从startHour到23,再到0到endHour
+ for (let h = startHour; h < 24; h++) {
+ hours.push(h);
+ }
+ for (let h = 0; h <= endHour; h++) {
+ hours.push(h);
+ }
+ }
+ return hours;
+ },
+ // 获取时间范围内的所有半小时时间点(格式:HH:mm)
+ getHalfHourlyPoints(startTime, endTime) {
+ const points = [];
+ let current = new Date(startTime);
+
+ // 对齐到最近的半小时(如 10:15 → 10:00)
+ current.setMinutes(current.getMinutes() >= 30 ? 30 : 0, 0, 0);
+
+ while (current <= endTime) {
+ const hours = current.getHours().toString().padStart(2, "0");
+ const minutes = current.getMinutes().toString().padStart(2, "0");
+ points.push(`${hours}:${minutes}`);
+ current = new Date(current.getTime() + 30 * 60 * 1000); // 增加30分钟
+ }
+
+ return points;
+ },
+ // 时间字符串(HH:mm) → 半小时段索引(0-47)
+ timeToHalfHourIndex(timeStr) {
+ const [hours, minutes] = timeStr.split(":").map(Number);
+ return hours * 2 + (minutes >= 30 ? 1 : 0);
+ },
+ // // 检测异常时间点
+ // detectAnomalies(hourlyData) {
+ // const anomalies = [];
+ // const now = new Date(); // 获取当前时间
+ // const currentHour = now.getHours(); // 获取当前小时
+
+ // hourlyData.forEach((count, hour) => {
+ // // 只处理当前时间之前的小时数据
+ // if (hour <= currentHour) {
+ // if (count > 2) {
+ // anomalies.push(`${hour}:00 - 多${count - 2}张`);
+ // } else if (count < 2) {
+ // anomalies.push(`${hour}:00 - 少${2 - count}张`);
+ // }
+ // }
+ // });
+
+ // return anomalies;
+ // },
// 分页逻辑
handleCurrentChange(val) {
this.page = val;
diff --git a/src/views/reportData/photostatis/index.vue b/src/views/reportData/photostatis/index.vue
index 83627ad..09fe2b5 100644
--- a/src/views/reportData/photostatis/index.vue
+++ b/src/views/reportData/photostatis/index.vue
@@ -116,18 +116,17 @@
-
-
+
-
{{ scope.row.photoInfo.firstPhotoTime }}
-
+ -->
-
+