From 77d35fc4ccb188f9985f7763ef069df9a6663b23 Mon Sep 17 00:00:00 2001 From: root <13910913995@163.com> Date: Fri, 28 Nov 2025 08:05:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/devices/imu_manager.py | 4 +- backend/main.py | 23 ++----- backend/utils.py | 11 ++-- frontend/src/renderer/src/services/api.js | 4 +- frontend/src/renderer/src/views/Detection.vue | 61 ++++++++++++------- 5 files changed, 57 insertions(+), 46 deletions(-) diff --git a/backend/devices/imu_manager.py b/backend/devices/imu_manager.py index b95ce1cc..037a2a32 100644 --- a/backend/devices/imu_manager.py +++ b/backend/devices/imu_manager.py @@ -305,10 +305,10 @@ class BleIMUDevice: while self.running: try: - logger.info(f"扫描并连接蓝牙IMU: {self.mac_address} ...") + # logger.info(f"扫描并连接蓝牙IMU: {self.mac_address} ...") device = await BleakScanner.find_device_by_address(self.mac_address, cb=dict(use_bdaddr=False)) if device is None: - logger.warning(f"未找到设备: {self.mac_address}") + # logger.warning(f"未找到设备: {self.mac_address}") await asyncio.sleep(2.0) continue diff --git a/backend/main.py b/backend/main.py index bbfa72ec..d6a850c3 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1017,10 +1017,7 @@ class AppServer: # 获取患者详情 try: patient = self.db_manager.get_patient(patient_id) - if patient: - return jsonify({'success': True, 'data': patient}) - else: - return jsonify({'success': False, 'error': '患者不存在'}), 404 + return jsonify({'success': True, 'data': patient}) except Exception as e: self.logger.error(f'获取患者详情失败: {e}') @@ -1051,12 +1048,7 @@ class AppServer: } self.db_manager.update_patient(patient_id, patient_data) - result = True - - if result: - return jsonify({'success': True, 'message': '患者信息更新成功'}) - else: - return jsonify({'success': False, 'error': '患者不存在'}), 404 + return jsonify({'success': True, 'message': '患者信息更新成功'}) except Exception as e: self.logger.error(f'更新患者信息失败: {e}') @@ -1066,10 +1058,7 @@ class AppServer: # 删除患者 try: result = self.db_manager.delete_patient(patient_id) - if result: - return jsonify({'success': True, 'message': '患者已删除'}) - else: - return jsonify({'success': False, 'error': '患者不存在'}), 404 + return jsonify({'success': True, 'message': '患者已删除'}) except Exception as e: self.logger.error(f'删除患者失败: {e}') @@ -1674,7 +1663,7 @@ class AppServer: def handle_subscribe_device(data): """订阅特定设备数据""" device_type = data.get('device_type') - if device_type in ['camera', 'femtobolt', 'imu', 'pressure']: + if device_type in ['camera1', 'camera2', 'femtobolt', 'imu', 'pressure']: self.logger.info(f'客户端订阅{device_type}设备数据') emit('subscription_status', { 'device_type': device_type, @@ -1997,7 +1986,7 @@ def main(): """主函数""" # 解析命令行参数 parser = argparse.ArgumentParser(description='Body Balance Evaluation System Backend') - parser.add_argument('--host', default='localhost', help='Host address to bind to') + parser.add_argument('--host', default='0.0.0.0', help='Host address to bind to') parser.add_argument('--port', type=int, default=5000, help='Port number to bind to') parser.add_argument('--debug', action='store_true', help='Enable debug mode') args = parser.parse_args() @@ -2008,4 +1997,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/backend/utils.py b/backend/utils.py index 57482ee1..9f4fe47f 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -233,10 +233,13 @@ class DataValidator: # 出生日期验证 if data.get('birth_date'): try: - birth_date = datetime.fromisoformat(data['birth_date'].replace('Z', '+00:00')) - if birth_date > datetime.now(): + birth_dt = datetime.fromisoformat(data['birth_date'].replace('Z', '+00:00')) + birth = birth_dt.date() + today = datetime.now().date() + lower = datetime(1900, 1, 1).date() + if birth > today: errors.append('出生日期不能是未来时间') - if birth_date < datetime(1900, 1, 1): + if birth < lower: errors.append('出生日期过早') except ValueError: errors.append('出生日期格式无效') @@ -523,4 +526,4 @@ class ResponseFormatter: config = Config() # 性能监控实例 -performance_monitor = PerformanceMonitor() \ No newline at end of file +performance_monitor = PerformanceMonitor() diff --git a/frontend/src/renderer/src/services/api.js b/frontend/src/renderer/src/services/api.js index 0d8ba21e..c175d682 100644 --- a/frontend/src/renderer/src/services/api.js +++ b/frontend/src/renderer/src/services/api.js @@ -13,7 +13,7 @@ api.interceptors.request.use( if (window.electronAPI) { config.baseURL = window.electronAPI.getBackendUrl() } else { - config.baseURL = 'http://192.168.1.60:5000' + config.baseURL = 'http://localhost:5000' } // 为需要发送数据的请求设置Content-Type(避免覆盖FormData) @@ -660,7 +660,7 @@ export const getBackendUrl = () => { if (window.electronAPI) { return window.electronAPI.getBackendUrl() } else { - return 'http://192.168.1.60:5000' + return 'http://localhost:5000' } } diff --git a/frontend/src/renderer/src/views/Detection.vue b/frontend/src/renderer/src/views/Detection.vue index ee99998d..7b378a64 100644 --- a/frontend/src/renderer/src/views/Detection.vue +++ b/frontend/src/renderer/src/views/Detection.vue @@ -314,11 +314,11 @@
- camera1
- camera2
@@ -678,7 +678,9 @@ const chartoption = ref({ ] }) // 四个设备的独立连接状态 -const cameraStatus = ref('未连接') // 相机设备状态 +const camera1Status = ref('未连接') +const camera2Status = ref('未连接') +const cameraStatus = computed(() => (camera1Status.value === '已连接' || camera2Status.value === '已连接') ? '已连接' : '未连接') const femtoboltStatus = ref('未连接') // 深度相机(FemtoBolt)设备状态 const imuStatus = ref('未连接') // IMU设备状态 const pressureStatus = ref('未连接') // 压力传感器设备状态 @@ -937,7 +939,8 @@ function connectWebSocket() { console.log('🔗 设备命名空间连接成功') // 连接成功后订阅所有设备数据 - devicesSocket.emit('subscribe_device', { device_type: 'camera' }) + devicesSocket.emit('subscribe_device', { device_type: 'camera1' }) + devicesSocket.emit('subscribe_device', { device_type: 'camera2' }) devicesSocket.emit('subscribe_device', { device_type: 'femtobolt' }) devicesSocket.emit('subscribe_device', { device_type: 'imu' }) devicesSocket.emit('subscribe_device', { device_type: 'pressure' }) @@ -949,7 +952,8 @@ function connectWebSocket() { devicesSocket.on('disconnect', () => { console.log('🔗 设备命名空间断开连接') // 断开连接时重置所有设备状态 - cameraStatus.value = '未连接' + camera1Status.value = '未连接' + camera2Status.value = '未连接' femtoboltStatus.value = '未连接' imuStatus.value = '未连接' pressureStatus.value = '未连接' @@ -1019,9 +1023,13 @@ function connectWebSocket() { const statusText = status ? '已连接' : '未连接' switch (device_type) { - case 'camera': - cameraStatus.value = statusText - console.log(`📷 相机状态: ${statusText}`) + case 'camera1': + camera1Status.value = statusText + console.log(`📷 相机1状态: ${statusText}`) + break + case 'camera2': + camera2Status.value = statusText + console.log(`📷 相机2状态: ${statusText}`) break case 'femtobolt': femtoboltStatus.value = statusText @@ -1080,7 +1088,8 @@ function disconnectWebSocket() { if (devicesSocket.connected) { // 取消订阅所有设备 try { - devicesSocket.emit('unsubscribe_device', { device_type: 'camera' }) + devicesSocket.emit('unsubscribe_device', { device_type: 'camera1' }) + devicesSocket.emit('unsubscribe_device', { device_type: 'camera2' }) devicesSocket.emit('unsubscribe_device', { device_type: 'femtobolt' }) devicesSocket.emit('unsubscribe_device', { device_type: 'imu' }) devicesSocket.emit('unsubscribe_device', { device_type: 'pressure' }) @@ -1106,7 +1115,8 @@ function disconnectWebSocket() { } // 重置所有设备状态 - cameraStatus.value = '未连接' + camera1Status.value = '未连接' + camera2Status.value = '未连接' femtoboltStatus.value = '未连接' imuStatus.value = '未连接' pressureStatus.value = '未连接' @@ -1501,11 +1511,17 @@ async function saveDetectionData() { pressure_image = tempInfo.value.pressure_data.foot_pressure.pressure_image foot_data = tempInfo.value.pressure_data.foot_pressure.pressure_zones } - let foot_image="" - if(tempInfo.value.camera_frame != null - && tempInfo.value.camera_frame.image != null ){ - foot_image=base64 + tempInfo.value.camera_frame.image + let foot1_image="" + if(tempInfo.value.camera1_frame != null + && tempInfo.value.camera1_frame.image != null ){ + foot1_image=base64 + tempInfo.value.camera1_frame.image } + let foot2_image="" + if(tempInfo.value.camera2_frame != null + && tempInfo.value.camera2_frame.image != null ){ + foot2_image=base64 + tempInfo.value.camera2_frame.image + } + let head_pose={} if(tempInfo.value.imu_data != null ){ @@ -1526,7 +1542,8 @@ async function saveDetectionData() { body_image: body_image, foot_data:foot_data, - foot_image:foot_image, + foot1_image:foot1_image, + foot2_image:foot2_image, foot_data_image:pressure_image, screen_image:null @@ -1569,7 +1586,7 @@ async function saveDetectionData() { // 调用后端API保存检测数据 async function sendDetectionData(data) { try { - const response = await fetch(`${BACKEND_URL}/api/detection/${patientInfo.value.sessionId}/collect` + const response = await fetch(`${BACKEND_URL}/api/detection/${patientInfo.value.sessionId}/save-data` , { method: 'POST', headers: { @@ -1872,8 +1889,8 @@ onMounted(() => { console.log(authStore.currentUser) creatorId.value = authStore.currentUser.id } - // patientId.value = props.selectedPatient.id - patientId.value = '202511150005' + patientId.value = props.selectedPatient.id + //patientId.value = '202511150005' // 加载患者信息 loadPatientInfo() // 启动检测 @@ -2053,8 +2070,10 @@ function refreshClick(type) { }, 5000) ElMessage.warning(`🚀 发送重启设备请求...`) if (devicesSocket && devicesSocket.connected) { - if(type == 'camera'){ - devicesSocket.emit('restart_device', { device_type: 'camera' }) + if(type == 'camera1'){ + devicesSocket.emit('restart_device', { device_type: 'camera1' }) + }else if(type == 'camera2'){ + devicesSocket.emit('restart_device', { device_type: 'camera2' }) }else if(type == 'femtobolt'){ devicesSocket.emit('restart_device', { device_type: 'femtobolt' }) }else if(type == 'imu'){ @@ -2716,4 +2735,4 @@ function handleEditUserInfo(){ padding-top: 50px; padding-right: 10px; } - \ No newline at end of file +