From 2a3d168e50748587bc416e92a7fcd77f65d5c3d9 Mon Sep 17 00:00:00 2001
From: root <13910913995@163.com>
Date: Wed, 6 Aug 2025 10:37:21 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A2=B3=E7=90=86=E4=BA=86=E5=89=8D=E7=AB=AF?=
=?UTF-8?q?=E6=A3=80=E6=B5=8B=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BA=A4=E4=BA=92?=
=?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/app.py | 4 +-
frontend/src/renderer/src/views/Detection.vue | 158 ++++--------------
2 files changed, 38 insertions(+), 124 deletions(-)
diff --git a/backend/app.py b/backend/app.py
index a238bfa2..25ee14e1 100644
--- a/backend/app.py
+++ b/backend/app.py
@@ -947,7 +947,7 @@ def handle_disconnect():
logger.info('客户端已断开连接')
# 原始的start_video处理逻辑(暂时注释)
-@socketio.on('start_video')
+@socketio.on('start_video_stream')
def handle_start_video(data=None):
try:
results = {'status': 'success', 'cameras': {}}
@@ -996,7 +996,7 @@ def handle_start_video(data=None):
logger.error(f'启动视频流失败: {e}', exc_info=True)
emit('video_status', {'status': 'error', 'message': f'启动失败: {str(e)}'})
-@socketio.on('stop_video')
+@socketio.on('stop_video_stream')
def handle_stop_video(data=None):
logger.info(f'收到stop_video事件,数据: {data}')
diff --git a/frontend/src/renderer/src/views/Detection.vue b/frontend/src/renderer/src/views/Detection.vue
index f7737266..d0bccf91 100644
--- a/frontend/src/renderer/src/views/Detection.vue
+++ b/frontend/src/renderer/src/views/Detection.vue
@@ -26,36 +26,13 @@
--el-button-border-color: transparent ">
结束
-
保存数据
-
-
-
+
-
测试时间:2025/5/28 下午14:38
测试医生:李四
@@ -509,8 +486,10 @@ function connectWebSocket() {
socket.on('connect', () => {
console.log('✅ WebSocket连接成功!Socket ID:', socket.id)
isConnected.value = true
- // 连接成功后自动开始RTSP播放(仅播放视频,不创建会话)
- startRtsp()
+ // 连接成功后自动启动视频流、IMU流和压力传感器流
+ startVideoStream()
+ startIMUStreaming();
+ startPressureStreaming();
})
// 连接失败事件
@@ -528,7 +507,9 @@ function connectWebSocket() {
socket.on('disconnect', (reason) => {
console.log('⚠️ 连接断开:', reason)
isConnected.value = false
- hideVideo()
+ stopVideoStream()
+ stopIMUStreaming()
+ stopPressureStreaming()
// 如果正在录像,停止录像
if (isRecording.value) {
stopRecording()
@@ -536,6 +517,7 @@ function connectWebSocket() {
}
})
+
// 监听视频状态事件
socket.on('video_status', (data) => {
console.log('📺 视频状态:', data)
@@ -552,11 +534,7 @@ function connectWebSocket() {
displayDepthCameraFrame(data.image)
})
- // 监听错误事件
- socket.on('error', (error) => {
- console.error('❌ Socket错误:', error)
- })
-
+
// 监听IMU状态事件
socket.on('imu_status', (data) => {
console.log('📡 IMU状态:', data)
@@ -589,29 +567,25 @@ function connectWebSocket() {
handlePressureData(data)
})
+ // 监听错误事件
+ socket.on('error', (error) => {
+ console.error('❌ Socket错误:', error)
+ })
+
+
} catch (error) {
console.error('💥 连接异常:', error.message)
isConnected.value = false
}
}
-// 断开WebSocket连接
-function disconnectWebSocket() {
- if (socket) {
- socket.disconnect()
- socket = null
- console.log('主动断开连接')
- isConnected.value = false
- hideVideo()
- }
-}
-// 启动视频流
-function startRtsp() {
+// 启动视频推流
+function startVideoStream() {
if (socket && socket.connected) {
console.log('🚀 发送start_video事件')
- socket.emit('start_video', {}, (ack) => {
+ socket.emit('start_video_stream', {}, (ack) => {
if (ack) {
console.log('✅ start_video事件已确认:', ack)
} else {
@@ -634,10 +608,10 @@ function startRtsp() {
}
// 停止视频流
-function stopRtsp() {
+function stopVideoStream() {
if (socket && socket.connected) {
console.log('🛑 发送stop_video事件')
- socket.emit('stop_video', {}, (ack) => {
+ socket.emit('stop_video_stream', {}, (ack) => {
if (ack) {
console.log('✅ stop_video事件已确认:', ack)
} else {
@@ -667,11 +641,6 @@ function displayDepthCameraFrame(base64Image) {
}
}
-// 隐藏视频
-function hideVideo() {
- rtspImgSrc.value = ''
- depthCameraImgSrc.value = ''
-}
// 处理IMU头部姿态数据
function handleIMUData(data) {
@@ -777,19 +746,7 @@ function stopPressureStreaming() {
}
}
-// 手动开始/停止录制功能
-function handleStartStopRecording() {
- if (!isConnected.value) {
- ElMessage.warning('WebSocket未连接,无法操作')
- return
- }
- if (isRecording.value) {
- stopRecording()
- } else {
- startRecording()
- }
-}
// 检测数据采集功能
async function handleDataCollection() {
@@ -880,8 +837,9 @@ async function handleDataCollection() {
}
}
-// 截图功能(保留原有功能)
-async function handleScreenshot() {
+// 保存检测数据
+
+async function saveDetectionData() {
if (screenshotLoading.value) return
try {
@@ -917,7 +875,7 @@ async function handleScreenshot() {
}
// 调用后端API保存截图
- const result = await saveScreenshot({
+ const result = await sendDetectionData({
patientId: patientInfo.value.id,
patientName: patientInfo.value.name,
sessionId: patientInfo.value.sessionId,
@@ -960,21 +918,9 @@ async function handleScreenshot() {
}
}
-// 生成检查记录ID
-function generateSessionId() {
- const now = new Date()
- const year = now.getFullYear()
- const month = String(now.getMonth() + 1).padStart(2, '0')
- const day = String(now.getDate()).padStart(2, '0')
- const hour = String(now.getHours()).padStart(2, '0')
- const minute = String(now.getMinutes()).padStart(2, '0')
- const second = String(now.getSeconds()).padStart(2, '0')
+// 调用后端API保存检测数据
+async function sendDetectionData(data) {
- return `${year}${month}${day}${hour}${minute}${second}`
-}
-
-// 调用后端API保存截图
-async function saveScreenshot(data) {
try {
const response = await fetch(`${BACKEND_URL}/api/detection/${patientInfo.value.sessionId}/collect`
, {
@@ -1371,41 +1317,8 @@ async function stopDetection() {
// 如果正在录制,停止录制
if (isRecording.value) {
stopRecording()
- }
- // saveRecording()
- isStart.value = false
-
- // // 调用后端API停止检测会话
- // if (patientInfo.value.sessionId) {
-
- // const response = await fetch(`${BACKEND_URL}/api/detection/${patientInfo.value.sessionId}/stop`, {
- // method: 'POST',
- // headers: {
- // 'Content-Type': 'application/json'
- // },
- // body: JSON.stringify({
- // duration: duration
- // })
- // })
-
- // if (response.ok) {
- // const result = await response.json()
- // if (result.success) {
- // console.log('✅ 检测会话已停止')
- // //停止弹出诊断信息
- // dialogVisible.value = true
- // if (result.duration) {
- // console.log(`⏱️ 检测持续时间: ${result.duration}秒`)
- // }
- // }
- // }
- // }
- // dialogVisible.value = true
- // // 清除检测开始时间和会话ID
- // patientInfo.value.detectionStartTime = null
- // // patientInfo.value.sessionId = null
-
- // ElMessage.success('检测已停止,视频继续播放')
+ }
+ isStart.value = false
} catch (error) {
console.error('❌ 停止检测失败:', error)
@@ -1450,16 +1363,17 @@ const loadPatientInfo = async () => {
// 处理页面关闭或刷新事件
const handleBeforeUnload = () => {
- // 停止录像(如果正在录像)
- if (isRecording.value) {
- stopRecording()
- }
// 停止检测(如果正在检测)
if (isStart.value) {
stopDetection()
}
// 停止视频播放
- stopRtsp()
+ stopVideoStream()
+ // 停止IMU流
+ stopIMUStreaming()
+ // 停止压力传感器流
+ stopPressureStreaming()
+
// 断开WebSocket连接
if (socket) {
socket.disconnect()