修改设备别名接口+UI
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/repositories/device_repository.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/get_user_device_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/unbind_device_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/update_devicename_usecase.dart';
|
||||
|
||||
import '../../domain/usecases/delete_work_record_usecase.dart';
|
||||
import '../../domain/usecases/get_device_location_usecase.dart';
|
||||
@@ -16,6 +17,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
final GetWorkRecordUseCase _getWorkRecordUseCase;
|
||||
final DeleteWorkRecordUseCase _deleteWorkRecordUseCase;
|
||||
final UnbindDeviceUseCase _unbindDeviceUseCase;
|
||||
final UpdateDevicenameUsecase _updateDevicename;
|
||||
|
||||
DevicesCubit(
|
||||
this.repository,
|
||||
@@ -24,10 +26,17 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
this._getWorkRecordUseCase,
|
||||
this._deleteWorkRecordUseCase,
|
||||
this._unbindDeviceUseCase,
|
||||
this._updateDevicename,
|
||||
) : super(const DevicesState());
|
||||
|
||||
Future<void> unbindDevice(String deviceId, String deviceName) async {
|
||||
emit(state.copyWith(isLoading: true, errorMessage: ''));
|
||||
emit(
|
||||
state.copyWith(
|
||||
isLoading: true,
|
||||
errorMessage: '',
|
||||
operationType: DeviceOperationType.unbind,
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final params = UnbindDeviceParams(deviceId, deviceName);
|
||||
@@ -38,6 +47,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: failure.message ?? '解绑设备失败',
|
||||
operationType: DeviceOperationType.none, // 操作结束重置
|
||||
),
|
||||
),
|
||||
(successCode) {
|
||||
@@ -56,6 +66,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
? null
|
||||
: state.selectedDevice,
|
||||
errorMessage: '',
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@@ -63,6 +74,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: '解绑失败:状态码 $successCode',
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -70,7 +82,68 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
);
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(isLoading: false, errorMessage: '解绑异常:${e.toString()}'),
|
||||
state.copyWith(isLoading: false, errorMessage: '解绑异常:${e.toString()}', operationType: DeviceOperationType.none),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateDeviceName(String deviceId, String deviceName) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
isLoading: true,
|
||||
errorMessage: '',
|
||||
operationType: DeviceOperationType.updateName,
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final params = UpdateDevicenameParams(deviceId, deviceName);
|
||||
final result = await _updateDevicename.call(params);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: failure.message ?? '更新设备名称失败',
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
),
|
||||
(successCode) {
|
||||
// 核心修复:int 转 bool 条件判断
|
||||
print('更新设备名称结果代码: $successCode'); // 调试输出结果代码
|
||||
final isSuccess = successCode == 1; // 显式转为 bool
|
||||
if (isSuccess) {
|
||||
//final updatedDevices = state.devices?.map((device) {
|
||||
// return device.deviceName == deviceId ? device.copyWith(deviceName: deviceName) : device;
|
||||
//}).toList();
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
//devices: updatedDevices,
|
||||
//selectedDevice: state.selectedDevice?.deviceName == deviceId ? state.selectedDevice?.copyWith(deviceName: deviceName) : state.selectedDevice,
|
||||
errorMessage: '',
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
emit(
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: '更新设备名称失败:状态码 $successCode',
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: '更新设备名称异常:${e.toString()}',
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user