一次大的提交

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

@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
/// 全局颜色常量
class AppColors {
@@ -27,26 +27,32 @@ class AppDimensions {
/// 上报类型枚举
enum ReportType {
deviceFault('report.device_fault', Icons.notifications_active),
patrolRecord('report.patrol_record', Icons.description),
hiddenDanger('report.hidden_danger', Icons.shield),
defectReport('report.defect_report', Icons.build);
mowerError('MOWER_ERROR', '割草机故障', Icons.notifications_active),
uavError('UAV_ERROR', '无人机故障', Icons.flight),
inspectionTask('INSPECTION_TASK', '巡检', Icons.search),
componentDefect('COMPONENT_DEFECT', '光伏组件故障', Icons.power),
cleanTask('CLEAN_TASK', '清洗任务', Icons.cleaning_services),
maintainTask('MAINTAIN_TASK', '维护任务', Icons.handyman),
repairTask('REPAIR_TASK', '维修任务', Icons.build),
other('OTHER', '其他', Icons.more_horiz);
final String labelKey;
final String orderType;
final String label;
final IconData icon;
const ReportType(this.labelKey, this.icon);
const ReportType(this.orderType, this.label, this.icon);
}
/// 问题等级枚举
enum ProblemLevel {
normal('report.normal', Color(0xFF86909C), Color(0xFFE5E6EB)),
important('report.important', Color(0xFFFF7D00), Color(0xFFE5E6EB)),
urgent('report.urgent', Color(0xFFF53F3F), Color(0xFFF53F3F));
info('INFO', '信息', Color(0xFF165DFF), Color(0xFF165DFF)),
warning('WARNING', '警告', Color(0xFFFF7D00), Color(0xFFFF7D00)),
error('ERROR', '错误', Color(0xFFF53F3F), Color(0xFFF53F3F));
final String labelKey;
final String level;
final String label;
final Color textColor;
final Color borderColor;
const ProblemLevel(this.labelKey, this.textColor, this.borderColor);
const ProblemLevel(this.level, this.label, this.textColor, this.borderColor);
}

View File

@@ -1,43 +1,174 @@
import 'package:dio/dio.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../domain/entities/report_entity.dart';
import '../../domain/usecases/submit_report_usecase.dart';
import '../constants/report_constants.dart';
import '../states/report_state.dart';
import '../../../home/domain/entities/site_entity.dart';
import '../../../home/domain/usecases/get_site_list_usecase.dart';
import '../../../home/domain/repositories/site_repository.dart';
import '../../../home/data/repositories/site_repository_impl.dart';
import '../../../home/data/datasources/site_datasource_impl.dart';
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
import '../../../device_list/data/models/robot_data_model.dart';
import '../../../device_list/domain/entities/drone_station_entity.dart';
/// 上报页面 Cubit
class ReportCubit extends Cubit<ReportState> {
final SubmitReportUseCase submitReportUseCase;
final Dio dio;
final AppUserCubit appUserCubit;
final UserStorage userStorage;
ReportCubit({required this.submitReportUseCase})
: super(ReportFormState(report: ReportEntity()));
ReportCubit({
required this.submitReportUseCase,
required this.dio,
required this.appUserCubit,
required this.userStorage,
}) : super(ReportFormState(report: ReportEntity())) {
_loadSiteList();
}
Future<void> _loadSiteList() async {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
emit(currentState.copyWith(sites: []));
try {
final siteDataSource = SiteDataSourceImpl(
dio,
userStorage,
appUserCubit,
);
final siteRepository = SiteRepositoryImpl(siteDataSource);
final getSiteListUseCase = GetSiteListUseCase(siteRepository);
final user = appUserCubit.state.user;
if (user == null) {
emit(currentState.copyWith(sites: []));
return;
}
final result = await getSiteListUseCase(user.userId);
result.fold(
(failure) {
emit(currentState.copyWith(sites: []));
},
(sites) {
SiteEntity? selectedSite;
if (sites.isNotEmpty) {
selectedSite = sites.first;
}
emit(
currentState.copyWith(
sites: sites,
selectedSite: selectedSite,
location: selectedSite?.siteName ?? '请选择场站',
report: currentState.report.copyWith(
siteId: selectedSite?.id,
siteName: selectedSite?.siteName,
),
),
);
},
);
} catch (e) {
emit(currentState.copyWith(sites: []));
}
}
}
Future<void> loadDeviceList(int siteId) async {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
emit(ReportDevicesLoading());
try {
final robotResponse = await dio.get(
HttpApiConsts.getRobotList,
queryParameters: {'siteId': siteId, 'pageSize': 9999, 'pageNum': 1},
);
final droneResponse = await dio.get(
HttpApiConsts.getSiteUAVList,
queryParameters: {'siteId': siteId},
);
List<RobotDataModel> robots = [];
List<DroneStationEntity> drones = [];
if (robotResponse.statusCode == 200 &&
robotResponse.data['code'] == 200) {
final List<dynamic> rows = robotResponse.data['rows'] ?? [];
robots = rows.map((item) => RobotDataModel.fromJson(item)).toList();
}
if (droneResponse.statusCode == 200 &&
droneResponse.data['code'] == 200) {
final List<dynamic> rows = droneResponse.data['rows'] ?? [];
drones = rows
.map((item) => DroneStationEntity.fromJson(item))
.toList();
}
emit(currentState.copyWith(robots: robots, drones: drones));
} catch (e) {
emit(currentState.copyWith(robots: [], drones: []));
}
}
}
/// 选择上报类型
void selectReportType(ReportType type) {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
emit(
currentState.copyWith(
selectedReportType: type,
report: currentState.report.copyWith(reportType: type.labelKey),
report: currentState.report.copyWith(reportType: type.orderType),
selectedDevice: null,
selectedDeviceId: null,
),
);
}
}
/// 选择设备
void selectDevice(String device) {
void selectSite(SiteEntity site) {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
emit(
currentState.copyWith(
selectedDevice: device,
report: currentState.report.copyWith(deviceId: device),
selectedSite: site,
location: site.siteName,
report: currentState.report.copyWith(
siteId: site.id,
siteName: site.siteName,
),
selectedDevice: null,
selectedDeviceId: null,
robots: [],
drones: [],
),
);
}
}
void selectDevice(String deviceName, String deviceId) {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
emit(
currentState.copyWith(
selectedDevice: deviceName,
selectedDeviceId: deviceId,
report: currentState.report.copyWith(
deviceId: deviceId,
deviceName: deviceName,
),
),
);
}
}
/// 更新位置
void updateLocation(String location) {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
@@ -50,7 +181,6 @@ class ReportCubit extends Cubit<ReportState> {
}
}
/// 更新问题描述
void updateDescription(String description) {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
@@ -62,20 +192,18 @@ class ReportCubit extends Cubit<ReportState> {
}
}
/// 选择问题等级
void selectProblemLevel(ProblemLevel level) {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
emit(
currentState.copyWith(
selectedProblemLevel: level,
report: currentState.report.copyWith(problemLevel: level.labelKey),
report: currentState.report.copyWith(problemLevel: level.level),
),
);
}
}
/// 添加媒体文件
void addMediaFile(String filePath) {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
@@ -90,7 +218,6 @@ class ReportCubit extends Cubit<ReportState> {
}
}
/// 删除媒体文件
void removeMediaFile(int index) {
if (state is ReportFormState) {
final currentState = state as ReportFormState;
@@ -105,43 +232,68 @@ class ReportCubit extends Cubit<ReportState> {
}
}
/// 提交上报
Future<void> submitReport() async {
if (state is! ReportFormState) return;
final currentState = state as ReportFormState;
// 验证必填项
if (currentState.selectedSite == null) {
emit(currentState.copyWith(errorMessage: '请选择场站'));
return;
}
if (currentState.selectedReportType == null) {
emit(currentState.copyWith(errorMessage: '请选择上报类型'));
return;
}
if (currentState.selectedDevice == null ||
currentState.selectedDevice!.isEmpty) {
emit(const ReportFailure('请选择设备'));
emit(currentState.copyWith(errorMessage: '请选择设备'));
return;
}
if (currentState.report.description == null ||
currentState.report.description!.isEmpty) {
emit(const ReportFailure('请填写问题描述'));
emit(currentState.copyWith(errorMessage: '请填写问题描述'));
return;
}
if (currentState.selectedProblemLevel == null) {
emit(const ReportFailure('请选择问题等级'));
emit(currentState.copyWith(errorMessage: '请选择问题等级'));
return;
}
// 开始提交
emit(ReportSubmitting());
final result = await submitReportUseCase.execute(currentState.report);
result.fold(
(failure) => emit(ReportFailure(failure.message)),
(success) => emit(ReportSuccess()),
(failure) => emit(currentState.copyWith(errorMessage: failure.message)),
(success) {
// 提交成功:清空表单,保留场站列表
emit(currentState.copyWith(
report: ReportEntity(),
selectedReportType: null,
selectedProblemLevel: null,
selectedDevice: null,
selectedDeviceId: null,
mediaFiles: [],
successMessage: '提交成功',
));
},
);
}
/// 重置表单
void clearMessages() {
if (state is ReportFormState) {
final s = state as ReportFormState;
emit(s.copyWith(errorMessage: null, successMessage: null));
}
}
void resetForm() {
emit(ReportFormState(report: ReportEntity()));
_loadSiteList();
}
}

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();
}
}

