更新睡眠报告时区显示问题。
This commit is contained in:
@@ -13,6 +13,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/base64Tool.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/model/WebSocketMessage.dart';
|
||||
@@ -39,6 +40,7 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
RxBool initFlag = false.obs;
|
||||
Timer? _resourceLoadTimer;
|
||||
Widget webviewWidget = Container();
|
||||
var wifiResponseData;
|
||||
|
||||
WebviewTestController() : super(WebviewTestModel()) {
|
||||
web = WebviewHelper(
|
||||
@@ -147,6 +149,7 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
'mac'.tr: selectDevice['mac'.tr],
|
||||
})));
|
||||
dealInstantData(selectDevice);
|
||||
dealDeviceData(selectDevice);
|
||||
} catch (e) {
|
||||
ef.log("[切换设备失败]$e");
|
||||
}
|
||||
@@ -189,26 +192,26 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
return instantData;
|
||||
});
|
||||
bridge.sdk.startTimer((args) async {
|
||||
ef.log('queryInstantData: $args');
|
||||
ef.log('开启定时: $args');
|
||||
MHTHomeController homeController = Get.find();
|
||||
homeController.startTimer(args);
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.cancelTimer((args) async {
|
||||
ef.log('queryInstantData: $args');
|
||||
ef.log('退出定时: $args');
|
||||
MHTHomeController homeController = Get.find();
|
||||
homeController.cancelTimer(args);
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.restoreTimer((args) async {
|
||||
ef.log('更新定时: $args[0]');
|
||||
ef.log('queryInstantData: $args');
|
||||
ef.log('更新定时: $args');
|
||||
MHTHomeController homeController = Get.find();
|
||||
var data = await homeController.restoreTimer(args);
|
||||
return data;
|
||||
});
|
||||
bridge.sdk.toBindDevice((args) async {
|
||||
ef.log('queryInstantData: $args');
|
||||
ef.log('绑定设备: $args');
|
||||
Get.toNamed("/mHTDeviceTypePage");
|
||||
return true;
|
||||
});
|
||||
@@ -471,7 +474,100 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
);
|
||||
ws.connect();
|
||||
}
|
||||
//EasyFlutter End
|
||||
|
||||
void dealDeviceData(selectDevice) {
|
||||
// 处理设备本身的数据
|
||||
var ws;
|
||||
ws = Easyws(
|
||||
url: ServiceConstant.webSocketService,
|
||||
onData: (data) {
|
||||
try {
|
||||
var tmp;
|
||||
if (data is String) {
|
||||
tmp = jsonDecode(data);
|
||||
} else if (data is Map<String, dynamic>) {
|
||||
tmp = data; // 直接用
|
||||
} else {
|
||||
print("未知数据格式".tr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tmp['data'] != null && tmp['data'] is Map) {
|
||||
var newData = tmp['data'];
|
||||
var mac = newData['mac'];
|
||||
String order = Base64Tool.decode(newData['data']);
|
||||
final webviewTestController = Get.find<WebviewTestController>();
|
||||
webviewTestController.web.jsbridge?.dart
|
||||
?.updateDeviceStatusByWifi(order);
|
||||
// 检查是否是当前设备的MAC
|
||||
// if (mac != null && mac == selectDevice['mac']) {
|
||||
// // 更新或添加设备数据
|
||||
// int index = wifiResponseData
|
||||
// .indexWhere((element) => element['mac'] == mac);
|
||||
// if (index >= 0) {
|
||||
// // 更新现有数据
|
||||
// wifiResponseData[index] = newData;
|
||||
// } else {
|
||||
// // 添加新数据
|
||||
// wifiResponseData.add(newData);
|
||||
// }
|
||||
|
||||
// // 可以在这里触发UI更新或其他处理
|
||||
// // 例如:Get.find<SomeController>().updateDeviceData(newData);
|
||||
// print("✅ 收到设备数据: ${newData.toString()}");
|
||||
// }
|
||||
}
|
||||
} catch (e) {
|
||||
ef.log("ws error =>$e");
|
||||
}
|
||||
},
|
||||
onStateChange: (x) {
|
||||
ef.log("ws状态变化 =>$x");
|
||||
if (x == EasywsState.connected) {
|
||||
try {
|
||||
// 1. 先取消可能存在的旧设备监听
|
||||
if (lastSelectDevice != null && lastSelectDevice.isNotEmpty) {
|
||||
String? oldMac = lastSelectDevice['mac'];
|
||||
if (oldMac != null && oldMac.isNotEmpty) {
|
||||
bool success = ws.send({
|
||||
"type": 2, // 取消监听
|
||||
"path": "/vsbs/web/rt/marttress", // 注意:可能需要不同的路径
|
||||
"data": {"mac": oldMac},
|
||||
});
|
||||
if (success) {
|
||||
ef.log("✅ 已取消监听旧设备:$oldMac");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
ef.log("❌ 取消旧设备监听失败: $e");
|
||||
}
|
||||
|
||||
try {
|
||||
// 2. 开始监听新设备
|
||||
if (selectDevice != null && selectDevice.isNotEmpty) {
|
||||
String? newMac = selectDevice['mac'];
|
||||
if (newMac != null && newMac.isNotEmpty) {
|
||||
bool success = ws.send({
|
||||
"type": 1, // 开始监听
|
||||
"path": "/vsbs/web/rt/marttress", // 设备数据的路径,可能需要确认
|
||||
"data": {"mac": newMac},
|
||||
});
|
||||
if (success) {
|
||||
ef.log("✅ 开始监听设备:$newMac");
|
||||
// 更新记录
|
||||
lastSelectDevice = selectDevice;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
ef.log("❌ 监听新设备失败: $e");
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
ws.connect();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
|
||||
Reference in New Issue
Block a user