完成扫码绑定的cubit层

完成扫码依赖的下载和权限配置
完成扫码绑定设备-初步测试打印扫码结果
This commit is contained in:
2026-03-04 10:22:12 +08:00
parent cb09c21f1b
commit 1bbcd451da
10 changed files with 134 additions and 6 deletions

View File

@@ -30,7 +30,7 @@ class DeviceStatusBloc extends Bloc<DeviceStatusEvent, DeviceStatusState> {
// 🔥 新增:模拟测试数据(调试用)
_testMockData();
// _testMockData();
}
void _testMockData() {
// 用户提供的真实指令数据(字节数组)

View File

@@ -13,6 +13,7 @@ import 'package:maibu_satabot_v2/features/devices/domain/usecases/update_devicen
import '../../data/models/device_add_path_point_model.dart';
import '../../data/models/device_work_area_param_model.dart';
import '../../domain/usecases/bind_device_usecase.dart';
import '../../domain/usecases/delete_work_record_usecase.dart';
import '../../domain/usecases/get_device_location_usecase.dart';
import '../../domain/usecases/get_work_record_usecase.dart';
@@ -25,6 +26,7 @@ class DevicesCubit extends Cubit<DevicesState> {
final DeviceRepository repository;
final GetWorkRecordUseCase _getWorkRecordUseCase;
final DeleteWorkRecordUseCase _deleteWorkRecordUseCase;
final BindDeviceUseCase _bindDeviceUseCase;
final UnbindDeviceUseCase _unbindDeviceUseCase;
final UpdateDevicenameUsecase _updateDevicename;
final SelectWorkRecordUseCase _selectWorkRecordUseCase;
@@ -43,7 +45,7 @@ class DevicesCubit extends Cubit<DevicesState> {
this._selectWorkRecordUseCase,
this._saveWorkRecordUseCase,
this._generatePathUseCase,
this._routePlanningUseCase
this._routePlanningUseCase, this._bindDeviceUseCase
) : super(const DevicesState());
Future<void> unbindDevice(String deviceId, String deviceName) async {
@@ -176,6 +178,41 @@ class DevicesCubit extends Cubit<DevicesState> {
selectDevice(device);
}, (r) => emit(state.copyWith(isLoading: false, selectedDevice: device)));
}
/// 绑定设备
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 ?? '绑定设备失败',
)),
// 成功处理(返回 int 状态码)
(successCode) {
if (successCode == 1) {
emit(state.copyWith(isLoading: false, errorMessage: ''));
// 绑定成功后刷新设备列表
//fetchAllDevices(state.?.username ?? '');
} else {
emit(state.copyWith(
isLoading: false,
errorMessage: '绑定失败:状态码 $successCode',
));
}
},
);
} catch (e) {
emit(state.copyWith(
isLoading: false,
errorMessage: '绑定异常:${e.toString()}',
));
}
}
/// 获取设备位置
Future<void> getDeviceLocation(DeviceEntity device) async {