所有一级页面和不分二级页面
This commit is contained in:
212
lib/features/v2/report/README.md
Normal file
212
lib/features/v2/report/README.md
Normal file
@@ -0,0 +1,212 @@
|
||||
# 现场上报模块使用说明
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 在路由中注册页面
|
||||
|
||||
```dart
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/report/report.dart';
|
||||
|
||||
// 在路由配置中添加
|
||||
GoRoute(
|
||||
path: '/report',
|
||||
builder: (context, state) => BlocProvider(
|
||||
create: (context) => ReportDependencyInjector.createReportCubit(),
|
||||
child: const ReportPage(),
|
||||
),
|
||||
),
|
||||
```
|
||||
|
||||
### 2. 跳转到上报页面
|
||||
|
||||
```dart
|
||||
context.push('/report');
|
||||
```
|
||||
|
||||
## 架构说明
|
||||
|
||||
### 清洁架构分层
|
||||
|
||||
```
|
||||
lib/features/v2/report/
|
||||
├── domain/ # 领域层(核心业务逻辑)
|
||||
│ ├── entities/ # 实体类
|
||||
│ │ └── report_entity.dart
|
||||
│ ├── repositories/ # 仓储接口
|
||||
│ │ └── report_repository.dart
|
||||
│ └── usecases/ # 用例
|
||||
│ └── submit_report_usecase.dart
|
||||
├── data/ # 数据层(数据获取与存储)
|
||||
│ ├── datasources/ # 数据源
|
||||
│ │ ├── report_remote_datasource.dart
|
||||
│ │ └── report_remote_datasource_impl.dart
|
||||
│ ├── models/ # 数据模型
|
||||
│ │ └── report_model.dart
|
||||
│ └── repositories/ # 仓储实现
|
||||
│ └── report_repository_impl.dart
|
||||
├── presentation/ # 表现层(UI + 状态管理)
|
||||
│ ├── constants/ # 常量
|
||||
│ │ └── report_constants.dart
|
||||
│ ├── cubit/ # 状态管理
|
||||
│ │ └── report_cubit.dart
|
||||
│ ├── states/ # 状态定义
|
||||
│ │ └── report_state.dart
|
||||
│ ├── pages/ # 页面
|
||||
│ │ └── report_page.dart
|
||||
│ ── widgets/ # 组件
|
||||
│ ├── report_type_selector.dart
|
||||
│ ├── device_selector.dart
|
||||
│ ├── description_input.dart
|
||||
│ ├── media_uploader.dart
|
||||
│ └── level_selector.dart
|
||||
├── di/ # 依赖注入
|
||||
│ └── report_di.dart
|
||||
└── report.dart # 统一导出
|
||||
```
|
||||
|
||||
## 核心功能
|
||||
|
||||
### 1. 上报类型选择
|
||||
- 设备故障
|
||||
- 巡检记录
|
||||
- 隐患上报
|
||||
- 缺陷上报
|
||||
|
||||
### 2. 设备选择
|
||||
- 点击选择设备(需实现设备选择页面)
|
||||
|
||||
### 3. 问题描述
|
||||
- 多行文本输入
|
||||
- 最大 200 字符限制
|
||||
- 实时字符计数
|
||||
|
||||
### 4. 媒体上传
|
||||
- 拍照上传
|
||||
- 录像上传
|
||||
- 图片预览
|
||||
- 删除已上传图片
|
||||
|
||||
### 5. 问题等级
|
||||
- 一般(灰色)
|
||||
- 重要(橙色)
|
||||
- 紧急(红色)
|
||||
|
||||
## 表单验证
|
||||
|
||||
提交时自动验证以下必填项:
|
||||
1. 设备选择
|
||||
2. 问题描述
|
||||
3. 问题等级
|
||||
|
||||
## 状态管理
|
||||
|
||||
### 状态类型
|
||||
- `ReportInitial`: 初始状态
|
||||
- `ReportFormState`: 表单数据状态
|
||||
- `ReportSubmitting`: 提交中状态
|
||||
- `ReportSuccess`: 提交成功状态
|
||||
- `ReportFailure`: 提交失败状态
|
||||
|
||||
### Cubit 方法
|
||||
- `selectReportType(ReportType)`: 选择上报类型
|
||||
- `selectDevice(String)`: 选择设备
|
||||
- `updateDescription(String)`: 更新问题描述
|
||||
- `selectProblemLevel(ProblemLevel)`: 选择问题等级
|
||||
- `addMediaFile(String)`: 添加媒体文件
|
||||
- `removeMediaFile(int)`: 删除媒体文件
|
||||
- `submitReport()`: 提交上报
|
||||
- `resetForm()`: 重置表单
|
||||
|
||||
## 自定义扩展
|
||||
|
||||
### 1. 对接真实 API
|
||||
|
||||
修改 `ReportRemoteDataSourceImpl`:
|
||||
|
||||
```dart
|
||||
class ReportRemoteDataSourceImpl implements ReportRemoteDataSource {
|
||||
final Dio dio; // 注入 Dio 实例
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> submitReport(ReportModel report) async {
|
||||
try {
|
||||
final response = await dio.post(
|
||||
'/api/report/submit',
|
||||
data: report.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return right(true);
|
||||
} else {
|
||||
return left(ServerFailure('提交失败'));
|
||||
}
|
||||
} catch (e) {
|
||||
return left(NetworkFailure('网络错误: $e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 实现设备选择
|
||||
|
||||
在 `ReportPage` 中修改 `_showDevicePicker` 方法:
|
||||
|
||||
```dart
|
||||
void _showDevicePicker(BuildContext context) {
|
||||
// 跳转到设备选择页面
|
||||
context.push('/device-select').then((device) {
|
||||
if (device != null) {
|
||||
context.read<ReportCubit>().selectDevice(device);
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 实现真实的相机/相册功能
|
||||
|
||||
添加依赖:
|
||||
```yaml
|
||||
dependencies:
|
||||
image_picker: ^1.1.2
|
||||
```
|
||||
|
||||
修改 `MediaUploader`:
|
||||
|
||||
```dart
|
||||
final ImagePicker picker = ImagePicker();
|
||||
|
||||
Future<void> _pickImage() async {
|
||||
final XFile? image = await picker.pickImage(source: ImageSource.camera);
|
||||
if (image != null) {
|
||||
cubit.addMediaFile(image.path);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 依赖说明
|
||||
|
||||
### 项目已有依赖
|
||||
- flutter_bloc: ^9.1.1
|
||||
- equatable: ^2.0.8
|
||||
- fpdart: ^1.2.0
|
||||
|
||||
### 可选依赖(按需添加)
|
||||
- image_picker: ^1.1.2 (图片/视频选择)
|
||||
- dio: ^5.9.0 (HTTP 请求,项目已有)
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 所有颜色、尺寸常量已抽取到 `report_constants.dart`
|
||||
2. 遵循清洁架构原则,内层不依赖外层
|
||||
3. 使用 fpdart 进行错误处理(Either 类型)
|
||||
4. 所有 UI 组件已适配 iOS 安全区
|
||||
5. 模拟数据已实现,可直接运行测试
|
||||
|
||||
## 后续开发建议
|
||||
|
||||
1. 实现真实的设备选择页面
|
||||
2. 对接后端 API
|
||||
3. 添加图片压缩功能
|
||||
4. 实现离线缓存
|
||||
5. 添加草稿保存功能
|
||||
84
lib/features/v2/report/USAGE_EXAMPLE.md
Normal file
84
lib/features/v2/report/USAGE_EXAMPLE.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# 现场上报模块 - 使用示例
|
||||
|
||||
## 1. 在路由中注册
|
||||
|
||||
在你的路由配置文件(如 `lib/core/router/app_router.dart`)中添加:
|
||||
|
||||
```dart
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/report/report.dart';
|
||||
|
||||
// 在 routes 列表中添加
|
||||
GoRoute(
|
||||
path: '/report',
|
||||
builder: (context, state) => BlocProvider(
|
||||
create: (context) => ReportDependencyInjector.createReportCubit(),
|
||||
child: const ReportPage(),
|
||||
),
|
||||
),
|
||||
```
|
||||
|
||||
## 2. 跳转到上报页面
|
||||
|
||||
在任何页面中,使用以下方式跳转:
|
||||
|
||||
```dart
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
// 跳转到上报页面
|
||||
context.push('/report');
|
||||
```
|
||||
|
||||
## 3. 完整示例
|
||||
|
||||
```dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class SomePage extends StatelessWidget {
|
||||
const SomePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('示例页面')),
|
||||
body: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
// 跳转到现场上报页面
|
||||
context.push('/report');
|
||||
},
|
||||
child: const Text('现场上报'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 4. 依赖说明
|
||||
|
||||
### 必需依赖(项目已包含)
|
||||
- flutter_bloc: ^9.1.1
|
||||
- equatable: ^2.0.8
|
||||
- fpdart: ^1.2.0
|
||||
- go_router: ^17.0.1
|
||||
|
||||
### 可选依赖(按需添加)
|
||||
如果需要实现真实的图片/视频上传功能,需要添加:
|
||||
```yaml
|
||||
dependencies:
|
||||
image_picker: ^1.1.2
|
||||
```
|
||||
|
||||
## 5. 注意事项
|
||||
|
||||
1. 确保在跳转前已经配置好路由
|
||||
2. BlocProvider 必须在 ReportPage 的父级
|
||||
3. 当前使用模拟数据,可直接运行测试
|
||||
4. 所有常量已抽取,便于主题定制
|
||||
|
||||
## 6. 后续开发
|
||||
|
||||
对接真实 API 时,修改 `lib/features/v2/report/data/datasources/report_remote_datasource_impl.dart` 文件即可。
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../models/report_model.dart';
|
||||
|
||||
/// 上报远程数据源接口
|
||||
abstract class ReportRemoteDataSource {
|
||||
/// 提交上报数据
|
||||
Future<Either<Failure, bool>> submitReport(ReportModel report);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../models/report_model.dart';
|
||||
import 'report_remote_datasource.dart';
|
||||
|
||||
/// 上报远程数据源实现(模拟接口请求)
|
||||
class ReportRemoteDataSourceImpl implements ReportRemoteDataSource {
|
||||
@override
|
||||
Future<Either<Failure, bool>> submitReport(ReportModel report) async {
|
||||
// 模拟网络请求延迟
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
// 模拟成功返回
|
||||
return right(true);
|
||||
|
||||
// 模拟失败情况(取消注释以测试错误处理)
|
||||
// return left(ServerFailure('提交失败,请重试'));
|
||||
}
|
||||
}
|
||||
68
lib/features/v2/report/data/models/report_model.dart
Normal file
68
lib/features/v2/report/data/models/report_model.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import '../../domain/entities/report_entity.dart';
|
||||
|
||||
/// 上报数据模型
|
||||
class ReportModel {
|
||||
final String? location;
|
||||
final String? reportType;
|
||||
final String? deviceId;
|
||||
final String? description;
|
||||
final List<String>? mediaUrls;
|
||||
final String? problemLevel;
|
||||
|
||||
ReportModel({
|
||||
this.location,
|
||||
this.reportType,
|
||||
this.deviceId,
|
||||
this.description,
|
||||
this.mediaUrls,
|
||||
this.problemLevel,
|
||||
});
|
||||
|
||||
/// 从 JSON 创建
|
||||
factory ReportModel.fromJson(Map<String, dynamic> json) {
|
||||
return ReportModel(
|
||||
location: json['location'] as String?,
|
||||
reportType: json['reportType'] as String?,
|
||||
deviceId: json['deviceId'] as String?,
|
||||
description: json['description'] as String?,
|
||||
mediaUrls: (json['mediaUrls'] as List<dynamic>?)?.cast<String>(),
|
||||
problemLevel: json['problemLevel'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
/// 转换为 JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'location': location,
|
||||
'reportType': reportType,
|
||||
'deviceId': deviceId,
|
||||
'description': description,
|
||||
'mediaUrls': mediaUrls,
|
||||
'problemLevel': problemLevel,
|
||||
};
|
||||
}
|
||||
|
||||
/// 转换为实体
|
||||
ReportEntity toEntity() {
|
||||
return ReportEntity(
|
||||
location: location,
|
||||
reportType: reportType,
|
||||
deviceId: deviceId,
|
||||
description: description,
|
||||
mediaUrls: mediaUrls,
|
||||
problemLevel: problemLevel,
|
||||
);
|
||||
}
|
||||
|
||||
/// 从实体创建
|
||||
factory ReportModel.fromEntity(ReportEntity entity) {
|
||||
return ReportModel(
|
||||
location: entity.location,
|
||||
reportType: entity.reportType,
|
||||
deviceId: entity.deviceId,
|
||||
description: entity.description,
|
||||
mediaUrls: entity.mediaUrls,
|
||||
problemLevel: entity.problemLevel,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../../domain/entities/report_entity.dart';
|
||||
import '../../domain/repositories/report_repository.dart';
|
||||
import '../datasources/report_remote_datasource.dart';
|
||||
import '../models/report_model.dart';
|
||||
|
||||
/// 上报仓储实现
|
||||
class ReportRepositoryImpl implements ReportRepository {
|
||||
final ReportRemoteDataSource remoteDataSource;
|
||||
|
||||
ReportRepositoryImpl({required this.remoteDataSource});
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> submitReport(ReportEntity report) async {
|
||||
// 将实体转换为模型
|
||||
final reportModel = ReportModel.fromEntity(report);
|
||||
|
||||
// 调用远程数据源
|
||||
return await remoteDataSource.submitReport(reportModel);
|
||||
}
|
||||
}
|
||||
26
lib/features/v2/report/di/report_di.dart
Normal file
26
lib/features/v2/report/di/report_di.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import '../data/datasources/report_remote_datasource.dart';
|
||||
import '../data/datasources/report_remote_datasource_impl.dart';
|
||||
import '../data/repositories/report_repository_impl.dart';
|
||||
import '../domain/repositories/report_repository.dart';
|
||||
import '../domain/usecases/submit_report_usecase.dart';
|
||||
import '../presentation/cubit/report_cubit.dart';
|
||||
|
||||
/// 上报模块依赖注入
|
||||
class ReportDependencyInjector {
|
||||
/// 创建 ReportCubit 实例
|
||||
static ReportCubit createReportCubit() {
|
||||
// 创建数据源
|
||||
final ReportRemoteDataSource remoteDataSource = ReportRemoteDataSourceImpl();
|
||||
|
||||
// 创建仓储
|
||||
final ReportRepository repository = ReportRepositoryImpl(
|
||||
remoteDataSource: remoteDataSource,
|
||||
);
|
||||
|
||||
// 创建用例
|
||||
final SubmitReportUseCase submitReportUseCase = SubmitReportUseCase(repository);
|
||||
|
||||
// 创建 Cubit
|
||||
return ReportCubit(submitReportUseCase: submitReportUseCase);
|
||||
}
|
||||
}
|
||||
36
lib/features/v2/report/domain/entities/report_entity.dart
Normal file
36
lib/features/v2/report/domain/entities/report_entity.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
/// 上报内容实体类
|
||||
class ReportEntity {
|
||||
final String? location;
|
||||
final String? reportType;
|
||||
final String? deviceId;
|
||||
final String? description;
|
||||
final List<String>? mediaUrls;
|
||||
final String? problemLevel;
|
||||
|
||||
const ReportEntity({
|
||||
this.location,
|
||||
this.reportType,
|
||||
this.deviceId,
|
||||
this.description,
|
||||
this.mediaUrls,
|
||||
this.problemLevel,
|
||||
});
|
||||
|
||||
ReportEntity copyWith({
|
||||
String? location,
|
||||
String? reportType,
|
||||
String? deviceId,
|
||||
String? description,
|
||||
List<String>? mediaUrls,
|
||||
String? problemLevel,
|
||||
}) {
|
||||
return ReportEntity(
|
||||
location: location ?? this.location,
|
||||
reportType: reportType ?? this.reportType,
|
||||
deviceId: deviceId ?? this.deviceId,
|
||||
description: description ?? this.description,
|
||||
mediaUrls: mediaUrls ?? this.mediaUrls,
|
||||
problemLevel: problemLevel ?? this.problemLevel,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../entities/report_entity.dart';
|
||||
|
||||
/// 上报仓储接口
|
||||
abstract class ReportRepository {
|
||||
/// 提交上报数据
|
||||
Future<Either<Failure, bool>> submitReport(ReportEntity report);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../entities/report_entity.dart';
|
||||
import '../repositories/report_repository.dart';
|
||||
|
||||
/// 提交上报用例
|
||||
class SubmitReportUseCase {
|
||||
final ReportRepository repository;
|
||||
|
||||
SubmitReportUseCase(this.repository);
|
||||
|
||||
Future<Either<Failure, bool>> execute(ReportEntity report) async {
|
||||
// 业务逻辑验证
|
||||
if (report.deviceId == null || report.deviceId!.isEmpty) {
|
||||
return left(Failure('请选择设备'));
|
||||
}
|
||||
if (report.description == null || report.description!.isEmpty) {
|
||||
return left(Failure('请填写问题描述'));
|
||||
}
|
||||
if (report.problemLevel == null || report.problemLevel!.isEmpty) {
|
||||
return left(Failure('请选择问题等级'));
|
||||
}
|
||||
|
||||
return await repository.submitReport(report);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 全局颜色常量
|
||||
class AppColors {
|
||||
static const Color primary = Color(0xFF165DFF);
|
||||
static const Color danger = Color(0xFFF53F3F);
|
||||
static const Color warning = Color(0xFFFF7D00);
|
||||
static const Color textPrimary = Color(0xFF1D2129);
|
||||
static const Color textSecondary = Color(0xFF4E5969);
|
||||
static const Color textHint = Color(0xFF86909C);
|
||||
static const Color background = Color(0xFFFFFFFF);
|
||||
static const Color cardBackground = Color(0xFFF8F9FA);
|
||||
static const Color borderColor = Color(0xFFE5E6EB);
|
||||
}
|
||||
|
||||
/// 全局尺寸常量
|
||||
class AppDimensions {
|
||||
static const double borderRadius = 16.0;
|
||||
static const double borderRadiusSmall = 8.0;
|
||||
static const double borderRadiusMedium = 12.0;
|
||||
static const double horizontalPadding = 16.0;
|
||||
static const double moduleSpacing = 20.0;
|
||||
static const double cardShadowBlur = 4.0;
|
||||
static const double buttonHeight = 48.0;
|
||||
static const double appBarHeight = 44.0;
|
||||
}
|
||||
|
||||
/// 上报类型枚举
|
||||
enum ReportType {
|
||||
deviceFault('设备故障', Icons.notifications_active),
|
||||
patrolRecord('巡检记录', Icons.description),
|
||||
hiddenDanger('隐患上报', Icons.shield),
|
||||
defectReport('缺陷上报', Icons.build);
|
||||
|
||||
final String label;
|
||||
final IconData icon;
|
||||
|
||||
const ReportType(this.label, this.icon);
|
||||
}
|
||||
|
||||
/// 问题等级枚举
|
||||
enum ProblemLevel {
|
||||
normal('一般', Color(0xFF86909C), Color(0xFFE5E6EB)),
|
||||
important('重要', Color(0xFFFF7D00), Color(0xFFE5E6EB)),
|
||||
urgent('紧急', Color(0xFFF53F3F), Color(0xFFF53F3F));
|
||||
|
||||
final String label;
|
||||
final Color textColor;
|
||||
final Color borderColor;
|
||||
|
||||
const ProblemLevel(this.label, this.textColor, this.borderColor);
|
||||
}
|
||||
137
lib/features/v2/report/presentation/cubit/report_cubit.dart
Normal file
137
lib/features/v2/report/presentation/cubit/report_cubit.dart
Normal file
@@ -0,0 +1,137 @@
|
||||
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';
|
||||
|
||||
/// 上报页面 Cubit
|
||||
class ReportCubit extends Cubit<ReportState> {
|
||||
final SubmitReportUseCase submitReportUseCase;
|
||||
|
||||
ReportCubit({required this.submitReportUseCase})
|
||||
: super(ReportFormState(report: ReportEntity()));
|
||||
|
||||
/// 选择上报类型
|
||||
void selectReportType(ReportType type) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
selectedReportType: type,
|
||||
report: currentState.report.copyWith(
|
||||
reportType: type.label,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 选择设备
|
||||
void selectDevice(String device) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
selectedDevice: device,
|
||||
report: currentState.report.copyWith(deviceId: device),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新位置
|
||||
void updateLocation(String location) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
location: location,
|
||||
report: currentState.report.copyWith(location: location),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新问题描述
|
||||
void updateDescription(String description) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
report: currentState.report.copyWith(description: description),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 选择问题等级
|
||||
void selectProblemLevel(ProblemLevel level) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
selectedProblemLevel: level,
|
||||
report: currentState.report.copyWith(
|
||||
problemLevel: level.label,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 添加媒体文件
|
||||
void addMediaFile(String filePath) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
final updatedFiles = List<String>.from(currentState.mediaFiles)
|
||||
..add(filePath);
|
||||
emit(currentState.copyWith(
|
||||
mediaFiles: updatedFiles,
|
||||
report: currentState.report.copyWith(mediaUrls: updatedFiles),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 删除媒体文件
|
||||
void removeMediaFile(int index) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
final updatedFiles = List<String>.from(currentState.mediaFiles)
|
||||
..removeAt(index);
|
||||
emit(currentState.copyWith(
|
||||
mediaFiles: updatedFiles,
|
||||
report: currentState.report.copyWith(mediaUrls: updatedFiles),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 提交上报
|
||||
Future<void> submitReport() async {
|
||||
if (state is! ReportFormState) return;
|
||||
|
||||
final currentState = state as ReportFormState;
|
||||
|
||||
// 验证必填项
|
||||
if (currentState.selectedDevice == null ||
|
||||
currentState.selectedDevice!.isEmpty) {
|
||||
emit(const ReportFailure('请选择设备'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentState.report.description == null ||
|
||||
currentState.report.description!.isEmpty) {
|
||||
emit(const ReportFailure('请填写问题描述'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentState.selectedProblemLevel == null) {
|
||||
emit(const ReportFailure('请选择问题等级'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 开始提交
|
||||
emit(ReportSubmitting());
|
||||
|
||||
final result = await submitReportUseCase.execute(currentState.report);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ReportFailure(failure.message)),
|
||||
(success) => emit(ReportSuccess()),
|
||||
);
|
||||
}
|
||||
|
||||
/// 重置表单
|
||||
void resetForm() {
|
||||
emit(ReportFormState(report: ReportEntity()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
/// 媒体预览页面
|
||||
class MediaPreviewPage extends StatefulWidget {
|
||||
final List<String> mediaFiles;
|
||||
final int initialIndex;
|
||||
|
||||
const MediaPreviewPage({
|
||||
super.key,
|
||||
required this.mediaFiles,
|
||||
required this.initialIndex,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MediaPreviewPage> createState() => _MediaPreviewPageState();
|
||||
}
|
||||
|
||||
class _MediaPreviewPageState extends State<MediaPreviewPage> {
|
||||
late PageController _pageController;
|
||||
VideoPlayerController? _videoController;
|
||||
int _currentIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_currentIndex = widget.initialIndex;
|
||||
_pageController = PageController(initialPage: widget.initialIndex);
|
||||
_initializeVideo(widget.mediaFiles[_currentIndex]);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController.dispose();
|
||||
_videoController?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// 初始化视频播放器
|
||||
Future<void> _initializeVideo(String filePath) async {
|
||||
// 先释放之前的控制器
|
||||
await _videoController?.dispose();
|
||||
_videoController = null;
|
||||
|
||||
if (_isVideoFile(filePath)) {
|
||||
_videoController = VideoPlayerController.file(File(filePath));
|
||||
try {
|
||||
await _videoController!.initialize();
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
debugPrint('视频初始化失败: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 判断是否为视频文件
|
||||
bool _isVideoFile(String filePath) {
|
||||
final lowerPath = filePath.toLowerCase();
|
||||
return lowerPath.endsWith('.mp4') ||
|
||||
lowerPath.endsWith('.mov') ||
|
||||
lowerPath.endsWith('.avi') ||
|
||||
lowerPath.endsWith('.mkv') ||
|
||||
lowerPath.endsWith('.wmv') ||
|
||||
lowerPath.endsWith('.flv');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
title: Text(
|
||||
'${_currentIndex + 1}/${widget.mediaFiles.length}',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: PageView.builder(
|
||||
controller: _pageController,
|
||||
itemCount: widget.mediaFiles.length,
|
||||
onPageChanged: (index) {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
_initializeVideo(widget.mediaFiles[index]);
|
||||
},
|
||||
itemBuilder: (context, index) {
|
||||
final filePath = widget.mediaFiles[index];
|
||||
if (_isVideoFile(filePath)) {
|
||||
return _buildVideoPreview();
|
||||
} else {
|
||||
return _buildImagePreview(filePath);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建图片预览
|
||||
Widget _buildImagePreview(String filePath) {
|
||||
final bool isNetworkImage = filePath.startsWith('http');
|
||||
|
||||
return Center(
|
||||
child: InteractiveViewer(
|
||||
child: isNetworkImage
|
||||
? Image.network(
|
||||
filePath,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(
|
||||
Icons.broken_image,
|
||||
color: Colors.white,
|
||||
size: 64,
|
||||
);
|
||||
},
|
||||
)
|
||||
: Image.file(
|
||||
File(filePath),
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(
|
||||
Icons.broken_image,
|
||||
color: Colors.white,
|
||||
size: 64,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建视频预览
|
||||
Widget _buildVideoPreview() {
|
||||
if (_videoController == null || !_videoController!.value.isInitialized) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: Colors.white),
|
||||
);
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: AspectRatio(
|
||||
aspectRatio: _videoController!.value.aspectRatio,
|
||||
child: VideoPlayer(_videoController!),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
476
lib/features/v2/report/presentation/pages/report_page.dart
Normal file
476
lib/features/v2/report/presentation/pages/report_page.dart
Normal file
@@ -0,0 +1,476 @@
|
||||
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 '../cubit/report_cubit.dart';
|
||||
import '../states/report_state.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
import '../widgets/report_type_selector.dart';
|
||||
import '../widgets/device_selector.dart';
|
||||
import '../widgets/description_input.dart';
|
||||
import '../widgets/media_uploader.dart';
|
||||
import '../widgets/level_selector.dart';
|
||||
import 'media_preview_page.dart';
|
||||
import '../../di/report_di.dart';
|
||||
|
||||
/// 现场上报主页面
|
||||
class ReportPage extends StatelessWidget {
|
||||
const ReportPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => ReportDependencyInjector.createReportCubit(),
|
||||
child: _ReportPageContent(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ReportPageContent extends StatelessWidget {
|
||||
const _ReportPageContent();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: SystemUiOverlayStyle.dark,
|
||||
child: Scaffold(
|
||||
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);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is ReportSubmitting) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppColors.primary,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is ReportFormState) {
|
||||
final cubit = context.read<ReportCubit>();
|
||||
return Column(
|
||||
children: [
|
||||
_buildAppBar(context, state.location, cubit),
|
||||
Expanded(
|
||||
child: _buildFormContent(context, state),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建导航栏
|
||||
PreferredSizeWidget _buildAppBar(BuildContext context, String location, ReportCubit cubit) {
|
||||
return PreferredSize(
|
||||
preferredSize: const Size.fromHeight(100),
|
||||
child: Container(
|
||||
color: AppColors.background,
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// 第一行:标题 + 提交按钮
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'现场上报',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<ReportCubit>().submitReport();
|
||||
},
|
||||
child: const Text(
|
||||
'提交',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 第二行:位置信息(可点击)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_showLocationPicker(context, cubit);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.location_on,
|
||||
color: AppColors.primary,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
child: Text(
|
||||
location,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.arrow_drop_down,
|
||||
size: 20,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建表单内容
|
||||
Widget _buildFormContent(BuildContext context, ReportFormState state) {
|
||||
final cubit = context.read<ReportCubit>();
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(
|
||||
top: AppDimensions.moduleSpacing,
|
||||
bottom: 40,
|
||||
),
|
||||
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);
|
||||
},
|
||||
),
|
||||
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: () {
|
||||
_pickImage(cubit);
|
||||
},
|
||||
onVideoTap: () {
|
||||
_pickVideo(cubit);
|
||||
},
|
||||
onAddFromGallery: () {
|
||||
_pickFromGallery(context, cubit);
|
||||
},
|
||||
onTap: (index) {
|
||||
_previewMedia(context, state.mediaFiles, index);
|
||||
},
|
||||
onRemove: (index) => cubit.removeMediaFile(index),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
|
||||
// 问题等级选择
|
||||
LevelSelector(
|
||||
selectedLevel: state.selectedProblemLevel,
|
||||
onSelected: (level) => cubit.selectProblemLevel(level),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建位置信息行
|
||||
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 {
|
||||
final XFile? image = await picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
maxWidth: 1920,
|
||||
maxHeight: 1080,
|
||||
imageQuality: 85,
|
||||
);
|
||||
|
||||
if (image != null) {
|
||||
cubit.addMediaFile(image.path);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('拍照失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 选择视频
|
||||
Future<void> _pickVideo(ReportCubit cubit) async {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
try {
|
||||
final XFile? video = await picker.pickVideo(
|
||||
source: ImageSource.camera,
|
||||
maxDuration: const Duration(minutes: 5),
|
||||
);
|
||||
|
||||
if (video != null) {
|
||||
cubit.addMediaFile(video.path);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('录像失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 预览媒体文件
|
||||
void _previewMedia(BuildContext context, List<String> mediaFiles, int index) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MediaPreviewPage(
|
||||
mediaFiles: mediaFiles,
|
||||
initialIndex: index,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 从相册选择
|
||||
Future<void> _pickFromGallery(BuildContext context, ReportCubit cubit) async {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
try {
|
||||
// 显示选择图片或视频的选项
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.image),
|
||||
title: const Text('选择图片'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context);
|
||||
final XFile? image = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxWidth: 1920,
|
||||
maxHeight: 1080,
|
||||
imageQuality: 85,
|
||||
);
|
||||
if (image != null) {
|
||||
cubit.addMediaFile(image.path);
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.video_library),
|
||||
title: const Text('选择视频'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context);
|
||||
final XFile? video = await picker.pickVideo(
|
||||
source: ImageSource.gallery,
|
||||
);
|
||||
if (video != null) {
|
||||
cubit.addMediaFile(video.path);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('从相册选择失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 显示位置选择器
|
||||
void _showLocationPicker(BuildContext context, ReportCubit cubit) {
|
||||
final locations = [
|
||||
'主厂房A区',
|
||||
'主厂房B区',
|
||||
'锅炉房',
|
||||
'汽机房',
|
||||
'控制室',
|
||||
'配电室',
|
||||
];
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('选择位置'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: locations.map((location) {
|
||||
return ListTile(
|
||||
title: Text(location),
|
||||
onTap: () {
|
||||
cubit.updateLocation(location);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示设备选择器
|
||||
void _showDevicePicker(BuildContext context, ReportCubit cubit) {
|
||||
final devices = [
|
||||
'锅炉1号',
|
||||
'锅炉2号',
|
||||
'汽轮机1号',
|
||||
'发电机1号',
|
||||
'变压器1号',
|
||||
'水泵1号',
|
||||
];
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('选择设备'),
|
||||
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: const Text('取消'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示成功对话框
|
||||
void _showSuccessDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('提交成功'),
|
||||
content: const Text('您的上报已成功提交'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context); // 返回上一页
|
||||
},
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示错误对话框
|
||||
void _showErrorDialog(BuildContext context, String message) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('提交失败'),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
80
lib/features/v2/report/presentation/states/report_state.dart
Normal file
80
lib/features/v2/report/presentation/states/report_state.dart
Normal file
@@ -0,0 +1,80 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../domain/entities/report_entity.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 上报页面状态抽象类
|
||||
abstract class ReportState extends Equatable {
|
||||
const ReportState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// 初始状态
|
||||
class ReportInitial extends ReportState {}
|
||||
|
||||
/// 加载中状态
|
||||
class ReportLoading extends ReportState {}
|
||||
|
||||
/// 提交中状态
|
||||
class ReportSubmitting extends ReportState {}
|
||||
|
||||
/// 提交成功状态
|
||||
class ReportSuccess extends ReportState {}
|
||||
|
||||
/// 提交失败状态
|
||||
class ReportFailure extends ReportState {
|
||||
final String message;
|
||||
|
||||
const ReportFailure(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
/// 表单数据状态
|
||||
class ReportFormState extends ReportState {
|
||||
final ReportEntity report;
|
||||
final ReportType? selectedReportType;
|
||||
final ProblemLevel? selectedProblemLevel;
|
||||
final String location;
|
||||
final String? selectedDevice;
|
||||
final List<String> mediaFiles;
|
||||
|
||||
const ReportFormState({
|
||||
required this.report,
|
||||
this.selectedReportType,
|
||||
this.selectedProblemLevel,
|
||||
this.location = '江苏省苏州市吴中区',
|
||||
this.selectedDevice,
|
||||
this.mediaFiles = const [],
|
||||
});
|
||||
|
||||
ReportFormState copyWith({
|
||||
ReportEntity? report,
|
||||
ReportType? selectedReportType,
|
||||
ProblemLevel? selectedProblemLevel,
|
||||
String? location,
|
||||
String? selectedDevice,
|
||||
List<String>? mediaFiles,
|
||||
}) {
|
||||
return ReportFormState(
|
||||
report: report ?? this.report,
|
||||
selectedReportType: selectedReportType ?? this.selectedReportType,
|
||||
selectedProblemLevel: selectedProblemLevel ?? this.selectedProblemLevel,
|
||||
location: location ?? this.location,
|
||||
selectedDevice: selectedDevice ?? this.selectedDevice,
|
||||
mediaFiles: mediaFiles ?? this.mediaFiles,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
report,
|
||||
selectedReportType,
|
||||
selectedProblemLevel,
|
||||
location,
|
||||
selectedDevice,
|
||||
mediaFiles,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 问题描述输入模块
|
||||
class DescriptionInput extends StatelessWidget {
|
||||
final String? description;
|
||||
final Function(String) onChanged;
|
||||
|
||||
const DescriptionInput({
|
||||
super.key,
|
||||
this.description,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(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: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'问题描述',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
maxLines: 5,
|
||||
maxLength: 200,
|
||||
onChanged: onChanged,
|
||||
decoration: InputDecoration(
|
||||
hintText: '请详细描述问题现象...',
|
||||
hintStyle: TextStyle(color: AppColors.textHint),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
borderSide: BorderSide(color: AppColors.borderColor),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
borderSide: BorderSide(color: AppColors.borderColor),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
borderSide: BorderSide(color: AppColors.primary, width: 2),
|
||||
),
|
||||
counterText: '',
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'${description?.length ?? 0}/200',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 设备选择器
|
||||
class DeviceSelector extends StatelessWidget {
|
||||
final String? selectedDevice;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const DeviceSelector({
|
||||
super.key,
|
||||
this.selectedDevice,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(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(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'设备选择',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
selectedDevice ?? '请选择设备',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: selectedDevice != null
|
||||
? AppColors.textPrimary
|
||||
: AppColors.textHint,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.arrow_drop_down,
|
||||
size: 20,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 问题等级选择器
|
||||
class LevelSelector extends StatelessWidget {
|
||||
final ProblemLevel? selectedLevel;
|
||||
final Function(ProblemLevel) onSelected;
|
||||
|
||||
const LevelSelector({
|
||||
super.key,
|
||||
this.selectedLevel,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(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: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'问题等级',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: ProblemLevel.values.map((level) {
|
||||
final isSelected = selectedLevel == level;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => onSelected(level),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
height: AppDimensions.buttonHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected && level == ProblemLevel.urgent
|
||||
? AppColors.danger.withOpacity(0.1)
|
||||
: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
border: Border.all(
|
||||
color: isSelected ? level.borderColor : AppColors.borderColor,
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
level.label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isSelected ? level.textColor : level.textColor.withOpacity(0.6),
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
259
lib/features/v2/report/presentation/widgets/media_uploader.dart
Normal file
259
lib/features/v2/report/presentation/widgets/media_uploader.dart
Normal file
@@ -0,0 +1,259 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 媒体上传模块
|
||||
class MediaUploader extends StatelessWidget {
|
||||
final List<String> mediaFiles;
|
||||
final VoidCallback onCameraTap;
|
||||
final VoidCallback onVideoTap;
|
||||
final VoidCallback onAddFromGallery;
|
||||
final Function(int) onRemove;
|
||||
final Function(int)? onTap;
|
||||
|
||||
const MediaUploader({
|
||||
super.key,
|
||||
required this.mediaFiles,
|
||||
required this.onCameraTap,
|
||||
required this.onVideoTap,
|
||||
required this.onAddFromGallery,
|
||||
required this.onRemove,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(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: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'上传图片/视频',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
// 拍照按钮
|
||||
_buildUploadButton(
|
||||
icon: Icons.camera_alt,
|
||||
label: '拍照',
|
||||
onTap: onCameraTap,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 录像按钮
|
||||
_buildUploadButton(
|
||||
icon: Icons.videocam,
|
||||
label: '录像',
|
||||
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,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
size: 14,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 视频播放图标
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUploadButton({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
bool isAddButton = false,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: isAddButton ? AppColors.cardBackground : AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusMedium),
|
||||
border: Border.all(
|
||||
color: isAddButton ? AppColors.borderColor : AppColors.primary,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: isAddButton ? AppColors.textHint : AppColors.primary,
|
||||
size: 24,
|
||||
),
|
||||
if (label.isNotEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isAddButton ? AppColors.textHint : AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 判断是否为视频文件
|
||||
bool _isVideoFile(String filePath) {
|
||||
final lowerPath = filePath.toLowerCase();
|
||||
return lowerPath.endsWith('.mp4') ||
|
||||
lowerPath.endsWith('.mov') ||
|
||||
lowerPath.endsWith('.avi') ||
|
||||
lowerPath.endsWith('.mkv') ||
|
||||
lowerPath.endsWith('.wmv') ||
|
||||
lowerPath.endsWith('.flv');
|
||||
}
|
||||
|
||||
/// 构建视频缩略图(显示占位符)
|
||||
Widget _buildVideoThumbnail(String filePath) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// 灰色背景
|
||||
Container(
|
||||
color: Colors.grey[300],
|
||||
),
|
||||
// 视频图标
|
||||
const Center(
|
||||
child: Icon(
|
||||
Icons.videocam,
|
||||
color: Colors.grey,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建占位图标
|
||||
Widget _buildPlaceholderIcon(IconData icon) {
|
||||
return Container(
|
||||
color: Colors.grey[300],
|
||||
child: Center(
|
||||
child: Icon(
|
||||
icon,
|
||||
color: Colors.grey,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 上报类型选择器
|
||||
class ReportTypeSelector extends StatelessWidget {
|
||||
final ReportType? selectedType;
|
||||
final Function(ReportType) onSelected;
|
||||
|
||||
const ReportTypeSelector({
|
||||
super.key,
|
||||
this.selectedType,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppDimensions.horizontalPadding),
|
||||
child: Row(
|
||||
children: ReportType.values.map((type) {
|
||||
final isSelected = selectedType == type;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => onSelected(type),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
border: Border.all(
|
||||
color: isSelected ? AppColors.primary : AppColors.borderColor,
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0x0D000000),
|
||||
blurRadius: AppDimensions.cardShadowBlur,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
type.icon,
|
||||
color: isSelected ? AppColors.primary : AppColors.textHint,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
type.label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isSelected ? AppColors.primary : AppColors.textSecondary,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
28
lib/features/v2/report/report.dart
Normal file
28
lib/features/v2/report/report.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
/// 现场上报模块 - 统一导出
|
||||
///
|
||||
/// 使用方式:
|
||||
/// ```dart
|
||||
/// import 'package:maibu_satabot_v2/features/v2/report/report.dart';
|
||||
/// ```
|
||||
|
||||
// 常量
|
||||
export 'presentation/constants/report_constants.dart';
|
||||
|
||||
// 状态
|
||||
export 'presentation/states/report_state.dart';
|
||||
|
||||
// Cubit
|
||||
export 'presentation/cubit/report_cubit.dart';
|
||||
|
||||
// 页面
|
||||
export 'presentation/pages/report_page.dart';
|
||||
|
||||
// 组件
|
||||
export 'presentation/widgets/report_type_selector.dart';
|
||||
export 'presentation/widgets/device_selector.dart';
|
||||
export 'presentation/widgets/description_input.dart';
|
||||
export 'presentation/widgets/media_uploader.dart';
|
||||
export 'presentation/widgets/level_selector.dart';
|
||||
|
||||
// 依赖注入
|
||||
export 'di/report_di.dart';
|
||||
Reference in New Issue
Block a user