This commit is contained in:
wyf
2025-08-04 10:10:44 +08:00
parent bc14dae324
commit 13ef007f88
13 changed files with 207 additions and 249 deletions

View File

@@ -137,9 +137,13 @@ class _LanguagePageState extends State<LanguagePage> {
.value = language;
final list = deviceController
.personnelList.value;
deviceController.getHomeSleeps(
list[0]["mac"], context);
if (list != null &&
list.isNotEmpty) {
deviceController
.getHomeSleeps(
list[0]["mac"],
context);
}
try {
// ef.kv.set("language",
// language.language_code);
@@ -203,10 +207,13 @@ class _LanguagePageState extends State<LanguagePage> {
deviceController
.personnelList
.value;
deviceController
.getHomeSleeps(
list[0]["mac"],
context);
if (list != null &&
list.isNotEmpty) {
deviceController
.getHomeSleeps(
list[0]["mac"],
context);
}
try {
// ef.kv.set("language",

View File

@@ -280,7 +280,7 @@ class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
1;
}
});
await homeController.getPersonList();
await homeController.getPersonList();
} else {
blueteethBindController.resumeScanning();
blueteethBindController.currentDeviceMac.value = "";
@@ -494,59 +494,130 @@ class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
}
//获取智能床/床垫mac
// Future<String> getBindTHMAC(
// BuildContext context, BlueToothDataModel device, Map deviceType) async {
// const int maxRetries = 2;
// const Duration timeout = Duration(seconds: 5);
// String? macAddress;
// try {
// // 连接设备
// THapp bledevice = THapp(device: device.scanResult.device);
// await bledevice.connect();
// var res2 = bledevice.isConnected;
// if (!res2) {
// edm.EasyDartModule.logger.error("蓝牙连接失败".tr);
// DailyLogUtils.printLog("蓝牙连接失败".tr);
// TopSlideNotification.show(
// context,
// text: "蓝牙连接失败".tr,
// textColor: themeController.currentColor.sc9,
// );
// throw Exception("蓝牙连接失败".tr);
// }
// blueteethBindController.blueConnectFlag.value = 2;
// blueteethBindController.currentDevice = bledevice;
// await Future.delayed(Duration(seconds: 2));
// if (deviceType['type'] == 3) {
// //智能床垫
// macAddress = await getMacFromType3(bledevice, timeout);
// } else if (deviceType['type'] == 2) {
// //智能床
// macAddress = await getMacFromType2(bledevice, timeout);
// } else {
// throw Exception("不支持的设备类型".tr);
// }
// if (macAddress == null) {
// throw Exception("未能获取到MAC地址".tr);
// }
// // device.macA = macAddress;
// print('MAC地址: $macAddress');
// return macAddress;
// } catch (e) {
// blueteethBindController.currentDeviceMac.value = "";
// edm.EasyDartModule.logger.error("蓝牙获取MAC失败$e");
// DailyLogUtils.printLog("蓝牙获取MAC失败$e");
// TopSlideNotification.show(
// context,
// // text: e.message ?? "设备连接失败,请重试".tr,
// text: "获取不到传感器mac,请重试".tr,
// textColor: themeController.currentColor.sc9,
// );
// rethrow;
// }
// }
Future<String> getBindTHMAC(
BuildContext context, BlueToothDataModel device, Map deviceType) async {
const int maxRetries = 2;
const int maxRetries = 2; // 重试2次
const Duration timeout = Duration(seconds: 5);
String? macAddress;
try {
// 连接设备
THapp bledevice = THapp(device: device.scanResult.device);
await bledevice.connect();
var res2 = bledevice.isConnected;
if (!res2) {
edm.EasyDartModule.logger.error("蓝牙连接失败".tr);
DailyLogUtils.printLog("蓝牙连接失败".tr);
TopSlideNotification.show(
context,
text: "蓝牙连接失败".tr,
textColor: themeController.currentColor.sc9,
);
throw Exception("蓝牙连接失败".tr);
}
blueteethBindController.blueConnectFlag.value = 2;
blueteethBindController.currentDevice = bledevice;
await Future.delayed(Duration(seconds: 2));
if (deviceType['type'] == 3) {
//智能床垫
macAddress = await getMacFromType3(bledevice, timeout);
} else if (deviceType['type'] == 2) {
//智能床
macAddress = await getMacFromType2(bledevice, timeout);
} else {
throw Exception("不支持的设备类型".tr);
}
for (int attempt = 1; attempt <= maxRetries; attempt++) {
try {
// 连接设备
THapp bledevice = THapp(device: device.scanResult.device);
await bledevice.connect();
var res2 = bledevice.isConnected;
if (macAddress == null) {
throw Exception("未能获取到MAC地址".tr);
}
if (!res2) {
edm.EasyDartModule.logger.error("蓝牙连接失败".tr);
DailyLogUtils.printLog("蓝牙连接失败".tr);
TopSlideNotification.show(
context,
text: "蓝牙连接失败".tr,
textColor: themeController.currentColor.sc9,
);
throw Exception("蓝牙连接失败".tr);
}
// device.macA = macAddress;
print('MAC地址: $macAddress');
return macAddress;
} catch (e) {
blueteethBindController.currentDeviceMac.value = "";
edm.EasyDartModule.logger.error("蓝牙获取MAC失败$e");
DailyLogUtils.printLog("蓝牙获取MAC失败$e");
TopSlideNotification.show(
context,
// text: e.message ?? "设备连接失败,请重试".tr,
text: "获取不到传感器mac,请重试".tr,
textColor: themeController.currentColor.sc9,
);
rethrow;
blueteethBindController.blueConnectFlag.value = 2;
blueteethBindController.currentDevice = bledevice;
await Future.delayed(Duration(seconds: 2));
// 根据设备类型获取 MAC
if (deviceType['type'] == 3) {
macAddress = await getMacFromType3(bledevice, timeout);
} else if (deviceType['type'] == 2) {
macAddress = await getMacFromType2(bledevice, timeout);
} else {
throw Exception("不支持的设备类型".tr);
}
if (macAddress != null) {
print('MAC地址: $macAddress');
return macAddress; // 成功获取直接返回
}
// 当前尝试失败,准备重试
DailyLogUtils.printLog("$attempt次尝试未获取到MAC地址");
if (attempt < maxRetries) {
await Future.delayed(Duration(seconds: 1)); // 等待后重试
}
} catch (e) {
DailyLogUtils.printLog("$attempt次蓝牙获取MAC失败: $e");
edm.EasyDartModule.logger.error("$attempt次蓝牙获取MAC失败: $e");
// 最后一次尝试失败后才提示
if (attempt == maxRetries) {
blueteethBindController.currentDeviceMac.value = "";
TopSlideNotification.show(
context,
text: "获取不到传感器mac,请重试".tr,
textColor: themeController.currentColor.sc9,
);
rethrow; // 抛出最后的异常
}
// 否则继续尝试
}
}
// 正常不会到这里
throw Exception("未知错误");
}
fillTHMac(

View File

@@ -558,7 +558,7 @@ class _SettingPageState extends State<SettingPage> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'ICP备案号:ICP备2023000785号-1'.tr,
'ICP备案号:ICP备2024068219号-1A'.tr,
style: TextStyle(
color: themeController.currentColor.sc4,
fontFamily: 'Inter',
@@ -571,7 +571,7 @@ class _SettingPageState extends State<SettingPage> {
AppConstants().ent_type == 1
? 'Copyright © 202-2025 嘉兴太和信息技术有限责任公司 版权所有'
.tr
: "Copyright © 202-2025 杭州欢睡科技有限公司 版权所有".tr,
: "Copyright © 202-2025 合肥眠花糖家具有限责任公司 版权所有".tr,
style: TextStyle(
color: themeController.currentColor.sc4,
fontFamily: 'Inter',

View File

@@ -538,7 +538,7 @@ class WebviewTestView extends GetComponent<WebviewTestController> {
alignment: Alignment.topLeft,
child: Obx(() {
return (controller.ready.value)
?controller.web.build()
? controller.web.build()
: Center(child: CircularProgressIndicator());
}),
),