一次大的提交

This commit is contained in:
2026-08-07 08:49:29 +08:00
parent bf2fc49c19
commit db70665ced
181 changed files with 23060 additions and 2804 deletions

View File

@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import '../cubit/report_cubit.dart';
import '../states/report_state.dart';
import '../constants/report_constants.dart';
@@ -14,7 +13,6 @@ import '../widgets/level_selector.dart';
import 'media_preview_page.dart';
import '../../di/report_di.dart';
/// 现场上报主页面
class ReportPage extends StatelessWidget {
const ReportPage({super.key});
@@ -38,14 +36,30 @@ class _ReportPageContent extends StatelessWidget {
backgroundColor: AppColors.cardBackground,
body: BlocConsumer<ReportCubit, ReportState>(
listener: (context, state) {
if (state is ReportSuccess) {
_showSuccessDialog(context);
} else if (state is ReportFailure) {
_showErrorDialog(context, state.message);
if (state is ReportFormState) {
if (state.successMessage != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.successMessage!),
backgroundColor: Colors.green,
duration: const Duration(seconds: 2),
),
);
context.read<ReportCubit>().clearMessages();
} else if (state.errorMessage != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.errorMessage!),
backgroundColor: Colors.red,
duration: const Duration(seconds: 2),
),
);
context.read<ReportCubit>().clearMessages();
}
}
},
builder: (context, state) {
if (state is ReportSubmitting) {
if (state is ReportSubmitting || state is ReportDevicesLoading) {
return const Center(
child: CircularProgressIndicator(color: AppColors.primary),
);
@@ -55,7 +69,7 @@ class _ReportPageContent extends StatelessWidget {
final cubit = context.read<ReportCubit>();
return Column(
children: [
_buildAppBar(context, state.location, cubit),
_buildAppBar(context, state, cubit),
Expanded(child: _buildFormContent(context, state)),
],
);
@@ -68,10 +82,9 @@ class _ReportPageContent extends StatelessWidget {
);
}
/// 构建导航栏
PreferredSizeWidget _buildAppBar(
BuildContext context,
String location,
ReportFormState state,
ReportCubit cubit,
) {
return PreferredSize(
@@ -86,13 +99,12 @@ class _ReportPageContent extends StatelessWidget {
),
child: Column(
children: [
// 第一行:标题 + 提交按钮
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppLocalizations.of(context).translate('report.title'),
style: const TextStyle(
const Text(
'现场上报',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: AppColors.textPrimary,
@@ -102,9 +114,9 @@ class _ReportPageContent extends StatelessWidget {
onTap: () {
context.read<ReportCubit>().submitReport();
},
child: Text(
AppLocalizations.of(context).translate('report.submit'),
style: const TextStyle(
child: const Text(
'提交',
style: TextStyle(
color: AppColors.primary,
fontSize: 18,
fontWeight: FontWeight.w600,
@@ -114,10 +126,9 @@ class _ReportPageContent extends StatelessWidget {
],
),
const SizedBox(height: 12),
// 第二行:位置信息(可点击)
GestureDetector(
onTap: () {
_showLocationPicker(context, cubit);
_showSitePicker(context, cubit, state);
},
child: Row(
children: [
@@ -129,7 +140,7 @@ class _ReportPageContent extends StatelessWidget {
const SizedBox(width: 6),
Flexible(
child: Text(
location,
state.location,
style: TextStyle(
fontSize: 14,
color: AppColors.textSecondary,
@@ -156,7 +167,6 @@ class _ReportPageContent extends StatelessWidget {
);
}
/// 构建表单内容
Widget _buildFormContent(BuildContext context, ReportFormState state) {
final cubit = context.read<ReportCubit>();
@@ -168,30 +178,23 @@ class _ReportPageContent extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 上报类型选择
ReportTypeSelector(
selectedType: state.selectedReportType,
onSelected: (type) => cubit.selectReportType(type),
),
const SizedBox(height: AppDimensions.moduleSpacing),
// 设备选择
DeviceSelector(
selectedDevice: state.selectedDevice,
onTap: () {
_showDevicePicker(context, cubit);
_showDevicePicker(context, cubit, state);
},
),
const SizedBox(height: AppDimensions.moduleSpacing),
// 问题描述
DescriptionInput(
description: state.report.description,
onChanged: (value) => cubit.updateDescription(value),
),
const SizedBox(height: AppDimensions.moduleSpacing),
// 媒体上传
MediaUploader(
mediaFiles: state.mediaFiles,
onCameraTap: () {
@@ -209,8 +212,6 @@ class _ReportPageContent extends StatelessWidget {
onRemove: (index) => cubit.removeMediaFile(index),
),
const SizedBox(height: AppDimensions.moduleSpacing),
// 问题等级选择
LevelSelector(
selectedLevel: state.selectedProblemLevel,
onSelected: (level) => cubit.selectProblemLevel(level),
@@ -221,40 +222,6 @@ class _ReportPageContent extends StatelessWidget {
);
}
/// 构建位置信息行
Widget _buildLocationRow(BuildContext context, String location) {
return Container(
margin: const EdgeInsets.symmetric(
horizontal: AppDimensions.horizontalPadding,
),
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
decoration: BoxDecoration(
color: AppColors.background,
borderRadius: BorderRadius.circular(AppDimensions.borderRadius),
boxShadow: [
BoxShadow(
color: const Color(0x0D000000),
blurRadius: AppDimensions.cardShadowBlur,
offset: const Offset(0, 2),
),
],
),
child: Row(
children: [
const Icon(Icons.location_on, color: AppColors.primary, size: 20),
const SizedBox(width: 8),
Expanded(
child: Text(
location,
style: TextStyle(fontSize: 16, color: AppColors.textPrimary),
),
),
],
),
);
}
/// 选择图片
Future<void> _pickImage(ReportCubit cubit) async {
final ImagePicker picker = ImagePicker();
try {
@@ -273,7 +240,6 @@ class _ReportPageContent extends StatelessWidget {
}
}
/// 选择视频
Future<void> _pickVideo(ReportCubit cubit) async {
final ImagePicker picker = ImagePicker();
try {
@@ -290,7 +256,6 @@ class _ReportPageContent extends StatelessWidget {
}
}
/// 预览媒体文件
void _previewMedia(BuildContext context, List<String> mediaFiles, int index) {
Navigator.push(
context,
@@ -301,11 +266,9 @@ class _ReportPageContent extends StatelessWidget {
);
}
/// 从相册选择
Future<void> _pickFromGallery(BuildContext context, ReportCubit cubit) async {
final ImagePicker picker = ImagePicker();
try {
// 显示选择图片或视频的选项
await showModalBottomSheet(
context: context,
builder: (context) => SafeArea(
@@ -314,9 +277,7 @@ class _ReportPageContent extends StatelessWidget {
children: [
ListTile(
leading: const Icon(Icons.image),
title: Text(
AppLocalizations.of(context).translate('report.select_image'),
),
title: const Text('选择图片'),
onTap: () async {
Navigator.pop(context);
final XFile? image = await picker.pickImage(
@@ -332,9 +293,7 @@ class _ReportPageContent extends StatelessWidget {
),
ListTile(
leading: const Icon(Icons.video_library),
title: Text(
AppLocalizations.of(context).translate('report.select_video'),
),
title: const Text('选择视频'),
onTap: () async {
Navigator.pop(context);
final XFile? video = await picker.pickVideo(
@@ -354,123 +313,246 @@ class _ReportPageContent extends StatelessWidget {
}
}
/// 显示位置选择器
void _showLocationPicker(BuildContext context, ReportCubit cubit) {
final loc = AppLocalizations.of(context);
final locations = [
loc.translate('report.main_building_a'),
loc.translate('report.main_building_b'),
loc.translate('report.boiler_room'),
loc.translate('report.turbine_room'),
loc.translate('report.control_room'),
loc.translate('report.power_distribution_room'),
];
void _showSitePicker(
BuildContext context,
ReportCubit cubit,
ReportFormState currentState,
) {
if (currentState.sites.isEmpty) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('暂无场站数据')));
return;
}
showDialog(
showModalBottomSheet(
context: context,
builder: (context) => AlertDialog(
title: Text(loc.translate('report.select_location')),
content: SingleChildScrollView(
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (context) {
return Container(
padding: const EdgeInsets.all(14),
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.6,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: locations.map((location) {
return ListTile(
title: Text(location),
onTap: () {
cubit.updateLocation(location);
Navigator.pop(context);
},
);
}).toList(),
children: [
const Text(
'选择场站',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const SizedBox(height: 14),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: currentState.sites.length,
itemBuilder: (context, index) {
final site = currentState.sites[index];
final isSelected = currentState.selectedSite?.id == site.id;
return ListTile(
title: Text(site.siteName),
subtitle:
site.siteCode != null && site.siteCode!.isNotEmpty
? Text('站点编码: ${site.siteCode}')
: null,
trailing: isSelected
? const Icon(Icons.check, color: Color(0xFF165DFF))
: null,
onTap: () {
cubit.selectSite(site);
Navigator.pop(context);
},
);
},
),
),
],
),
);
},
);
}
void _showDevicePicker(
BuildContext context,
ReportCubit cubit,
ReportFormState state,
) {
final selectedType = state.selectedReportType;
final selectedSite = state.selectedSite;
if (selectedSite == null) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('请先选择场站')));
return;
}
if (selectedType == null) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('请先选择上报类型')));
return;
}
bool isRobotType = selectedType == ReportType.mowerError;
bool isDroneType = selectedType == ReportType.uavError;
if (!isRobotType && !isDroneType) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('选择设备'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: const Text('设备一'),
onTap: () {
cubit.selectDevice('设备一', 'device_1');
Navigator.pop(context);
},
),
ListTile(
title: const Text('设备二'),
onTap: () {
cubit.selectDevice('设备二', 'device_2');
Navigator.pop(context);
},
),
ListTile(
title: const Text('设备三'),
onTap: () {
cubit.selectDevice('设备三', 'device_3');
Navigator.pop(context);
},
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(loc.translate('report.cancel')),
),
],
),
);
}
);
return;
}
/// 显示设备选择器
void _showDevicePicker(BuildContext context, ReportCubit cubit) {
final loc = AppLocalizations.of(context);
final devices = [
loc.translate('report.boiler_1'),
loc.translate('report.boiler_2'),
loc.translate('report.turbine_1'),
loc.translate('report.generator_1'),
loc.translate('report.transformer_1'),
loc.translate('report.water_pump_1'),
];
Future<void> loadAndShowDevices() async {
await cubit.loadDeviceList(selectedSite.id);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(loc.translate('report.select_device')),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: devices.map((device) {
return ListTile(
title: Text(device),
onTap: () {
cubit.selectDevice(device);
Navigator.pop(context);
},
);
}).toList(),
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(loc.translate('report.cancel')),
),
],
),
);
}
WidgetsBinding.instance.addPostFrameCallback((_) {
final newState = cubit.state;
if (newState is! ReportFormState) return;
/// 显示成功对话框
void _showSuccessDialog(BuildContext context) {
final loc = AppLocalizations.of(context);
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text(loc.translate('report.submit_success')),
content: Text(loc.translate('report.submit_success_message')),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
Navigator.pop(context); // 返回上一页
},
child: Text(loc.translate('report.confirm')),
),
],
),
);
}
List<Widget> deviceList = [];
/// 显示错误对话框
void _showErrorDialog(BuildContext context, String message) {
final loc = AppLocalizations.of(context);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(loc.translate('report.submit_failed')),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(loc.translate('report.confirm')),
if (isRobotType) {
if (newState.robots.isEmpty) {
deviceList = [
const Center(
child: Padding(
padding: EdgeInsets.all(32),
child: Text(
'暂无机器人数据',
style: TextStyle(fontSize: 14, color: Color(0xFF86909C)),
),
),
),
];
} else {
deviceList = newState.robots
.map(
(robot) => ListTile(
title: Text(robot.name),
subtitle: robot.alias != null && robot.alias!.isNotEmpty
? Text(robot.alias!)
: null,
trailing: Text(robot.status),
onTap: () {
cubit.selectDevice(robot.name, robot.id);
Navigator.pop(context);
},
),
)
.toList();
}
} else if (isDroneType) {
if (newState.drones.isEmpty) {
deviceList = [
const Center(
child: Padding(
padding: EdgeInsets.all(32),
child: Text(
'暂无无人机数据',
style: TextStyle(fontSize: 14, color: Color(0xFF86909C)),
),
),
),
];
} else {
deviceList = newState.drones
.map(
(drone) => ListTile(
title: Text(drone.callsign),
subtitle: Text(drone.deviceSn),
onTap: () {
cubit.selectDevice(drone.callsign, drone.deviceSn);
Navigator.pop(context);
},
),
)
.toList();
}
}
showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
],
),
);
builder: (context) {
return Container(
padding: const EdgeInsets.all(14),
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.6,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
isRobotType ? '选择机器人' : '选择无人机',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const SizedBox(height: 14),
Expanded(
child: ListView(shrinkWrap: true, children: deviceList),
),
],
),
);
},
);
});
}
loadAndShowDevices();
}
}