diff --git a/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index 2f056a02..e7bcae34 100755 --- a/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -225,7 +225,6 @@ class LockDetailLogic extends BaseGetXController { StartChartManage().lockPeerId.isNotEmpty) { sendStarChartOpenLockMessage(reply); } - break; case 0x16: // 正在开锁中... @@ -277,6 +276,7 @@ class LockDetailLogic extends BaseGetXController { //失败 // AppLog.log('开锁失败'); openDoorError(); + showToast('开锁失败'.tr); break; } } @@ -514,22 +514,39 @@ class LockDetailLogic extends BaseGetXController { ); BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, - (BluetoothConnectionState deviceConnectionState) async { - if (deviceConnectionState == BluetoothConnectionState.connected) { - BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false); - // FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令'); - IoSenderManage.senderOpenLock( - lockID: BlueManage().connectDeviceName, - userID: await Storage.getUid(), - openMode: state.openDoorModel, - openTime: getUTCNetTime(), - onlineToken: state.lockNetToken, - token: getTokenList, - needAuthor: 1, - signKey: signKeyDataList, - privateKey: getPrivateKeyList, - ); - }); + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false); + // FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令'); + IoSenderManage.senderOpenLock( + lockID: BlueManage().connectDeviceName, + userID: await Storage.getUid(), + openMode: state.openDoorModel, + openTime: getUTCNetTime(), + onlineToken: state.lockNetToken, + token: getTokenList, + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + ); + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + cancelBlueConnetctToastTimer(); + BuglyTool.uploadException( + message: '蓝牙连接失败-开锁失败', detail: '蓝牙连接失败,断开连接, 开锁失败--OpenLockCommand:$command', upload: true); + final String getMobile = (await Storage.getMobile())!; + ApmHelper.instance.trackEvent('open_lock', { + 'lock_name': state.keyInfos.value.lockName!, + 'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, + 'date': DateTool().getNowDateWithType(1), + 'open_lock_result': '断开连接', + }); + + // if (state.ifCurrentScreen.value == true) { + // showBlueConnetctToast(); + // } + resetOpenDoorState(); + } + }); } //蓝牙关闭 @@ -683,14 +700,12 @@ class LockDetailLogic extends BaseGetXController { var lockId = currentKeyInfo.lockId ?? 0; var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0; - var lockPeerId = StartChartManage().lockPeerId; - - if (lockPeerId.isEmpty) { - final network = currentKeyInfo.network; - if (network != null && network.peerId != null && network.peerId!.isNotEmpty) { - lockPeerId = network.peerId!; - StartChartManage().lockPeerId = lockPeerId; - } + // 每次远程开锁都使用当前锁的peerId,确保使用正确的锁 + final network = currentKeyInfo.network; + var lockPeerId = ''; + if (network != null && network.peerId != null && network.peerId!.isNotEmpty) { + lockPeerId = network.peerId!; + StartChartManage().lockPeerId = lockPeerId; } if (remoteUnlock == 1) { @@ -762,7 +777,6 @@ class LockDetailLogic extends BaseGetXController { if (userID == null || userID.isEmpty) { throw Exception('未找到用户ID'); } - AppLog.log('用户ID: $userID'); // 构建开锁命令 final OpenLockCommand openLockCommand = OpenLockCommand( @@ -776,11 +790,9 @@ class LockDetailLogic extends BaseGetXController { signKey: signKeyList, privateKey: privateKeyList, ); - AppLog.log('构建开锁命令成功'); // 包装命令数据 - final List messageDetail = openLockCommand.packageData(); - + final messageDetail = openLockCommand.packageData(); // 发送蓝牙透传开锁命令 StartChartManage().sendRemoteUnLockMessage( bluetoothDeviceName: bluetoothDeviceName, @@ -894,8 +906,6 @@ class LockDetailLogic extends BaseGetXController { } } - // 添加网络质量评估变量 - int _networkQualityScore = 5; // 1-5分,5为最佳 /// 发送监控消息 void sendMonitorMessage() async { final catEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig ?? []; @@ -909,30 +919,6 @@ class LockDetailLogic extends BaseGetXController { return; } } - // 根据网络质量设置提示信息 - switch (_networkQualityScore) { - case 1: - state.networkQualityMessage.value = '很差'; - break; - case 2: - state.networkQualityMessage.value = '较差'; - break; - case 3: - state.networkQualityMessage.value = '一般'; - break; - case 4: - state.networkQualityMessage.value = '良好'; - break; - case 5: - state.networkQualityMessage.value = '优秀'; - break; - default: - state.networkQualityMessage.value = ''; - } - // 根据网络质量设置提示信息 - if (_networkQualityScore < 4) { - showToast('网络质量'.tr + ':${state.networkQualityMessage.value}'); - } if (catEyeConfig.isNotEmpty && catEyeConfig.length > 0 && catEyeConfig[0].catEyeMode != 0) { if (network == null || network?.peerId == null || network?.peerId == '') { showToast('设备未配网'.tr); diff --git a/lib/main/lockDetail/lockSet/thirdPartyPlatform/third_party_platform_logic.dart b/lib/main/lockDetail/lockSet/thirdPartyPlatform/third_party_platform_logic.dart index 152e88c0..72f56be1 100644 --- a/lib/main/lockDetail/lockSet/thirdPartyPlatform/third_party_platform_logic.dart +++ b/lib/main/lockDetail/lockSet/thirdPartyPlatform/third_party_platform_logic.dart @@ -29,10 +29,10 @@ class ThirdPartyPlatformLogic extends BaseGetXController { super.onReady(); await getActivateInfo(); // 恢复之前保存的选中状态 - final savedIndex = await state.getSavedSelectedPlatformIndex(); - if (savedIndex != null && savedIndex < state.platFormSet.length) { - state.selectPlatFormIndex.value = savedIndex; - } + // final savedIndex = await state.getSavedSelectedPlatformIndex(); + // if (savedIndex != null && savedIndex < state.platFormSet.length) { + // state.selectPlatFormIndex.value = savedIndex; + // } _initReplySubscription(); await getServerDatetime(); showEasyLoading(); @@ -215,8 +215,8 @@ class ThirdPartyPlatformLogic extends BaseGetXController { if (state.selectPlatFormIndex.value == 1 || state.selectPlatFormIndex.value == 0) { if (state.registerKey.isNotEmpty) { // 持久化保存选项 - state.saveSelectedPlatformIndex(state.selectPlatFormIndex.value); - _requestAuthorizationCode(); + // state.saveSelectedPlatformIndex(state.selectPlatFormIndex.value); + // _requestAuthorizationCode(); } } else { showToast('目前只支持切换至涂鸦智能、锁通通协议'.tr); diff --git a/lib/main/lockDetail/lockSet/thirdPartyPlatform/third_party_platform_state.dart b/lib/main/lockDetail/lockSet/thirdPartyPlatform/third_party_platform_state.dart index da3269e0..13421d95 100644 --- a/lib/main/lockDetail/lockSet/thirdPartyPlatform/third_party_platform_state.dart +++ b/lib/main/lockDetail/lockSet/thirdPartyPlatform/third_party_platform_state.dart @@ -35,14 +35,14 @@ class ThirdPartyPlatformState { int serverTime = 0; // 服务器时间即UTC+0时间 // 存储选中的平台索引 - static const String _SELECTED_PLATFORM_INDEX_KEY = 'selected_platform_index'; - Future saveSelectedPlatformIndex(int index) async { - final prefs = await SharedPreferences.getInstance(); - await prefs.setInt(_SELECTED_PLATFORM_INDEX_KEY, index); - } - // 从本地存储读取选中的平台索引 - Future getSavedSelectedPlatformIndex() async { - final prefs = await SharedPreferences.getInstance(); - return prefs.getInt(_SELECTED_PLATFORM_INDEX_KEY); - } + // static const String _SELECTED_PLATFORM_INDEX_KEY = 'selected_platform_index'; + // Future saveSelectedPlatformIndex(int index) async { + // final prefs = await SharedPreferences.getInstance(); + // await prefs.setInt(_SELECTED_PLATFORM_INDEX_KEY, index); + // } + // // 从本地存储读取选中的平台索引 + // Future getSavedSelectedPlatformIndex() async { + // final prefs = await SharedPreferences.getInstance(); + // return prefs.getInt(_SELECTED_PLATFORM_INDEX_KEY); + // } }