告警中心的二级详情页面+信息中心的页面+对接机器人接口
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_detail_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_detail_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 指标趋势图组件
|
||||
class MetricTrendChart extends StatelessWidget {
|
||||
final HistoryMetrics historyData;
|
||||
final MetricType selectedMetric;
|
||||
final Function(MetricType) onMetricChanged;
|
||||
|
||||
const MetricTrendChart({
|
||||
super.key,
|
||||
required this.historyData,
|
||||
required this.selectedMetric,
|
||||
required this.onMetricChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [AlarmDimensions.cardShadow],
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'指标趋势',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 指标切换标签
|
||||
_buildMetricTabs(),
|
||||
const SizedBox(height: 16),
|
||||
// 折线图
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: _buildChart(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMetricTabs() {
|
||||
return Row(
|
||||
children: MetricType.values.map((metric) {
|
||||
final isSelected = metric == selectedMetric;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => onMetricChanged(metric),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? const Color(0xFFE8F3FF) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
metric.label,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
color: isSelected ? AlarmColors.primary : AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildChart() {
|
||||
List<MetricDataPoint> dataPoints;
|
||||
double maxY;
|
||||
|
||||
switch (selectedMetric) {
|
||||
case MetricType.power:
|
||||
dataPoints = historyData.power;
|
||||
maxY = 1500;
|
||||
break;
|
||||
case MetricType.voltage:
|
||||
dataPoints = historyData.voltage;
|
||||
maxY = 800;
|
||||
break;
|
||||
case MetricType.frequency:
|
||||
dataPoints = historyData.frequency;
|
||||
maxY = 60;
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataPoints.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'暂无数据',
|
||||
style: TextStyle(color: AlarmColors.textTertiary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final spots = dataPoints
|
||||
.asMap()
|
||||
.entries
|
||||
.map((e) => FlSpot(e.key.toDouble(), e.value.value))
|
||||
.toList();
|
||||
|
||||
return LineChart(
|
||||
LineChartData(
|
||||
gridData: FlGridData(
|
||||
show: true,
|
||||
drawVerticalLine: true,
|
||||
horizontalInterval: maxY / 5,
|
||||
getDrawingHorizontalLine: (value) {
|
||||
return FlLine(
|
||||
color: const Color(0xFFE5E6EB).withOpacity(0.3),
|
||||
strokeWidth: 1,
|
||||
);
|
||||
},
|
||||
getDrawingVerticalLine: (value) {
|
||||
return FlLine(
|
||||
color: const Color(0xFFE5E6EB).withOpacity(0.3),
|
||||
strokeWidth: 1,
|
||||
);
|
||||
},
|
||||
),
|
||||
titlesData: FlTitlesData(
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 30,
|
||||
getTitlesWidget: (value, meta) {
|
||||
final index = value.toInt();
|
||||
if (index >= 0 && index < dataPoints.length) {
|
||||
// 只显示部分标签避免拥挤
|
||||
if (index == 0 || index == dataPoints.length ~/ 2 || index == dataPoints.length - 1) {
|
||||
return Text(
|
||||
dataPoints[index].time,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: AlarmColors.textTertiary,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
leftTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 40,
|
||||
interval: maxY / 5,
|
||||
getTitlesWidget: (value, meta) {
|
||||
return Text(
|
||||
value.toInt().toString(),
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: AlarmColors.textTertiary,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
rightTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
topTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
minX: 0,
|
||||
maxX: (dataPoints.length - 1).toDouble(),
|
||||
minY: 0,
|
||||
maxY: maxY,
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
spots: spots,
|
||||
isCurved: true,
|
||||
color: AlarmColors.primary,
|
||||
barWidth: 2,
|
||||
dotData: FlDotData(
|
||||
show: true,
|
||||
getDotPainter: (spot, percent, barData, index) {
|
||||
return FlDotCirclePainter(
|
||||
radius: 3,
|
||||
color: AlarmColors.danger,
|
||||
strokeWidth: 1,
|
||||
strokeColor: Colors.white,
|
||||
);
|
||||
},
|
||||
),
|
||||
belowBarData: BarAreaData(
|
||||
show: true,
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AlarmColors.primary.withOpacity(0.2),
|
||||
AlarmColors.primary.withOpacity(0.0),
|
||||
],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user