This commit is contained in:
wyf
2025-06-27 16:27:56 +08:00
parent ee88290dfe
commit cee6c75f26
10 changed files with 92 additions and 15 deletions

View File

@@ -20,6 +20,8 @@ import 'package:vbvs_app/model/api_response.dart';
import 'package:vbvs_app/pages/mh_page/component/mht_bind_dialog.dart';
import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.dart';
import 'package:vbvs_app/pages/mh_page/device/model/BlueToothDataModel.dart';
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
import 'package:vbvs_app/pages/mh_page/test/WebviewTestModel.dart';
class DeviceComponentWidget extends StatefulWidget {
BlueToothDataModel bleDevice;
@@ -36,6 +38,7 @@ class DeviceComponentWidget extends StatefulWidget {
class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
ThemeController themeController = Get.find();
MHTBlueToothController blueteethBindController = Get.find();
MHTHomeController homeController = Get.find();
var lisObj;
@override
@@ -172,7 +175,7 @@ class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
borderRadius: 16.rpx,
onTap: () async {
try {
// 连接前暂停扫描
//连接前暂停扫描
blueteethBindController.pauseScanning();
if (blueteethBindController.currentDeviceMac?.value !=
null &&
@@ -225,6 +228,40 @@ class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
TopSlideNotification.show(context,
text: response.msg!);
if (response.code == HttpStatusCodes.ok) {
try {
WebviewTestController webviewTestController =
Get.find();
webviewTestController.web.jsbridge?.dart
.unBindDevice();
} catch (e) {
ef.log("[h5]通知列表更新报错:$e");
}
homeController.getPersonList();
//请求绑定设备列表
// homeController.getSleepReport();
homeController.getDeviceNum().then((apiResponse) {
if (apiResponse.code != HttpStatusCodes.ok) {
TopSlideNotification.show(
Get.context!,
text: apiResponse.msg!,
textColor: themeController.currentColor.sc9,
);
}
});
homeController
.getDeviceList(group: 'room')
.then((apiResponse) {
if (apiResponse.code != HttpStatusCodes.ok) {
TopSlideNotification.show(
Get.context!,
text: apiResponse.msg!,
textColor: themeController.currentColor.sc9,
);
} else {
//请求睡眠报告
// deviceController.getSleepReport();
}
});
//更新设备绑定流程
Get.toNamed("/mHTwifiPage",
arguments: widget.bleDevice);
@@ -242,6 +279,7 @@ class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
textColor: themeController.currentColor.sc9,
);
}
blueteethBindController.resumeScanning();
},
onCancel: () {
print('用户点击了取消');
@@ -262,10 +300,11 @@ class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
DailyLogUtils.writeLog("连接异常: $e");
} finally {
// 确保在任何情况下都恢复扫描
if (blueteethBindController
.currentDeviceMac.value.isEmpty) {
blueteethBindController.resumeScanning();
}
// if (blueteethBindController
// .currentDeviceMac.value.isEmpty) {
// blueteethBindController.resumeScanning();
// }
blueteethBindController.resumeScanning();
}
},
colors: [stringToColor("1592AA"), stringToColor("006FA3")],
@@ -452,7 +491,7 @@ class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
try {
// 连接设备
THapp bledevice = THapp(device: device.scanResult.device);
await bledevice.connect();
await bledevice.connect();
var res2 = bledevice.isConnected;
if (!res2) {
@@ -468,7 +507,7 @@ class _DeviceComponentWidgetState extends State<DeviceComponentWidget> {
blueteethBindController.blueConnectFlag.value = 2;
blueteethBindController.currentDevice = bledevice;
await Future.delayed(Duration(seconds: 1));
var read = bledevice.getresource('fff0/fff1');
await read!.characteristic.setNotifyValue(true);
var write = bledevice.getresource('fff0/fff2');