对接路径规划的列表(根据场站的下的)

优化无人机机场的监控视频的显示视频流畅度提升80%
添加首页tcp指示灯的机器状态信息展示功能。(暂不支持在此页面上设备的切换显示)
This commit is contained in:
2026-06-09 14:39:55 +08:00
parent ff4a3836c7
commit 058a5d9588
26 changed files with 3634 additions and 1028 deletions

View File

@@ -0,0 +1,318 @@
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import '../../../../../core/consts/http_api_consts.dart';
import '../../domain/entities/flight_task_entity.dart';
class FlightTaskSelectorModal extends StatefulWidget {
final String currentGatewaySn;
final Function(List<FlightTaskEntity>) onTaskSelected;
const FlightTaskSelectorModal({
super.key,
required this.currentGatewaySn,
required this.onTaskSelected,
});
@override
State<FlightTaskSelectorModal> createState() => _FlightTaskSelectorModalState();
}
class _FlightTaskSelectorModalState extends State<FlightTaskSelectorModal> {
DateTimeRange? _selectedDateRange;
String? _selectedDeviceSn;
Map<String, List<FlightTaskEntity>?> _taskData = {};
bool _isLoading = false;
String? _errorMessage;
final Dio _dio = Dio();
@override
void initState() {
super.initState();
_selectedDeviceSn = widget.currentGatewaySn;
_setDefaultDateRange();
}
void _setDefaultDateRange() {
final now = DateTime.now();
final todayStart = DateTime(now.year, now.month, now.day);
final todayEnd = DateTime(now.year, now.month, now.day, 23, 59, 59);
_selectedDateRange = DateTimeRange(start: todayStart, end: todayEnd);
}
Future<void> _selectDateRange(BuildContext context) async {
final picked = await showDateRangePicker(
context: context,
firstDate: DateTime(2020),
lastDate: DateTime(2030),
initialDateRange: _selectedDateRange,
);
if (picked != null) {
setState(() {
_selectedDateRange = picked;
});
}
}
Future<void> _loadTasks() async {
if (_selectedDateRange == null || _selectedDeviceSn == null) {
setState(() {
_errorMessage = '请选择时间和设备';
});
return;
}
setState(() {
_isLoading = true;
_errorMessage = null;
});
try {
final beginAt = _selectedDateRange!.start.millisecondsSinceEpoch ~/ 1000;
final endAt = _selectedDateRange!.end.millisecondsSinceEpoch ~/ 1000;
final response = await _dio.post(
HttpApiConsts.getFlightTask,
data: {
'sns': [_selectedDeviceSn!],
'beginAt': beginAt,
'endAt': endAt,
},
);
if (response.statusCode != 200) {
throw Exception('网络请求失败');
}
final responseData = response.data;
if (responseData['code'] != 200) {
throw Exception(responseData['msg'] ?? '业务异常');
}
final data = responseData['data'] as Map<String, dynamic>;
final result = <String, List<FlightTaskEntity>?>{};
data.forEach((sn, value) {
if (value != null && value['list'] != null) {
final list = value['list'] as List<dynamic>;
result[sn] = list.map((item) => FlightTaskEntity.fromJson(item)).toList();
} else {
result[sn] = null;
}
});
setState(() {
_taskData = result;
_isLoading = false;
});
} catch (e) {
setState(() {
_isLoading = false;
_errorMessage = '加载失败: $e';
});
}
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'选择飞行任务',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 24),
_buildTimeSelector(),
const SizedBox(height: 12),
_buildDeviceSelector(),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _isLoading ? null : _loadTasks,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF165DFF),
minimumSize: const Size(double.infinity, 48),
),
child: _isLoading
? const CircularProgressIndicator(color: Colors.white)
: const Text('查询任务'),
),
if (_errorMessage != null) ...[
const SizedBox(height: 12),
Text(
_errorMessage!,
style: const TextStyle(color: Color(0xFFF53F3F)),
),
],
if (_taskData.isNotEmpty) ...[
const SizedBox(height: 16),
Flexible(
child: _buildTaskList(),
),
],
],
),
);
}
Widget _buildTimeSelector() {
return GestureDetector(
onTap: () => _selectDateRange(context),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFFF2F3F5),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
const Icon(Icons.calendar_today, color: Color(0xFF86909C)),
const SizedBox(width: 12),
Expanded(
child: Text(
_selectedDateRange != null
? '${_formatDate(_selectedDateRange!.start)} - ${_formatDate(_selectedDateRange!.end)}'
: '选择时间范围',
style: const TextStyle(fontSize: 14),
),
),
],
),
),
);
}
Widget _buildDeviceSelector() {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFFF2F3F5),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
const Icon(Icons.devices, color: Color(0xFF86909C)),
const SizedBox(width: 12),
Expanded(
child: Text(
_selectedDeviceSn ?? '未知设备',
style: const TextStyle(fontSize: 14),
),
),
],
),
);
}
Widget _buildTaskList() {
final tasks = _taskData[_selectedDeviceSn];
if (tasks == null || tasks.isEmpty) {
return const Center(
child: Padding(
padding: EdgeInsets.all(32),
child: Text('暂无任务数据'),
),
);
}
return ListView.builder(
shrinkWrap: true,
itemCount: tasks.length,
itemBuilder: (context, index) {
final task = tasks[index];
return _buildTaskItem(task);
},
);
}
Widget _buildTaskItem(FlightTaskEntity task) {
return GestureDetector(
onTap: () {
widget.onTaskSelected([task]);
},
child: Container(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE5E6EB)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
task.name,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 8),
Row(
children: [
Text(
'类型: ${task.taskType}',
style: const TextStyle(fontSize: 12, color: Color(0xFF86909C)),
),
const Spacer(),
Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: _getStatusColor(task.status).withOpacity(0.1),
borderRadius: BorderRadius.circular(4),
),
child: Text(
task.status,
style: TextStyle(
fontSize: 11,
color: _getStatusColor(task.status),
),
),
),
],
),
const SizedBox(height: 4),
Text(
'开始: ${_formatDateTime(task.beginAt)}',
style: const TextStyle(fontSize: 12, color: Color(0xFF86909C)),
),
Text(
'结束: ${_formatDateTime(task.endAt)}',
style: const TextStyle(fontSize: 12, color: Color(0xFF86909C)),
),
],
),
),
);
}
Color _getStatusColor(String status) {
switch (status.toLowerCase()) {
case 'success':
return const Color(0xFF00B42A);
case 'failed':
return const Color(0xFFF53F3F);
case 'running':
return const Color(0xFF165DFF);
default:
return const Color(0xFF86909C);
}
}
String _formatDate(DateTime date) {
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
}
String _formatDateTime(String dateTimeStr) {
try {
final dateTime = DateTime.parse(dateTimeStr);
return '${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}';
} catch (e) {
return dateTimeStr;
}
}
}