完成解决合并扫码绑定代码问题

完成优化tcp的重连和认证
完成登录响应慢和热加载时候tcp不能统一对象的重连
This commit is contained in:
2026-03-05 10:00:18 +08:00
parent ac9ee670ec
commit e7ac4b00f3
5 changed files with 133 additions and 32 deletions

View File

@@ -180,16 +180,21 @@ class DevicesCubit extends Cubit<DevicesState> {
}
/// 绑定设备
Future<void> bindDevice(String deviceId, String deviceAlias) async {
emit(state.copyWith(isLoading: true, errorMessage: ''));
try {
final params = BindDeviceParams(deviceId, deviceAlias);
final result = await _bindDeviceUseCase.call(params);
result.fold(
// 失败处理
(failure) => emit(state.copyWith(
isLoading: false,
errorMessage: failure.message ?? '绑定设备失败',
)),
(failure) {
emit(state.copyWith(
isLoading: false,
errorMessage: failure.message ?? '绑定设备失败',
));
// 抛出异常,携带后端返回的错误消息(如“设备不存在”)
throw Exception(failure.message ?? '绑定设备失败');
},
// 成功处理(返回 int 状态码)
(successCode) {
if (successCode == 1) {
@@ -201,14 +206,17 @@ class DevicesCubit extends Cubit<DevicesState> {
isLoading: false,
errorMessage: '绑定失败:状态码 $successCode',
));
throw Exception('绑定失败:状态码 $successCode');
}
},
);
} catch (e) {
emit(state.copyWith(
isLoading: false,
errorMessage: '绑定异常:${e.toString()}',
));
// emit(state.copyWith(
// isLoading: false,
// errorMessage: '绑定异常:${e.toString()}',
// ));
// 🔥 重新抛出,传递给 UI
rethrow;
}
}