所有一级页面和不分二级页面
This commit is contained in:
@@ -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';
|
||||
Reference in New Issue
Block a user