View File

@@ -1,6 +1,9 @@
import 'package:equatable/equatable.dart';
import '../../domain/entities/report_entity.dart';
import '../constants/report_constants.dart';
import '../../../home/domain/entities/site_entity.dart';
import '../../../device_list/data/models/robot_data_model.dart';
import '../../../device_list/domain/entities/drone_station_entity.dart';
/// 上报页面状态抽象类
abstract class ReportState extends Equatable {
@@ -32,6 +35,11 @@ class ReportFailure extends ReportState {
List<Object?> get props => [message];
}
/// 设备列表加载状态
class ReportDevicesLoading extends ReportState {
const ReportDevicesLoading();
}
/// 表单数据状态
class ReportFormState extends ReportState {
final ReportEntity report;
@@ -39,7 +47,14 @@ class ReportFormState extends ReportState {
final ProblemLevel? selectedProblemLevel;
final String location;
final String? selectedDevice;
final String? selectedDeviceId;
final List<String> mediaFiles;
final List<SiteEntity> sites;
final SiteEntity? selectedSite;
final List<RobotDataModel> robots;
final List<DroneStationEntity> drones;
final String? errorMessage;
final String? successMessage;
const ReportFormState({
required this.report,
@@ -47,7 +62,14 @@ class ReportFormState extends ReportState {
this.selectedProblemLevel,
this.location = '江苏省苏州市吴中区',
this.selectedDevice,
this.selectedDeviceId,
this.mediaFiles = const [],
this.sites = const [],
this.selectedSite,
this.robots = const [],
this.drones = const [],
this.errorMessage,
this.successMessage,
});
ReportFormState copyWith({
@@ -56,7 +78,14 @@ class ReportFormState extends ReportState {
ProblemLevel? selectedProblemLevel,
String? location,
String? selectedDevice,
String? selectedDeviceId,
List<String>? mediaFiles,
List<SiteEntity>? sites,
SiteEntity? selectedSite,
List<RobotDataModel>? robots,
List<DroneStationEntity>? drones,
String? errorMessage,
String? successMessage,
}) {
return ReportFormState(
report: report ?? this.report,
@@ -64,7 +93,14 @@ class ReportFormState extends ReportState {
selectedProblemLevel: selectedProblemLevel ?? this.selectedProblemLevel,
location: location ?? this.location,
selectedDevice: selectedDevice ?? this.selectedDevice,
selectedDeviceId: selectedDeviceId ?? this.selectedDeviceId,
mediaFiles: mediaFiles ?? this.mediaFiles,
sites: sites ?? this.sites,
selectedSite: selectedSite ?? this.selectedSite,
robots: robots ?? this.robots,
drones: drones ?? this.drones,
errorMessage: errorMessage,
successMessage: successMessage,
);
}
@@ -75,6 +111,13 @@ class ReportFormState extends ReportState {
selectedProblemLevel,
location,
selectedDevice,
selectedDeviceId,
mediaFiles,
sites,
selectedSite,
robots,
drones,
errorMessage,
successMessage,
];
}

View File

@@ -40,27 +40,35 @@ class DeviceSelector extends StatelessWidget {
color: AppColors.textPrimary,
),
),
Row(
children: [
Text(
selectedDevice ??
AppLocalizations.of(
context,
).translate('report.please_select_device'),
style: TextStyle(
fontSize: 14,
color: selectedDevice != null
? AppColors.textPrimary
: AppColors.textHint,
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Flexible(
child: Text(
selectedDevice ??
AppLocalizations.of(
context,
).translate('report.please_select_device'),
style: TextStyle(
fontSize: 12,
color: selectedDevice != null
? AppColors.textPrimary
: AppColors.textHint,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.right,
),
),
),
const SizedBox(width: 4),
Icon(
Icons.arrow_drop_down,
size: 20,
color: AppColors.textHint,
),
],
const SizedBox(width: 4),
Icon(
Icons.arrow_drop_down,
size: 20,
color: AppColors.textHint,
),
],
),
),
],
),

View File

@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import '../constants/report_constants.dart';
/// 问题等级选择器
class LevelSelector extends StatelessWidget {
final ProblemLevel? selectedLevel;
final Function(ProblemLevel) onSelected;
@@ -15,7 +13,6 @@ class LevelSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context);
return Container(
margin: const EdgeInsets.symmetric(
horizontal: AppDimensions.horizontalPadding,
@@ -35,9 +32,9 @@ class LevelSelector extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
loc.translate('report.problem_level'),
style: const TextStyle(
const Text(
'问题等级',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.textPrimary,
@@ -54,8 +51,8 @@ class LevelSelector extends StatelessWidget {
margin: const EdgeInsets.symmetric(horizontal: 4),
height: AppDimensions.buttonHeight,
decoration: BoxDecoration(
color: isSelected && level == ProblemLevel.urgent
? AppColors.danger.withOpacity(0.1)
color: isSelected
? level.textColor.withOpacity(0.1)
: AppColors.background,
borderRadius: BorderRadius.circular(
AppDimensions.borderRadiusSmall,
@@ -69,7 +66,7 @@ class LevelSelector extends StatelessWidget {
),
child: Center(
child: Text(
loc.translate(level.labelKey),
level.label,
style: TextStyle(
fontSize: 14,
color: isSelected

View File

@@ -53,127 +53,131 @@ class MediaUploader extends StatelessWidget {
),
),
const SizedBox(height: 12),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
// 拍照按钮
_buildUploadButton(
icon: Icons.camera_alt,
label: loc.translate('report.take_photo'),
onTap: onCameraTap,
),
const SizedBox(width: 8),
// 录像按钮
_buildUploadButton(
icon: Icons.videocam,
label: loc.translate('report.record_video'),
onTap: onVideoTap,
),
const SizedBox(width: 8),
// 已上传的媒体预览
...mediaFiles.asMap().entries.map((entry) {
final String filePath = entry.value;
final bool isNetworkImage = filePath.startsWith('http');
final bool isVideo = _isVideoFile(filePath);
SizedBox(
width: double.infinity,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
physics: const ClampingScrollPhysics(),
child: Row(
children: [
// 拍照按钮
_buildUploadButton(
icon: Icons.camera_alt,
label: loc.translate('report.take_photo'),
onTap: onCameraTap,
),
const SizedBox(width: 8),
// 录像按钮
_buildUploadButton(
icon: Icons.videocam,
label: loc.translate('report.record_video'),
onTap: onVideoTap,
),
const SizedBox(width: 8),
// 已上传的媒体预览
...mediaFiles.asMap().entries.map((entry) {
final String filePath = entry.value;
final bool isNetworkImage = filePath.startsWith('http');
final bool isVideo = _isVideoFile(filePath);
return GestureDetector(
onTap: () => onTap?.call(entry.key),
child: Stack(
children: [
Container(
width: 80,
height: 80,
margin: const EdgeInsets.only(right: 8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
AppDimensions.borderRadiusSmall,
),
color: AppColors.cardBackground,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(
AppDimensions.borderRadiusSmall,
),
child: isVideo
? _buildVideoThumbnail(filePath)
: (isNetworkImage
? Image.network(
filePath,
fit: BoxFit.cover,
errorBuilder:
(context, error, stackTrace) {
return _buildPlaceholderIcon(
Icons.broken_image,
);
},
)
: Image.file(
File(filePath),
fit: BoxFit.cover,
errorBuilder:
(context, error, stackTrace) {
return _buildPlaceholderIcon(
Icons.broken_image,
);
},
)),
),
),
Positioned(
top: 4,
right: 12,
child: GestureDetector(
onTap: () => onRemove(entry.key),
child: Container(
width: 20,
height: 20,
decoration: const BoxDecoration(
color: Colors.black54,
shape: BoxShape.circle,
return GestureDetector(
onTap: () => onTap?.call(entry.key),
child: Stack(
children: [
Container(
width: 80,
height: 80,
margin: const EdgeInsets.only(right: 8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
AppDimensions.borderRadiusSmall,
),
child: const Icon(
Icons.close,
size: 14,
color: Colors.white,
color: AppColors.cardBackground,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(
AppDimensions.borderRadiusSmall,
),
child: isVideo
? _buildVideoThumbnail(filePath)
: (isNetworkImage
? Image.network(
filePath,
fit: BoxFit.cover,
errorBuilder:
(context, error, stackTrace) {
return _buildPlaceholderIcon(
Icons.broken_image,
);
},
)
: Image.file(
File(filePath),
fit: BoxFit.cover,
errorBuilder:
(context, error, stackTrace) {
return _buildPlaceholderIcon(
Icons.broken_image,
);
},
)),
),
),
),
// 视频播放图标
if (isVideo)
Positioned(
child: Container(
width: 80,
height: 80,
margin: const EdgeInsets.only(right: 8),
alignment: Alignment.center,
top: 4,
right: 12,
child: GestureDetector(
onTap: () => onRemove(entry.key),
child: Container(
padding: const EdgeInsets.all(8),
width: 20,
height: 20,
decoration: const BoxDecoration(
color: Colors.black38,
color: Colors.black54,
shape: BoxShape.circle,
),
child: const Icon(
Icons.play_arrow,
Icons.close,
size: 14,
color: Colors.white,
size: 24,
),
),
),
),
],
),
);
}).toList(),
// 添加按钮
_buildUploadButton(
icon: Icons.add,
label: '',
onTap: onAddFromGallery,
isAddButton: true,
),
],
// 视频播放图标
if (isVideo)
Positioned(
child: Container(
width: 80,
height: 80,
margin: const EdgeInsets.only(right: 8),
alignment: Alignment.center,
child: Container(
padding: const EdgeInsets.all(8),
decoration: const BoxDecoration(
color: Colors.black38,
shape: BoxShape.circle,
),
child: const Icon(
Icons.play_arrow,
color: Colors.white,
size: 24,
),
),
),
),
],
),
);
}).toList(),
// 添加按钮
_buildUploadButton(
icon: Icons.add,
label: '',
onTap: onAddFromGallery,
isAddButton: true,
),
],
),
),
),
],

View File

@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import '../constants/report_constants.dart';
/// 上报类型选择器
class ReportTypeSelector extends StatelessWidget {
final ReportType? selectedType;
final Function(ReportType) onSelected;
@@ -19,22 +17,24 @@ class ReportTypeSelector extends StatelessWidget {
padding: const EdgeInsets.symmetric(
horizontal: AppDimensions.horizontalPadding,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: ReportType.values.map((type) {
final isSelected = selectedType == type;
return Flexible(
flex: 1,
child: GestureDetector(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
physics: const ClampingScrollPhysics(),
child: Row(
children: ReportType.values.map((type) {
final isSelected = selectedType == type;
return GestureDetector(
onTap: () => onSelected(type),
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 3),
margin: const EdgeInsets.symmetric(horizontal: 6),
padding: const EdgeInsets.symmetric(
horizontal: 8,
horizontal: 16,
vertical: 14,
),
decoration: BoxDecoration(
color: AppColors.background,
color: isSelected
? AppColors.primary.withOpacity(0.1)
: AppColors.background,
borderRadius: BorderRadius.circular(
AppDimensions.borderRadiusSmall,
),
@@ -60,13 +60,13 @@ class ReportTypeSelector extends StatelessWidget {
color: isSelected
? AppColors.primary
: AppColors.textHint,
size: 26,
size: 24,
),
const SizedBox(height: 6),
Text(
AppLocalizations.of(context).translate(type.labelKey),
type.label,
style: TextStyle(
fontSize: 11,
fontSize: 12,
height: 1.2,
color: isSelected
? AppColors.primary
@@ -82,9 +82,9 @@ class ReportTypeSelector extends StatelessWidget {
],
),
),
),
);
}).toList(),
);
}).toList(),
),
),
);
}