diff --git a/assets/miniapp/mhtControl_1.0.0.zip b/assets/miniapp/mhtControl_1.0.0.zip index c9fd3a1..99c3bf4 100644 Binary files a/assets/miniapp/mhtControl_1.0.0.zip and b/assets/miniapp/mhtControl_1.0.0.zip differ diff --git a/lib/controller/mh_controller/people_info_controller.dart b/lib/controller/mh_controller/people_info_controller.dart index 61c8659..5034a7d 100644 --- a/lib/controller/mh_controller/people_info_controller.dart +++ b/lib/controller/mh_controller/people_info_controller.dart @@ -41,7 +41,7 @@ class PeopleInfoController extends GetControllerEx { @override Future onInit() async { super.onInit(); - await getPeoples(Get.arguments['mac']); // 控制器创建时立即执行 + // await getPeoples(Get.arguments['mac']); // 控制器创建时立即执行 } getPeoples(String mac) async { diff --git a/lib/controller/user_info_controller.dart b/lib/controller/user_info_controller.dart index df62545..50326f3 100644 --- a/lib/controller/user_info_controller.dart +++ b/lib/controller/user_info_controller.dart @@ -60,7 +60,7 @@ class UserInfoController extends GetControllerEx { RxDouble textHalfWidth = 0.0.obs; List device_bind_status = []; - int device_bind_flag = 0;//0。未初始化 1.已初始化 + int device_bind_flag = 0; //0。未初始化 1.已初始化 Future uploadImg() async { EasyDartModule.logger.info("请求上传图片"); @@ -133,6 +133,10 @@ class UserInfoController extends GetControllerEx { apiResponse.msg = "昵称为空".tr; return apiResponse; } + if (user.tmpNickName!.length >= 9) { + apiResponse.msg = "最长字符为8个字".tr; + return apiResponse; + } String serviceAddress = ServiceConstant.service_address; String serviceName = ServiceConstant.server_service; String serviceApi = ServiceConstant.user_info; diff --git a/lib/pages/mh_page/device/controller/mht_bluetooth_controller.dart b/lib/pages/mh_page/device/controller/mht_bluetooth_controller.dart index f674ef5..02125d2 100644 --- a/lib/pages/mh_page/device/controller/mht_bluetooth_controller.dart +++ b/lib/pages/mh_page/device/controller/mht_bluetooth_controller.dart @@ -189,6 +189,7 @@ class MHTBlueToothController extends GetControllerEx { return res; } else { model.deviceDataStatus = []; + return ApiResponse(code:1, msg: "".tr); } } catch (e) { print("获取设备状态异常: $e"); @@ -218,10 +219,10 @@ class MHTBlueToothController extends GetControllerEx { "macA": bleDevice.macA, if (bleDevice.macB != null && bleDevice.macB!.isNotEmpty) "macB": bleDevice.macB, - if (bleDevice.name!=null && bleDevice.name!.isNotEmpty) - 'param':{ - 'name':bleDevice.name, - }, + if (bleDevice.name != null && bleDevice.name!.isNotEmpty) + 'param': { + 'name': bleDevice.name, + }, }; var response = @@ -237,8 +238,8 @@ class MHTBlueToothController extends GetControllerEx { // personController.currentPersonId.value = res.data['id']; //todo 绑定成功需要返回传感器id currentDeviceMac.value = ""; - if(res.data!=null){ - if(currentFullDevice!=null){ + if (res.data != null) { + if (currentFullDevice != null) { currentFullDevice!.macAID = res.data['macA']; currentFullDevice!.macBID = res.data['macB']; } diff --git a/lib/pages/mh_page/device/mht_blueteeth_device_page.dart b/lib/pages/mh_page/device/mht_blueteeth_device_page.dart index 75ffa9f..c19d92b 100644 --- a/lib/pages/mh_page/device/mht_blueteeth_device_page.dart +++ b/lib/pages/mh_page/device/mht_blueteeth_device_page.dart @@ -112,97 +112,105 @@ class _MHTBlueteethDevicePageState extends State { } void _startScanning() async { - if (!mounted || isScanning || !mhtBlueToothController.shouldScan.value) - return; + try { + if (!mounted || isScanning || !mhtBlueToothController.shouldScan.value) + return; - _scanSubscription?.cancel(); - var bluetoothState = await FlutterBluePlus.isOn; - mhtBlueToothController.model.bluetooth = bluetoothState; - mhtBlueToothController.updateAll(); - - if (!bluetoothState && !_isDialogShowing) { - _isDialogShowing = true; - mhtBlueToothController.model.blueRawData = []; - mhtBlueToothController.model.deviceDataStatus = []; + _scanSubscription?.cancel(); + var bluetoothState = await FlutterBluePlus.isOn; + mhtBlueToothController.model.bluetooth = bluetoothState; mhtBlueToothController.updateAll(); - await _showBluetoothNotEnabledDialog(); - _isDialogShowing = false; - return; - } - if (!isScanning) { - setState(() { - isScanning = true; - }); - - await FlutterBluePlus.startScan(timeout: Duration(seconds: 10)); - - _scanSubscription = FlutterBluePlus.scanResults.listen((results) { - if (!mounted) return; - - final signalThreshold = mhtBlueToothController.model.singal!; - final searchKey = - mhtBlueToothController.search.value.trim().toLowerCase(); - - final filteredResults = results.where((r) { - final localName = r.advertisementData.localName; - final isTarget = r.rssi > signalThreshold && - isTargetDevice( - localName, widget.deviceType['reg'].cast()); - if (!isTarget) return false; - final name = r.advertisementData.advName.toLowerCase(); - String macAddress = r.device.remoteId.str; - final mac = macAddress.replaceAll(':', ''); - final search = searchKey.trim().replaceAll(':', '').toLowerCase(); - - if (search.isNotEmpty && - !name.contains(search) && - !mac.replaceAll(':', '').toLowerCase().contains(search)) { - return false; - } - - return true; - }).map((r) { - return BlueToothDataModel.fromScanResult( - r, widget.deviceType['type']?.toInt(), - bind: false, - name: r.advertisementData.localName, - mac: r.device.remoteId.str.replaceAll(':', '')); - }).toList(); - - final currentDevices = mhtBlueToothController.model.blueRawData ?? []; - final newDevices = []; - - for (var newDevice in filteredResults) { - // 检查设备是否已存在 - final existingIndex = - currentDevices.indexWhere((d) => d.mac == newDevice.mac); - - if (existingIndex >= 0) { - // 更新已有设备信息(如信号强度) - currentDevices[existingIndex] = newDevice; - } else { - // 添加新设备 - newDevices.add(newDevice); - } - } - - setState(() { - mhtBlueToothController.model.blueRawData = [ - ...currentDevices, - ...newDevices - ]; - }); - }); - - await Future.delayed(Duration(seconds: 10)); - await FlutterBluePlus.stopScan(); - - if (mounted) { - setState(() { - isScanning = false; - }); + if (!bluetoothState && !_isDialogShowing) { + _isDialogShowing = true; + mhtBlueToothController.model.blueRawData = []; + mhtBlueToothController.model.deviceDataStatus = []; + mhtBlueToothController.updateAll(); + await _showBluetoothNotEnabledDialog(); + _isDialogShowing = false; + return; } + + if (!isScanning) { + setState(() { + isScanning = true; + }); + + await FlutterBluePlus.startScan(timeout: Duration(seconds: 10)); + + _scanSubscription = FlutterBluePlus.scanResults.listen((results) { + if (!mounted) return; + + final signalThreshold = mhtBlueToothController.model.singal!; + final searchKey = + mhtBlueToothController.search.value.trim().toLowerCase(); + + final filteredResults = results.where((r) { + final localName = r.advertisementData.localName; + final isTarget = r.rssi > signalThreshold && + isTargetDevice( + localName, widget.deviceType['reg'].cast()); + if (!isTarget) return false; + final name = r.advertisementData.advName.toLowerCase(); + String macAddress = r.device.remoteId.str; + final mac = macAddress.replaceAll(':', ''); + final search = searchKey.trim().replaceAll(':', '').toLowerCase(); + + if (search.isNotEmpty && + !name.contains(search) && + !mac.replaceAll(':', '').toLowerCase().contains(search)) { + return false; + } + + return true; + }).map((r) { + return BlueToothDataModel.fromScanResult( + r, widget.deviceType['type']?.toInt(), + bind: false, + name: r.advertisementData.localName, + mac: r.device.remoteId.str.replaceAll(':', '')); + }).toList(); + + final currentDevices = mhtBlueToothController.model.blueRawData ?? []; + final newDevices = []; + + for (var newDevice in filteredResults) { + // 检查设备是否已存在 + final existingIndex = + currentDevices.indexWhere((d) => d.mac == newDevice.mac); + + if (existingIndex >= 0) { + // 更新已有设备信息(如信号强度) + currentDevices[existingIndex] = newDevice; + } else { + // 添加新设备 + newDevices.add(newDevice); + } + } + + setState(() { + mhtBlueToothController.model.blueRawData = [ + ...currentDevices, + ...newDevices + ]; + }); + }); + + await Future.delayed(Duration(seconds: 10)); + await FlutterBluePlus.stopScan(); + + if (mounted) { + setState(() { + isScanning = false; + }); + } + } + } catch (e) { + ef.log("$e"); + } finally { + setState(() { + isScanning = false; + }); } } diff --git a/lib/pages/mh_page/people_info.dart b/lib/pages/mh_page/people_info.dart index 65168ec..58061d5 100644 --- a/lib/pages/mh_page/people_info.dart +++ b/lib/pages/mh_page/people_info.dart @@ -13,6 +13,7 @@ import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; import 'package:vbvs_app/controller/home/home_controller.dart'; import 'package:vbvs_app/controller/main_bottom/global_controller.dart'; import 'package:vbvs_app/controller/mh_controller/people_info_controller.dart'; +import 'package:vbvs_app/controller/person/person_controller.dart'; import 'package:vbvs_app/pages/common/selectDialog.dart'; import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart'; @@ -33,6 +34,7 @@ class PeopleInfoPage extends GetView { PeopleInfoController controller = Get.put(PeopleInfoController()); @override Widget build(BuildContext context) { + getPersonData(); return LayoutBuilder( builder: (context, boxConstraints) => GestureDetector( onTap: () { @@ -831,4 +833,9 @@ class PeopleInfoPage extends GetView { return "-"; } } + + Future getPersonData() async { + PeopleInfoController peopleInfoController = Get.find(); + await peopleInfoController.getPeoples(Get.arguments['mac']); // 控制器创建时立即执行 + } }