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 @@