修复一些字段不规范造成的歧义,和依赖注入问题
This commit is contained in:
@@ -25,6 +25,7 @@ import '../../features/devices/data/repositories/device_hostriry_work_impl.dart'
|
||||
import '../../features/devices/data/repositories/device_repository_impl.dart';
|
||||
import '../../features/devices/domain/repositories/device_hostrity_work_repository.dart';
|
||||
import '../../features/devices/domain/usecases/device_work_hostrirty_usecase.dart';
|
||||
import '../../features/devices/domain/usecases/get_device_location_usecase.dart';
|
||||
import '../../features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import '../app/app_user_cubit.dart';
|
||||
import '../network/dio_client.dart';
|
||||
@@ -102,7 +103,8 @@ Future<void> init() async {
|
||||
|
||||
/// 5. 状态管理 (Cubit/Bloc)
|
||||
sl.registerLazySingleton(() => AppUserCubit()); // AuthCubit 依赖它,必须先注册
|
||||
sl.registerLazySingleton(() => DevicesCubit(sl(), sl()));
|
||||
sl.registerLazySingleton(() => GetDeviceLocationUseCase(sl()));
|
||||
sl.registerLazySingleton(() => DevicesCubit(sl(), sl(), sl()));
|
||||
sl.registerFactory(() => RemoteControlCubit(sl()));
|
||||
|
||||
/// 6. 认证 (Auth)
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/data/datasources/device_http_datasource.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
|
||||
import '../../../domain/entities/device_location_entity.dart';
|
||||
|
||||
class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
final Dio dio;
|
||||
|
||||
@@ -80,13 +82,13 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<dynamic> getDeviceLocation(String username) async {
|
||||
Future<dynamic> getDeviceLocation(String deviceame) async {
|
||||
// TODO: implement getDeviceLocation
|
||||
try {
|
||||
// 发起 GET 请求
|
||||
final response = await dio.get(
|
||||
'https://serviceri.satabot.com/iot/device/userDevice',
|
||||
queryParameters: {'tenantName': username},
|
||||
queryParameters: {'tenantName': deviceame},
|
||||
// options: Options(
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
@@ -99,7 +101,14 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
if (data['code'] == 200) {
|
||||
return data['data']; // 返回设备数据
|
||||
//return data['data']; // 返回设备数据
|
||||
final locationData = data['data'];// 假设数据结构,测试时候如有不妥就修改结果的实例化
|
||||
return DeviceLocationEntity(
|
||||
deviceName: locationData['deviceName'],
|
||||
latitude: locationData['latitude'],
|
||||
longitude: locationData['longitude'],
|
||||
);
|
||||
|
||||
} else {
|
||||
throw Exception(data['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class GetDeviceLocationUseCase {
|
||||
|
||||
GetDeviceLocationUseCase(this.repository);
|
||||
//获取设备的位置
|
||||
Future<Either<DeviceFailure, DeviceLocationEntity>> call(String username) async {
|
||||
return await repository.getDeviceLocation(username);
|
||||
Future<Either<DeviceFailure, DeviceLocationEntity>> call(String Devicename) async {
|
||||
return await repository.getDeviceLocation(Devicename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user