更新实时体征连接

This commit is contained in:
wyf
2025-09-19 14:49:25 +08:00
parent 676c51f339
commit aaf378e016
2 changed files with 54 additions and 45 deletions

View File

@@ -57,6 +57,58 @@ class _InstantBodyPageState extends State<InstantBodyPage>
// type: 1,
// data: {"mac": widget.personInfo['mac']})));
// _startOnlineTimer(); // 初始化时启动定时器
try {
Future.delayed(Duration(seconds: 0), () {
CommonVariables.callMap["/vsbs/web/rt/marttress"] = (data) {
edm.EasyDartModule.logger.info("[websocket]实时体征页面数据-->${data}]");
ef.log("[websocket]实时体征页面数据-->${data}]");
if (data['status'] == "离线") {
inBed = "-";
bodyMotion = -1;
heartrate = -1;
snores = "-";
breathrate = -1;
breathState = "-";
onlineState = "离线".tr;
return;
}
inBed = data["inBed"];
// 心率 呼吸 体动 呼吸暂停
if ("离床".tr == inBed) {
breathState = "".tr;
bodyMotion = 0;
breathrate = 0;
heartrate = 0;
snores = "".tr;
} else {
onlineState = "在线".tr; // 接收到数据,设置为在线
breathState =
data["breathState"] == null || data["breathState"] == ""
? "-"
: data["breathState"].toString().tr;
bodyMotion = data['bodyMotion'] == null ? -1 : data['bodyMotion'];
breathrate = data["breathRate"] == null ? -1 : data["breathRate"];
heartrate = data['heartRate'] == null ? -1 : data['heartRate'];
snores = data['snores'] == null || data['snores'] == ""
? "".tr
: "".tr;
}
if (mounted) {
setState(() {
onlineState = "在线".tr; // 接收到数据,设置为在线
});
}
_startOnlineTimer(); // 重置定时器
};
});
} catch (e) {
print(e);
edm.EasyDartModule.logger
.error("[webscoekt]格式化数据错误-->${{"mac": widget.personInfo['mac']}}");
}
_initWebSocket();
super.initState();
}
@@ -92,6 +144,7 @@ class _InstantBodyPageState extends State<InstantBodyPage>
WidgetsBinding.instance.removeObserver(this); // 移除生命周期观察者
_onlineTimer?.cancel();
_closeWebSocket();
CommonVariables.callMap.remove("/vsbs/web/rt/marttress");
super.dispose();
}
@@ -129,50 +182,6 @@ class _InstantBodyPageState extends State<InstantBodyPage>
@override
Widget build(BuildContext context) {
Map device = widget.personInfo;
try {
CommonVariables.callMap["/vsbs/web/rt/marttress"] = (data) {
if (data['status'] == "离线") {
inBed = "-";
bodyMotion = -1;
heartrate = -1;
snores = "-";
breathrate = -1;
breathState = "-";
return;
}
inBed = data["inBed"];
// 心率 呼吸 体动 呼吸暂停
if ("离床".tr == inBed) {
breathState = "".tr;
bodyMotion = 0;
breathrate = 0;
heartrate = 0;
snores = "".tr;
} else {
onlineState = "在线".tr; // 接收到数据,设置为在线
breathState = data["breathState"] == null || data["breathState"] == ""
? "-"
: data["breathState"].toString().tr;
bodyMotion = data['bodyMotion'] == null ? -1 : data['bodyMotion'];
breathrate = data["breathRate"] == null ? -1 : data["breathRate"];
heartrate = data['heartRate'] == null ? -1 : data['heartRate'];
snores =
data['snores'] == null || data['snores'] == "" ? "".tr : "".tr;
}
if (mounted) {
setState(() {
onlineState = "在线".tr; // 接收到数据,设置为在线
});
}
_startOnlineTimer(); // 重置定时器
};
} catch (e) {
print(e);
edm.EasyDartModule.logger
.error("[webscoekt]格式化数据错误-->${{"mac": widget.personInfo['mac']}}");
}
return LayoutBuilder(
builder: (context, bodySize) => GestureDetector(