所有一级页面和不分二级页面
This commit is contained in:
170
lib/features/v2/workorder/presentation/pages/workorder_page.dart
Normal file
170
lib/features/v2/workorder/presentation/pages/workorder_page.dart
Normal file
@@ -0,0 +1,170 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../../core/consts/workorder_consts.dart';
|
||||
import '../cubit/workorder_cubit.dart';
|
||||
import '../widgets/workorder_tabbar.dart';
|
||||
import '../widgets/workorder_count_card.dart';
|
||||
import '../widgets/workorder_item_card.dart';
|
||||
import '../../domain/usecases/get_workorder_list_usecase.dart';
|
||||
import '../../data/repositories/workorder_repository_impl.dart';
|
||||
import '../../data/datasources/workorder_remote_datasource_impl.dart';
|
||||
|
||||
/// 工单任务主页面
|
||||
class WorkOrderPage extends StatelessWidget {
|
||||
const WorkOrderPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 创建 Repository 和 UseCases
|
||||
final remoteDataSource = WorkOrderRemoteDataSourceImpl();
|
||||
final repository = WorkOrderRepositoryImpl(remoteDataSource: remoteDataSource);
|
||||
final getWorkOrderListUseCase = GetWorkOrderListUseCase(repository: repository);
|
||||
final getWorkOrderCountUseCase = GetWorkOrderCountUseCase(repository: repository);
|
||||
|
||||
return BlocProvider(
|
||||
create: (context) {
|
||||
final cubit = WorkOrderCubit(
|
||||
getWorkOrderListUseCase: getWorkOrderListUseCase,
|
||||
getWorkOrderCountUseCase: getWorkOrderCountUseCase,
|
||||
);
|
||||
cubit.loadInitialData();
|
||||
return cubit;
|
||||
},
|
||||
child: AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: SystemUiOverlayStyle.dark,
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFFF7F8FA),
|
||||
body: BlocBuilder<WorkOrderCubit, WorkOrderState>(
|
||||
builder: (context, state) {
|
||||
if (state is WorkOrderLoading) {
|
||||
return _buildLoadingView();
|
||||
} else if (state is WorkOrderLoaded) {
|
||||
return _buildContentView(context, state);
|
||||
} else if (state is WorkOrderError) {
|
||||
return _buildErrorView(context, state);
|
||||
}
|
||||
return _buildLoadingView();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingView() {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(AppConstants.primaryColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorView(BuildContext context, WorkOrderError state) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: AppConstants.auxiliaryTextColor,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
state.failure.message,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppConstants.auxiliaryTextColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<WorkOrderCubit>().loadInitialData();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppConstants.primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('重试'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContentView(BuildContext context, WorkOrderLoaded state) {
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// 导航栏
|
||||
_buildAppBar(),
|
||||
// 标签栏
|
||||
_buildTabBar(context, state),
|
||||
|
||||
// 内容区域
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await context.read<WorkOrderCubit>().refreshData();
|
||||
},
|
||||
child: ListView(
|
||||
children: [
|
||||
// 统计卡片
|
||||
if (state.count != null)
|
||||
WorkOrderCountCard(count: state.count!),
|
||||
|
||||
// 工单列表
|
||||
...state.workOrders.map((workOrder) => WorkOrderItemCard(
|
||||
workOrder: workOrder,
|
||||
onTap: () {
|
||||
// TODO: 跳转到工单详情页
|
||||
debugPrint('点击工单: ${workOrder.title}');
|
||||
},
|
||||
)),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppBar() {
|
||||
return Container(
|
||||
height: 44.0,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: const Row(
|
||||
children: [
|
||||
Text(
|
||||
'工单任务',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Icon(
|
||||
Icons.add_circle_outline,
|
||||
size: 24,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabBar(BuildContext context, WorkOrderLoaded state) {
|
||||
return WorkOrderTabBar(
|
||||
currentStatus: state.currentStatus,
|
||||
onTabChanged: (status) {
|
||||
context.read<WorkOrderCubit>().switchTab(status);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user