所有一级页面和不分二级页面
This commit is contained in:
4
lib/features/v2/device_list/data/data.dart
Normal file
4
lib/features/v2/device_list/data/data.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
// 数据层聚合导出
|
||||
export 'datasources/datasources.dart';
|
||||
export 'models/models.dart';
|
||||
export 'repositories/repositories.dart';
|
||||
@@ -0,0 +1,2 @@
|
||||
// 数据源层
|
||||
export 'device_remote_datasource.dart';
|
||||
@@ -0,0 +1,95 @@
|
||||
import '../../domain/entities/device_entity.dart';
|
||||
import '../../domain/entities/device_status_entity.dart';
|
||||
import '../models/device_data_model.dart';
|
||||
import '../models/device_status_data_model.dart';
|
||||
|
||||
/// 设备远程数据源抽象接口
|
||||
abstract class DeviceRemoteDataSource {
|
||||
Future<DeviceStatusDataModel> getDeviceStatus();
|
||||
Future<List<DeviceDataModel>> getDeviceList({String? typeFilter});
|
||||
}
|
||||
|
||||
/// 设备远程数据源实现类 - 模拟从 API 获取数据
|
||||
class DeviceRemoteDataSourceImpl implements DeviceRemoteDataSource {
|
||||
@override
|
||||
Future<DeviceStatusDataModel> getDeviceStatus() async {
|
||||
// 模拟网络延迟
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
// 模拟数据
|
||||
return const DeviceStatusDataModel(
|
||||
total: 136,
|
||||
online: 122,
|
||||
offline: 6,
|
||||
exception: 8,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DeviceDataModel>> getDeviceList({String? typeFilter}) async {
|
||||
// 模拟网络延迟
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
|
||||
// 模拟数据 - 根据设计图
|
||||
final allDevices = [
|
||||
const DeviceDataModel(
|
||||
deviceId: '10001',
|
||||
name: '逆变器 INV-001',
|
||||
type: '逆变器',
|
||||
status: '在线',
|
||||
power: 125.8,
|
||||
todayEnergy: 752.6,
|
||||
),
|
||||
const DeviceDataModel(
|
||||
deviceId: '10002',
|
||||
name: '逆变器 INV-002',
|
||||
type: '逆变器',
|
||||
status: '在线',
|
||||
power: 118.6,
|
||||
todayEnergy: 698.2,
|
||||
),
|
||||
const DeviceDataModel(
|
||||
deviceId: '10003',
|
||||
name: '汇流箱 SCB-001',
|
||||
type: '汇流箱',
|
||||
status: '在线',
|
||||
power: 0,
|
||||
todayEnergy: 0,
|
||||
current: 12.6,
|
||||
temperature: 36.2,
|
||||
),
|
||||
const DeviceDataModel(
|
||||
deviceId: '10004',
|
||||
name: '组件组串 STR-001',
|
||||
type: '组件',
|
||||
status: '在线',
|
||||
power: 85.3,
|
||||
todayEnergy: 0,
|
||||
radiation: 823,
|
||||
),
|
||||
const DeviceDataModel(
|
||||
deviceId: '10005',
|
||||
name: '监控 MON-001',
|
||||
type: '监控',
|
||||
status: '离线',
|
||||
power: 0,
|
||||
todayEnergy: 0,
|
||||
),
|
||||
const DeviceDataModel(
|
||||
deviceId: '10006',
|
||||
name: '逆变器 INV-003',
|
||||
type: '逆变器',
|
||||
status: '异常',
|
||||
power: 45.2,
|
||||
todayEnergy: 256.8,
|
||||
),
|
||||
];
|
||||
|
||||
// 根据类型过滤
|
||||
if (typeFilter != null && typeFilter != '全部') {
|
||||
return allDevices.where((device) => device.type == typeFilter).toList();
|
||||
}
|
||||
|
||||
return allDevices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import '../../domain/entities/device_entity.dart';
|
||||
|
||||
/// 设备数据模型
|
||||
class DeviceDataModel {
|
||||
final String deviceId;
|
||||
final String name;
|
||||
final String type;
|
||||
final String status;
|
||||
final double power;
|
||||
final double todayEnergy;
|
||||
final double? temperature;
|
||||
final double? current;
|
||||
final double? voltage;
|
||||
final double? radiation;
|
||||
|
||||
const DeviceDataModel({
|
||||
required this.deviceId,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.power,
|
||||
required this.todayEnergy,
|
||||
this.temperature,
|
||||
this.current,
|
||||
this.voltage,
|
||||
this.radiation,
|
||||
});
|
||||
|
||||
/// 从 JSON 创建数据模型
|
||||
factory DeviceDataModel.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceDataModel(
|
||||
deviceId: json['deviceId'] as String,
|
||||
name: json['name'] as String,
|
||||
type: json['type'] as String,
|
||||
status: json['status'] as String,
|
||||
power: (json['power'] as num).toDouble(),
|
||||
todayEnergy: (json['todayEnergy'] as num).toDouble(),
|
||||
temperature: json['temperature']?.toDouble(),
|
||||
current: json['current']?.toDouble(),
|
||||
voltage: json['voltage']?.toDouble(),
|
||||
radiation: json['radiation']?.toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
/// 转换为 JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'deviceId': deviceId,
|
||||
'name': name,
|
||||
'type': type,
|
||||
'status': status,
|
||||
'power': power,
|
||||
'todayEnergy': todayEnergy,
|
||||
'temperature': temperature,
|
||||
'current': current,
|
||||
'voltage': voltage,
|
||||
'radiation': radiation,
|
||||
};
|
||||
}
|
||||
|
||||
/// 转换为实体
|
||||
DeviceEntity toEntity() {
|
||||
return DeviceEntity(
|
||||
deviceId: deviceId,
|
||||
name: name,
|
||||
type: type,
|
||||
status: status,
|
||||
power: power,
|
||||
todayEnergy: todayEnergy,
|
||||
temperature: temperature,
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
radiation: radiation,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import '../../domain/entities/device_status_entity.dart';
|
||||
|
||||
/// 设备状态统计数据模型
|
||||
class DeviceStatusDataModel {
|
||||
final int total;
|
||||
final int online;
|
||||
final int offline;
|
||||
final int exception;
|
||||
|
||||
const DeviceStatusDataModel({
|
||||
required this.total,
|
||||
required this.online,
|
||||
required this.offline,
|
||||
required this.exception,
|
||||
});
|
||||
|
||||
/// 从 JSON 创建数据模型
|
||||
factory DeviceStatusDataModel.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceStatusDataModel(
|
||||
total: json['total'] as int,
|
||||
online: json['online'] as int,
|
||||
offline: json['offline'] as int,
|
||||
exception: json['exception'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
/// 转换为 JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'total': total,
|
||||
'online': online,
|
||||
'offline': offline,
|
||||
'exception': exception,
|
||||
};
|
||||
}
|
||||
|
||||
/// 转换为实体
|
||||
DeviceStatusEntity toEntity() {
|
||||
return DeviceStatusEntity(
|
||||
total: total,
|
||||
online: online,
|
||||
offline: offline,
|
||||
exception: exception,
|
||||
);
|
||||
}
|
||||
}
|
||||
3
lib/features/v2/device_list/data/models/models.dart
Normal file
3
lib/features/v2/device_list/data/models/models.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
// 数据模型层
|
||||
export 'device_data_model.dart';
|
||||
export 'device_status_data_model.dart';
|
||||
@@ -0,0 +1,23 @@
|
||||
import '../../domain/entities/device_entity.dart';
|
||||
import '../../domain/entities/device_status_entity.dart';
|
||||
import '../../domain/repositories/device_repository.dart';
|
||||
import '../datasources/device_remote_datasource.dart';
|
||||
|
||||
/// 设备仓储实现类
|
||||
class DeviceRepositoryImpl implements DeviceRepository {
|
||||
final DeviceRemoteDataSource remoteDataSource;
|
||||
|
||||
const DeviceRepositoryImpl({required this.remoteDataSource});
|
||||
|
||||
@override
|
||||
Future<DeviceStatusEntity> getDeviceStatus() async {
|
||||
final dataModel = await remoteDataSource.getDeviceStatus();
|
||||
return dataModel.toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DeviceEntity>> getDeviceList({String? typeFilter}) async {
|
||||
final dataModels = await remoteDataSource.getDeviceList(typeFilter: typeFilter);
|
||||
return dataModels.map((model) => model.toEntity()).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// 仓储实现
|
||||
export 'device_repository_impl.dart';
|
||||
Reference in New Issue
Block a user