From ea01d79bbdc652d0d6c5bd1243c68eab248c611c Mon Sep 17 00:00:00 2001 From: liyi Date: Mon, 28 Apr 2025 09:20:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=91?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuringWifi_logic.dart | 164 +++++++----------- .../configuringWifi/configuringWifi_page.dart | 2 +- .../wifiList/wifiList_logic.dart | 25 +-- 3 files changed, 81 insertions(+), 110 deletions(-) diff --git a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart index 3b23c309..76cc2bf4 100755 --- a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart +++ b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart @@ -181,17 +181,28 @@ class ConfiguringWifiLogic extends BaseGetXController { // 保存到缓存 await Storage.saveLockNetWorkInfo(jsonMap); - await _getUploadLockSet(); + showToast('配网成功'.tr, something: () { + state.sureBtnState.value = 0; // 确保重置状态 + if (state.pageName.value == 'lockSet') { + Get.close(2); + } else { + Get.offAllNamed(Routers.starLockMain); + } + eventBus.fire(SuccessfulDistributionNetwork()); + }); + + // 获取锁设置 + _getUploadLockSet(); } else { dismissEasyLoading(); - showToast('网络配置失败,请重试'.tr); + // showToast('网络配置失败,请重试'.tr); state.sureBtnState.value = 0; } } catch (e) { if (EasyLoading.isShow) { dismissEasyLoading(); } - showToast('解析配网信息失败,请重试'.tr); + // showToast('解析配网信息失败,请重试'.tr); state.sureBtnState.value = 0; // 确保重置状态 AppLog.log('解析配网信息失败: $e'); return; // 添加return阻止后续流程 @@ -203,7 +214,7 @@ class ConfiguringWifiLogic extends BaseGetXController { if (EasyLoading.isShow) { dismissEasyLoading(); } - showToast('WiFi密码错误,请重新输入'.tr); + // showToast('WiFi密码错误,请重新输入'.tr); state.sureBtnState.value = 0; // 确保重置状态 break; @@ -212,7 +223,7 @@ class ConfiguringWifiLogic extends BaseGetXController { if (EasyLoading.isShow) { dismissEasyLoading(); } - showToast('找不到该WiFi网络,请确认WiFi名称正确'.tr); + // showToast('找不到该WiFi网络,请确认WiFi名称正确'.tr); state.sureBtnState.value = 0; // 确保重置状态 break; @@ -221,7 +232,7 @@ class ConfiguringWifiLogic extends BaseGetXController { if (EasyLoading.isShow) { dismissEasyLoading(); } - showToast('连接WiFi超时,请确保网络信号良好'.tr); + // showToast('连接WiFi超时,请确保网络信号良好'.tr); state.sureBtnState.value = 0; // 确保重置状态 break; @@ -230,7 +241,7 @@ class ConfiguringWifiLogic extends BaseGetXController { if (EasyLoading.isShow) { dismissEasyLoading(); } - showToast('配网失败 (错误码: $status),请重试'.tr); + // showToast('配网失败 (错误码: $status),请重试'.tr); state.sureBtnState.value = 0; // 确保重置状态 break; } @@ -315,12 +326,15 @@ class ConfiguringWifiLogic extends BaseGetXController { } // 设置蓝牙操作超时处理 - showBlueConnetctToastTimer(action: () { - if (EasyLoading.isShow) { - dismissEasyLoading(); - } - state.sureBtnState.value = 0; // 连接超时时重置状态 - }); + showBlueConnetctToastTimer( + action: () { + if (EasyLoading.isShow) { + dismissEasyLoading(); + } + state.sureBtnState.value = 0; // 连接超时时重置状态 + }, + outTimer: 30, + ); // 发送配网指令 BlueManage().blueSendData( @@ -340,7 +354,7 @@ class ConfiguringWifiLogic extends BaseGetXController { } cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; // 发送命令失败时重置状态 - showToast('发送配网指令失败:${e.toString()}'.tr); + // showToast('发送配网指令失败:${e.toString()}'.tr); } } else if (connectionState == BluetoothConnectionState.disconnected) { if (EasyLoading.isShow) { @@ -474,70 +488,53 @@ class ConfiguringWifiLogic extends BaseGetXController { default: //失败 dismissEasyLoading(); - showToast('获取设备状态失败'.tr); + // showToast('获取设备状态失败'.tr); break; } } // 上传数据获取设置 Future _getUploadLockSet() async { - // 保持已有的loading状态,不再重新显示loading - showBlueConnetctToastTimer(action: () { - if (EasyLoading.isShow) { - dismissEasyLoading(); - } - state.sureBtnState.value = 0; - }); - - try { - final List? token = await Storage.getStringList(saveBlueToken); - if (token == null || token.isEmpty) { - throw Exception('Token is empty'); - } - final List getTokenList = changeStringListToIntList(token); - // 蓝牙获取锁设置 - await _uploadLockSet(getTokenList); - } catch (e) { - if (EasyLoading.isShow) { - dismissEasyLoading(); - } - cancelBlueConnetctToastTimer(); - state.sureBtnState.value = 0; - } + final List? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + // 蓝牙获取锁设置 + await _uploadLockSet(getTokenList); } // 公共的上传锁设置 Future _uploadLockSet(List token) async { - try { - final List? privateKey = - await Storage.getStringList(saveBluePrivateKey); - if (privateKey == null || privateKey.isEmpty) { - throw Exception('Private key is empty'); - } - final List getPrivateKeyList = changeStringListToIntList(privateKey); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + if (privateKey == null || privateKey.isEmpty) { + throw Exception('Private key is empty'); + } + final List getPrivateKeyList = changeStringListToIntList(privateKey); - final List? signKey = - await Storage.getStringList(saveBlueSignKey); - if (signKey == null || signKey.isEmpty) { - throw Exception('Sign key is empty'); - } - final List signKeyDataList = changeStringListToIntList(signKey); + final List? signKey = await Storage.getStringList(saveBlueSignKey); + if (signKey == null || signKey.isEmpty) { + throw Exception('Sign key is empty'); + } + final List signKeyDataList = changeStringListToIntList(signKey); - IoSenderManage.updataLockSetCommand( + BlueManage().blueSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { + IoSenderManage.updataLockSetCommand( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), token: token, needAuthor: 1, signKey: signKeyDataList, - privateKey: getPrivateKeyList); - } catch (e) { - if (EasyLoading.isShow) { + privateKey: getPrivateKeyList, + ); + } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + if (state.ifCurrentScreen.value == true) { + showBlueConnetctToast(); + } } - cancelBlueConnetctToastTimer(); - showToast('上传设置失败:${e.toString()}'.tr); - state.sureBtnState.value = 0; - } + }, isAddEquipment: true); } // 上传数据获取锁设置解析 @@ -565,7 +562,7 @@ class ConfiguringWifiLogic extends BaseGetXController { if (EasyLoading.isShow) { dismissEasyLoading(); // 错误时关闭loading } - showToast('获取设置权限失败:${e.toString()}'.tr); + // showToast('获取设置权限失败:${e.toString()}'.tr); state.sureBtnState.value = 0; // 确保重置状态 } break; @@ -574,7 +571,7 @@ class ConfiguringWifiLogic extends BaseGetXController { if (EasyLoading.isShow) { dismissEasyLoading(); // 错误时关闭loading } - showToast('获取锁设置失败 (错误码: $status)'.tr); + // showToast('获取锁设置失败 (错误码: $status)'.tr); state.sureBtnState.value = 0; // 确保重置状态 break; } @@ -585,43 +582,16 @@ class ConfiguringWifiLogic extends BaseGetXController { {required int uploadType, required int recordType, required List records}) async { - try { - final LoginEntity entity = await ApiRepository.to.lockDataUpload( - lockId: state.lockBasicInfo.value.lockId ?? -1, - uploadType: uploadType, - recordType: recordType, - records: records, - isUnShowLoading: true); + final LoginEntity entity = await ApiRepository.to.lockDataUpload( + lockId: state.lockBasicInfo.value.lockId ?? -1, + uploadType: uploadType, + recordType: recordType, + records: records, + isUnShowLoading: true); - if (entity.errorCode!.codeIsSuccessful) { - if (EasyLoading.isShow) { - dismissEasyLoading(); - } - showToast('配网成功'.tr, something: () { - state.sureBtnState.value = 0; // 确保重置状态 - if (state.pageName.value == 'lockSet') { - Get.close(2); - } else { - Get.offAllNamed(Routers.starLockMain); - } - - eventBus.fire( - PassCurrentLockInformationEvent(state.lockSetInfoData.value)); - eventBus.fire(SuccessfulDistributionNetwork()); - }); - } else { - if (EasyLoading.isShow) { - dismissEasyLoading(); - } - // showToast('数据上传失败:${entity.errorCode}'.tr); - state.sureBtnState.value = 0; // 确保重置状态 - } - } catch (e) { - if (EasyLoading.isShow) { - dismissEasyLoading(); - } - // showToast('数据上传异常:${e.toString()}'.tr); - state.sureBtnState.value = 0; // 确保重置状态 + if (entity.errorCode!.codeIsSuccessful) { + eventBus + .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); } } } diff --git a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_page.dart b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_page.dart index 51c45a9d..33a38066 100755 --- a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_page.dart +++ b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_page.dart @@ -51,7 +51,7 @@ class _ConfiguringWifiPageState extends State () => SubmitBtn( btnName: state.sureBtnState.value == 1 ? '配置中...'.tr : '确定'.tr, // 当sureBtnState为1时按钮不可用 - isDisabled: state.sureBtnState.value == 1, + isDisabled: state.sureBtnState.value == 0, onClick: state.sureBtnState.value == 1 ? null : () { diff --git a/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart b/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart index 6ee5bea6..93532323 100755 --- a/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart +++ b/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart @@ -37,14 +37,14 @@ class WifiListLogic extends BaseGetXController { }, onError: (error) { // 处理CRC校验失败等错误 AppLog.log('WiFi列表获取过程中发生错误: $error'); - + // 取消loading状态,显示错误提示 dismissEasyLoading(); cancelBlueConnetctToastTimer(); - + // 重置按钮状态,允许重新扫描 state.sureBtnState.value = 0; - + // 如果是CRC校验失败,显示特定提示 if (error.toString().contains('CRC')) { showToast('数据校验失败,请重新扫描'.tr); @@ -91,29 +91,29 @@ class WifiListLogic extends BaseGetXController { // 把得到的数据按33位分割成数组然后处理 final List> getList = splitList(reply.data, 33); final List> uploadList = >[]; - + for (int i = 0; i < getList.length; i++) { final List indexList = getList[i]; final Map indexMap = {}; final List wifiName = indexList.sublist(0, 32); final String wifiNameStr = utf8String(wifiName).trim(); - + // 过滤掉空的WiFi名称 if (wifiNameStr.isEmpty) { continue; } - + indexMap['wifiName'] = wifiNameStr; indexMap['rssi'] = (indexList.last - 255).toString(); uploadList.add(indexMap); } - + // 按信号强度排序WiFi列表 (从强到弱) - uploadList.sort((a, b) => - int.parse(b['rssi']!).compareTo(int.parse(a['rssi']!))); - + uploadList.sort( + (a, b) => int.parse(b['rssi']!).compareTo(int.parse(a['rssi']!))); + state.wifiNameDataList.value = uploadList; - + if (uploadList.isEmpty) { showToast('未检测到可用的WiFi网络'.tr); } @@ -144,7 +144,7 @@ class WifiListLogic extends BaseGetXController { showBlueConnetctToastTimer(action: () { state.sureBtnState.value = 0; }); - + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { if (connectionState == BluetoothConnectionState.connected) { @@ -172,6 +172,7 @@ class WifiListLogic extends BaseGetXController { super.onReady(); _initReplySubscription(); await senderGetWifiListWifiAction(); + dismissEasyLoading(); } @override