梳理了前端检测页面的交互处理逻辑
This commit is contained in:
parent
d1738c3e42
commit
2a3d168e50
@ -947,7 +947,7 @@ def handle_disconnect():
|
|||||||
logger.info('客户端已断开连接')
|
logger.info('客户端已断开连接')
|
||||||
|
|
||||||
# 原始的start_video处理逻辑(暂时注释)
|
# 原始的start_video处理逻辑(暂时注释)
|
||||||
@socketio.on('start_video')
|
@socketio.on('start_video_stream')
|
||||||
def handle_start_video(data=None):
|
def handle_start_video(data=None):
|
||||||
try:
|
try:
|
||||||
results = {'status': 'success', 'cameras': {}}
|
results = {'status': 'success', 'cameras': {}}
|
||||||
@ -996,7 +996,7 @@ def handle_start_video(data=None):
|
|||||||
logger.error(f'启动视频流失败: {e}', exc_info=True)
|
logger.error(f'启动视频流失败: {e}', exc_info=True)
|
||||||
emit('video_status', {'status': 'error', 'message': f'启动失败: {str(e)}'})
|
emit('video_status', {'status': 'error', 'message': f'启动失败: {str(e)}'})
|
||||||
|
|
||||||
@socketio.on('stop_video')
|
@socketio.on('stop_video_stream')
|
||||||
def handle_stop_video(data=None):
|
def handle_stop_video(data=None):
|
||||||
logger.info(f'收到stop_video事件,数据: {data}')
|
logger.info(f'收到stop_video事件,数据: {data}')
|
||||||
|
|
||||||
|
@ -26,36 +26,13 @@
|
|||||||
--el-button-border-color: transparent ">
|
--el-button-border-color: transparent ">
|
||||||
结束
|
结束
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button v-if="isStart && isConnected" @click="handleScreenshot" type="primary" class="start-btn" style="background-image: linear-gradient(to right, #FBB106, #A817C6);
|
<el-button v-if="isStart && isConnected" @click="saveDetectionData" type="primary" class="start-btn" style="background-image: linear-gradient(to right, #FBB106, #A817C6);
|
||||||
--el-button-border-color: #409EFF;
|
--el-button-border-color: #409EFF;
|
||||||
--el-button-border-color: transparent ">
|
--el-button-border-color: transparent ">
|
||||||
保存数据
|
保存数据
|
||||||
</el-button>
|
</el-button>
|
||||||
<!-- <el-button
|
|
||||||
@click="handleStartStopRecording"
|
|
||||||
:disabled="!isConnected"
|
|
||||||
type="warning"
|
|
||||||
class="start-btn"
|
|
||||||
style="background-image: linear-gradient(to right, rgb(255, 193, 7), rgb(255, 87, 34));
|
|
||||||
--el-button-border-color: #409EFF;
|
|
||||||
--el-button-border-color: transparent; margin-left: 10px;"
|
|
||||||
>
|
|
||||||
{{ isRecording ? '停止录制' : '开始录制' }}
|
|
||||||
</el-button> -->
|
|
||||||
<!-- <el-button
|
|
||||||
v-if="isStart == true"
|
|
||||||
@click="handleDataCollection"
|
|
||||||
:loading="dataCollectionLoading"
|
|
||||||
type="success"
|
|
||||||
style="width: 120px;background-image: linear-gradient(to right, rgb(40, 167, 69), rgb(25, 135, 84));
|
|
||||||
--el-button-border-color: #409EFF;
|
|
||||||
--el-button-border-color: transparent; margin-left: 10px;"
|
|
||||||
>
|
|
||||||
检测数据采集
|
|
||||||
</el-button> -->
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="top-bar-right">
|
<div class="top-bar-right">
|
||||||
<span class="info-item">测试时间:2025/5/28 下午14:38</span>
|
<span class="info-item">测试时间:2025/5/28 下午14:38</span>
|
||||||
<span class="info-item">测试医生:李四</span>
|
<span class="info-item">测试医生:李四</span>
|
||||||
@ -509,8 +486,10 @@ function connectWebSocket() {
|
|||||||
socket.on('connect', () => {
|
socket.on('connect', () => {
|
||||||
console.log('✅ WebSocket连接成功!Socket ID:', socket.id)
|
console.log('✅ WebSocket连接成功!Socket ID:', socket.id)
|
||||||
isConnected.value = true
|
isConnected.value = true
|
||||||
// 连接成功后自动开始RTSP播放(仅播放视频,不创建会话)
|
// 连接成功后自动启动视频流、IMU流和压力传感器流
|
||||||
startRtsp()
|
startVideoStream()
|
||||||
|
startIMUStreaming();
|
||||||
|
startPressureStreaming();
|
||||||
})
|
})
|
||||||
|
|
||||||
// 连接失败事件
|
// 连接失败事件
|
||||||
@ -528,7 +507,9 @@ function connectWebSocket() {
|
|||||||
socket.on('disconnect', (reason) => {
|
socket.on('disconnect', (reason) => {
|
||||||
console.log('⚠️ 连接断开:', reason)
|
console.log('⚠️ 连接断开:', reason)
|
||||||
isConnected.value = false
|
isConnected.value = false
|
||||||
hideVideo()
|
stopVideoStream()
|
||||||
|
stopIMUStreaming()
|
||||||
|
stopPressureStreaming()
|
||||||
// 如果正在录像,停止录像
|
// 如果正在录像,停止录像
|
||||||
if (isRecording.value) {
|
if (isRecording.value) {
|
||||||
stopRecording()
|
stopRecording()
|
||||||
@ -536,6 +517,7 @@ function connectWebSocket() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// 监听视频状态事件
|
// 监听视频状态事件
|
||||||
socket.on('video_status', (data) => {
|
socket.on('video_status', (data) => {
|
||||||
console.log('📺 视频状态:', data)
|
console.log('📺 视频状态:', data)
|
||||||
@ -552,11 +534,7 @@ function connectWebSocket() {
|
|||||||
displayDepthCameraFrame(data.image)
|
displayDepthCameraFrame(data.image)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听错误事件
|
|
||||||
socket.on('error', (error) => {
|
|
||||||
console.error('❌ Socket错误:', error)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 监听IMU状态事件
|
// 监听IMU状态事件
|
||||||
socket.on('imu_status', (data) => {
|
socket.on('imu_status', (data) => {
|
||||||
console.log('📡 IMU状态:', data)
|
console.log('📡 IMU状态:', data)
|
||||||
@ -589,29 +567,25 @@ function connectWebSocket() {
|
|||||||
handlePressureData(data)
|
handlePressureData(data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 监听错误事件
|
||||||
|
socket.on('error', (error) => {
|
||||||
|
console.error('❌ Socket错误:', error)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('💥 连接异常:', error.message)
|
console.error('💥 连接异常:', error.message)
|
||||||
isConnected.value = false
|
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) {
|
if (socket && socket.connected) {
|
||||||
console.log('🚀 发送start_video事件')
|
console.log('🚀 发送start_video事件')
|
||||||
|
|
||||||
socket.emit('start_video', {}, (ack) => {
|
socket.emit('start_video_stream', {}, (ack) => {
|
||||||
if (ack) {
|
if (ack) {
|
||||||
console.log('✅ start_video事件已确认:', ack)
|
console.log('✅ start_video事件已确认:', ack)
|
||||||
} else {
|
} else {
|
||||||
@ -634,10 +608,10 @@ function startRtsp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 停止视频流
|
// 停止视频流
|
||||||
function stopRtsp() {
|
function stopVideoStream() {
|
||||||
if (socket && socket.connected) {
|
if (socket && socket.connected) {
|
||||||
console.log('🛑 发送stop_video事件')
|
console.log('🛑 发送stop_video事件')
|
||||||
socket.emit('stop_video', {}, (ack) => {
|
socket.emit('stop_video_stream', {}, (ack) => {
|
||||||
if (ack) {
|
if (ack) {
|
||||||
console.log('✅ stop_video事件已确认:', ack)
|
console.log('✅ stop_video事件已确认:', ack)
|
||||||
} else {
|
} else {
|
||||||
@ -667,11 +641,6 @@ function displayDepthCameraFrame(base64Image) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏视频
|
|
||||||
function hideVideo() {
|
|
||||||
rtspImgSrc.value = ''
|
|
||||||
depthCameraImgSrc.value = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理IMU头部姿态数据
|
// 处理IMU头部姿态数据
|
||||||
function handleIMUData(data) {
|
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() {
|
async function handleDataCollection() {
|
||||||
@ -880,8 +837,9 @@ async function handleDataCollection() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 截图功能(保留原有功能)
|
// 保存检测数据
|
||||||
async function handleScreenshot() {
|
|
||||||
|
async function saveDetectionData() {
|
||||||
if (screenshotLoading.value) return
|
if (screenshotLoading.value) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -917,7 +875,7 @@ async function handleScreenshot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 调用后端API保存截图
|
// 调用后端API保存截图
|
||||||
const result = await saveScreenshot({
|
const result = await sendDetectionData({
|
||||||
patientId: patientInfo.value.id,
|
patientId: patientInfo.value.id,
|
||||||
patientName: patientInfo.value.name,
|
patientName: patientInfo.value.name,
|
||||||
sessionId: patientInfo.value.sessionId,
|
sessionId: patientInfo.value.sessionId,
|
||||||
@ -960,21 +918,9 @@ async function handleScreenshot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成检查记录ID
|
// 调用后端API保存检测数据
|
||||||
function generateSessionId() {
|
async function sendDetectionData(data) {
|
||||||
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')
|
|
||||||
|
|
||||||
return `${year}${month}${day}${hour}${minute}${second}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用后端API保存截图
|
|
||||||
async function saveScreenshot(data) {
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${BACKEND_URL}/api/detection/${patientInfo.value.sessionId}/collect`
|
const response = await fetch(`${BACKEND_URL}/api/detection/${patientInfo.value.sessionId}/collect`
|
||||||
, {
|
, {
|
||||||
@ -1371,41 +1317,8 @@ async function stopDetection() {
|
|||||||
// 如果正在录制,停止录制
|
// 如果正在录制,停止录制
|
||||||
if (isRecording.value) {
|
if (isRecording.value) {
|
||||||
stopRecording()
|
stopRecording()
|
||||||
}
|
}
|
||||||
// saveRecording()
|
isStart.value = false
|
||||||
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('检测已停止,视频继续播放')
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ 停止检测失败:', error)
|
console.error('❌ 停止检测失败:', error)
|
||||||
@ -1450,16 +1363,17 @@ const loadPatientInfo = async () => {
|
|||||||
|
|
||||||
// 处理页面关闭或刷新事件
|
// 处理页面关闭或刷新事件
|
||||||
const handleBeforeUnload = () => {
|
const handleBeforeUnload = () => {
|
||||||
// 停止录像(如果正在录像)
|
|
||||||
if (isRecording.value) {
|
|
||||||
stopRecording()
|
|
||||||
}
|
|
||||||
// 停止检测(如果正在检测)
|
// 停止检测(如果正在检测)
|
||||||
if (isStart.value) {
|
if (isStart.value) {
|
||||||
stopDetection()
|
stopDetection()
|
||||||
}
|
}
|
||||||
// 停止视频播放
|
// 停止视频播放
|
||||||
stopRtsp()
|
stopVideoStream()
|
||||||
|
// 停止IMU流
|
||||||
|
stopIMUStreaming()
|
||||||
|
// 停止压力传感器流
|
||||||
|
stopPressureStreaming()
|
||||||
|
|
||||||
// 断开WebSocket连接
|
// 断开WebSocket连接
|
||||||
if (socket) {
|
if (socket) {
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
|
Loading…
Reference in New Issue
Block a user