修复版本管理整包更新无法弹出的问题

完成集成新的登录接口的更换使用
完成集成用户的场站列表接口
完成开发设计选择场站项为全局属性
完成我的页面的个人信息的集成和详情页面的开发
完成设备页面的中无人机机场的列表接口对接入和个项页面的布局的优化
完成设备页面的中无人机机场的详情接口的对接和使用和页面的更新布局
This commit is contained in:
2026-05-29 14:13:34 +08:00
parent 938aac2db9
commit 335c468aac
23 changed files with 1294 additions and 705 deletions

View File

@@ -2,9 +2,14 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../../core/di/injection.dart';
import '../../../../../core/app/app_user_cubit.dart';
import '../../../../v2/site/presentation/cubit/site_cubit.dart';
import '../bloc/device_status_bloc.dart';
import '../bloc/device_status_event.dart';
import '../bloc/device_status_state.dart';
import '../bloc/drone_station_bloc.dart';
import '../bloc/drone_station_event.dart';
import '../bloc/drone_station_state.dart';
import '../widgets/device_item_widget.dart';
import '../widgets/drone_station_item_card.dart';
import 'robot_list_page.dart';
@@ -318,31 +323,122 @@ class DeviceStatusView extends StatelessWidget {
}
Widget _buildDroneStationList(BuildContext context) {
// 模拟机场数据
final stations = [
{'name': '1号无人机机场', 'id': 'AIRPORT-01'},
{'name': '2号无人机机场', 'id': 'AIRPORT-02'},
{'name': '3号无人机机场', 'id': 'AIRPORT-03'},
];
// 从全局 SiteCubit 获取选中的场站 ID
final selectedSite = sl<SiteCubit>().state.selectedSite;
if (selectedSite == null) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.location_off,
size: 48,
color: Color(0xFF86909C),
),
const SizedBox(height: 16),
const Text(
'请先选择场站',
style: TextStyle(
fontSize: 14,
color: Color(0xFF4E5969),
),
),
],
),
);
}
return ListView.builder(
padding: const EdgeInsets.only(top: 16, bottom: 16),
itemCount: stations.length,
itemBuilder: (context, index) {
final station = stations[index];
return DroneStationItemCard(
name: station['name'] as String,
id: station['id'] as String,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DroneStationDetailPage(),
return BlocProvider(
create: (_) => sl<DroneStationBloc>()..add(DroneStationLoadData(selectedSite.id)),
child: BlocBuilder<DroneStationBloc, DroneStationState>(
builder: (context, state) {
if (state is DroneStationLoading) {
return const Center(
child: CircularProgressIndicator(
color: Color(0xFF165DFF),
),
);
},
);
},
}
if (state is DroneStationError) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.error_outline,
size: 48,
color: Color(0xFF86909C),
),
const SizedBox(height: 16),
Text(
state.message,
style: const TextStyle(
fontSize: 14,
color: Color(0xFF4E5969),
),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
context.read<DroneStationBloc>().add(DroneStationLoadData(selectedSite.id));
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF165DFF),
foregroundColor: Colors.white,
),
child: const Text('重试'),
),
],
),
);
}
if (state is DroneStationLoaded) {
final stations = state.stations;
if (stations.isEmpty) {
return const Center(
child: Text(
'该场站暂无无人机机场',
style: TextStyle(
fontSize: 14,
color: Color(0xFF4E5969),
),
),
);
}
return RefreshIndicator(
onRefresh: () async {
context.read<DroneStationBloc>().add(DroneStationRefresh(selectedSite.id));
},
color: const Color(0xFF165DFF),
child: ListView.builder(
padding: const EdgeInsets.only(top: 16, bottom: 16),
itemCount: stations.length,
itemBuilder: (context, index) {
final station = stations[index];
return DroneStationItemCard(
station: station,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DroneStationDetailPage(station: station),
),
);
},
);
},
),
);
}
return const Center(child: Text('暂无数据'));
},
),
);
}

View File

@@ -1,111 +1,133 @@
import 'package:flutter/material.dart';
import 'drone_mission_control_page.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../../core/di/injection.dart';
import '../../domain/entities/drone_station_entity.dart';
import '../bloc/drone_station_bloc.dart';
import '../bloc/drone_station_event.dart';
import '../bloc/drone_station_state.dart';
import 'drone_video_control_page.dart';
import 'drone_mission_control_page.dart';
import 'drone_monitor_page.dart';
/// 无人机机场详情页面
class DroneStationDetailPage extends StatelessWidget {
const DroneStationDetailPage({super.key});
class DroneStationDetailPage extends StatefulWidget {
final DroneStationEntity station;
const DroneStationDetailPage({
super.key,
required this.station,
});
@override
State<DroneStationDetailPage> createState() => _DroneStationDetailPageState();
}
class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
late DroneStationBloc _bloc;
@override
void initState() {
super.initState();
_bloc = sl<DroneStationBloc>();
_bloc.add(UAVDetailLoad(
gatewaySn: widget.station.gatewaySn,
deviceSn: widget.station.deviceSn,
));
}
@override
void dispose() {
_bloc.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F6F8),
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Color(0xFF1D2129)),
onPressed: () => Navigator.pop(context),
),
title: const Text(
'无人机机场详情',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
return BlocProvider.value(
value: _bloc,
child: Scaffold(
backgroundColor: const Color(0xFFF5F6F8),
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Color(0xFF1D2129)),
onPressed: () => Navigator.pop(context),
),
title: const Text(
'无人机机场详情',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
centerTitle: true,
),
body: BlocBuilder<DroneStationBloc, DroneStationState>(
builder: (context, state) {
if (state is UAVDetailLoading) {
return const Center(
child: CircularProgressIndicator(color: Color(0xFF165DFF)),
);
}
if (state is UAVDetailError) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 48, color: Color(0xFF86909C)),
const SizedBox(height: 16),
Text(state.message, style: const TextStyle(fontSize: 14, color: Color(0xFF4E5969))),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
_bloc.add(UAVDetailLoad(
gatewaySn: widget.station.gatewaySn,
deviceSn: widget.station.deviceSn,
));
},
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF165DFF)),
child: const Text('重试'),
),
],
),
);
}
if (state is UAVDetailLoaded) {
return _buildContent(state.detail);
}
return const Center(child: Text('正在加载...'));
},
),
centerTitle: true,
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
_buildAirportStatusCard(),
const SizedBox(height: 12),
_buildDroneStatusCard(context),
const SizedBox(height: 12),
_buildQuickActions(context),
const SizedBox(height: 20),
],
),
);
}
/// 机场状态卡片
Widget _buildAirportStatusCard() {
Widget _buildContent(UAVDetailEntity detail) {
return ListView(
padding: const EdgeInsets.all(16),
children: [
_buildAirportStatusCard(detail),
const SizedBox(height: 12),
_buildDroneStatusCard(detail),
const SizedBox(height: 12),
_buildQuickActions(),
const SizedBox(height: 20),
],
);
}
Widget _buildAirportStatusCard(UAVDetailEntity detail) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 8,
offset: Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'机场状态',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const SizedBox(height: 16),
_buildStatusRow('机场编号', 'AIRPORT-01', status: '正常'),
const SizedBox(height: 12),
_buildStatusRow('位置', '升压站旁 - 无人机机场'),
const SizedBox(height: 12),
_buildStatusRow('舱门状态', '关闭', status: '正常'),
const SizedBox(height: 12),
_buildStatusRowWithProgress('充电状态', '充电中', '85%'),
const SizedBox(height: 12),
_buildWeatherRow(),
const SizedBox(height: 12),
_buildStatusRow('网络状态', '4G/5G 强'),
],
),
);
}
/// 无人机状态卡片
Widget _buildDroneStatusCard(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DroneVideoControlPage(),
),
);
},
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 8,
offset: Offset(0, 2),
),
BoxShadow(color: Color(0x0D000000), blurRadius: 8, offset: Offset(0, 2)),
],
),
child: Column(
@@ -113,148 +135,109 @@ class DroneStationDetailPage extends StatelessWidget {
children: [
Row(
children: [
const Text(
'无人机状态',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const Text('机场状态', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1D2129))),
const Spacer(),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: const Color(0xFF00B42A).withOpacity(0.1),
color: detail.isOnline ? const Color(0xFF00B42A).withOpacity(0.1) : const Color(0xFFF53F3F).withOpacity(0.1),
borderRadius: BorderRadius.circular(4),
),
child: const Text(
'在线',
style: TextStyle(
fontSize: 12,
color: Color(0xFF00B42A),
fontWeight: FontWeight.w500,
),
),
child: Text(detail.isOnline ? '在线' : '离线', style: TextStyle(fontSize: 12, color: detail.isOnline ? const Color(0xFF00B42A) : const Color(0xFFF53F3F), fontWeight: FontWeight.w500)),
),
],
),
const SizedBox(height: 16),
Row(
children: [
Image.asset(
'assets/images/xunjian.png',
width: 60,
height: 60,
fit: BoxFit.contain,
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'无人机 - 01',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Color(0xFF1D2129),
),
),
const SizedBox(height: 8),
_buildDroneBatteryRow(),
],
),
),
],
),
const SizedBox(height: 12),
_buildStatusRow('飞行模式', '待命'),
const SizedBox(height: 12),
_buildStatusRow('机身状态', '正常'),
const SizedBox(height: 12),
_buildStatusRow('上次任务', '逆变器区巡检(05-20 10:30)'),
const Divider(height: 1, color: Color(0xFFF2F3F5)),
const SizedBox(height: 16),
_buildInfoRow('机场名称', detail.callsign.isNotEmpty ? detail.callsign : '未知'),
_buildInfoRow('设备序列号', detail.deviceSn),
_buildInfoRow('网关序列号', detail.gatewaySn),
_buildInfoRow('位置坐标', (detail.latitude != null && detail.longitude != null) ? '${detail.latitude}, ${detail.longitude}' : '未知'),
_buildInfoRow('电量', detail.capacityPercent != null ? '${detail.capacityPercent}%' : '未知'),
_buildInfoRow('环境温度', detail.environmentTemperature != null ? '${detail.environmentTemperature}°C' : '未知'),
_buildInfoRow('风速', detail.windSpeed != null ? '${detail.windSpeed} m/s' : '未知'),
_buildInfoRow('降雨量', detail.rainfall ?? '未知'),
_buildInfoRow('网络状态', detail.networkState?.toString() ?? '未知'),
_buildPositionStateRow('位置状态', detail.positionState),
],
),
),
);
}
/// 快捷操作按钮
Widget _buildQuickActions(BuildContext context) {
Widget _buildDroneStatusCard(UAVDetailEntity detail) {
return GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => const DroneVideoControlPage()));
},
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: const [BoxShadow(color: Color(0x0D000000), blurRadius: 8, offset: Offset(0, 2))],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Text('无人机状态', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1D2129))),
const Spacer(),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: detail.isDroneOnline ? const Color(0xFF00B42A).withOpacity(0.1) : const Color(0xFFF53F3F).withOpacity(0.1),
borderRadius: BorderRadius.circular(4),
),
child: Text(detail.isDroneOnline ? '在线' : '离线', style: TextStyle(fontSize: 12, color: detail.isDroneOnline ? const Color(0xFF00B42A) : const Color(0xFFF53F3F), fontWeight: FontWeight.w500)),
),
],
),
const SizedBox(height: 16),
_buildInfoRow('无人机呼号', detail.droneCallsign.isNotEmpty ? detail.droneCallsign : '未知'),
const SizedBox(height: 12),
_buildInfoRow('设备序列号', detail.deviceSn),
const SizedBox(height: 12),
_buildInfoRow('电量', detail.capacityPercent != null ? '${detail.capacityPercent}%' : '未知'),
const SizedBox(height: 12),
_buildInfoRow('高度', detail.height != null ? '${detail.height} m' : '未知'),
const SizedBox(height: 12),
_buildInfoRow('距离home点', detail.homeDistance != null ? '${detail.homeDistance} m' : '未知'),
const SizedBox(height: 12),
_buildInfoRow('实时电量', detail.liveCapacity != null ? '${detail.liveCapacity}%' : '未知'),
if (detail.gatewayCameraList != null && detail.gatewayCameraList!.isNotEmpty) ...[
const SizedBox(height: 12),
_buildCameraListRow('网关摄像头', detail.gatewayCameraList!),
],
],
),
),
);
}
Widget _buildQuickActions() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 8,
offset: Offset(0, 2),
),
],
boxShadow: const [BoxShadow(color: Color(0x0D000000), blurRadius: 8, offset: Offset(0, 2))],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'快捷操作',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const Text('快捷操作', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1D2129))),
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: _buildQuickActionButton(
context,
icon: Icons.flight_takeoff,
label: '开舱',
color: const Color(0xFF165DFF),
onTap: () {},
),
),
Expanded(child: _buildQuickActionButton(icon: Icons.flight_takeoff, label: '开舱', color: const Color(0xFF165DFF), onTap: () {})),
const SizedBox(width: 12),
Expanded(
child: _buildQuickActionButton(
context,
icon: Icons.flight,
label: '起飞准备',
color: const Color(0xFF165DFF),
onTap: () {},
),
),
Expanded(child: _buildQuickActionButton(icon: Icons.flight, label: '起飞准备', color: const Color(0xFF165DFF), onTap: () {})),
const SizedBox(width: 12),
Expanded(
child: _buildQuickActionButton(
context,
icon: Icons.home,
label: '返航',
color: const Color(0xFFFF7D00),
onTap: () {},
),
),
Expanded(child: _buildQuickActionButton(icon: Icons.home, label: '返航', color: const Color(0xFFFF7D00), onTap: () {})),
const SizedBox(width: 12),
Expanded(
child: _buildQuickActionButton(
context,
icon: Icons.task,
label: '任务下发',
color: const Color(0xFF165DFF),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DroneMissionControlPage(),
),
);
},
),
),
Expanded(child: _buildQuickActionButton(icon: Icons.monitor, label: '看监控', color: const Color(0xFF165DFF), onTap: _goToMonitor)),
],
),
],
@@ -262,37 +245,45 @@ class DroneStationDetailPage extends StatelessWidget {
);
}
/// 快捷操作按钮
Widget _buildQuickActionButton(
BuildContext context, {
required IconData icon,
required String label,
required Color color,
required VoidCallback onTap,
}) {
void _goToMonitor() {
Navigator.push(context, MaterialPageRoute(builder: (context) => DroneMonitorPage()));
}
Widget _buildQuickActionButton({required IconData icon, required String label, required Color color, required VoidCallback onTap}) {
return GestureDetector(
onTap: onTap,
child: Column(
children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: color.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
),
child: Icon(
icon,
color: color,
size: 24,
),
width: 48, height: 48,
decoration: BoxDecoration(color: color.withOpacity(0.1), borderRadius: BorderRadius.circular(12)),
child: Icon(icon, color: color, size: 24),
),
const SizedBox(height: 8),
Text(
label,
style: const TextStyle(
fontSize: 12,
color: Color(0xFF4E5969),
Text(label, style: const TextStyle(fontSize: 12, color: Color(0xFF4E5969))),
],
),
);
}
Widget _buildInfoRow(String label, String value) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 80,
child: Text(label, style: const TextStyle(fontSize: 12, color: Color(0xFF86909C))),
),
const SizedBox(width: 12),
const Text(':', style: TextStyle(fontSize: 12, color: Color(0xFFC0C4CC))),
const SizedBox(width: 8),
Expanded(
child: Text(
value,
style: const TextStyle(fontSize: 12, color: Color(0xFF1D2129), fontWeight: FontWeight.w500),
textAlign: TextAlign.left,
),
),
],
@@ -300,166 +291,29 @@ class DroneStationDetailPage extends StatelessWidget {
);
}
/// 状态行(带状态标签)
Widget _buildStatusRow(String label, String value, {String? status}) {
Widget _buildPositionStateRow(String label, PositionState? positionState) {
String value = '未知';
if (positionState != null) {
value = 'GPS:${positionState.gpsNumber} RTX:${positionState.rtkNumber} 固定:${positionState.isFixed}';
}
return Row(
children: [
Text(
label,
style: const TextStyle(
fontSize: 13,
color: Color(0xFF86909C),
),
),
Text(label, style: const TextStyle(fontSize: 13, color: Color(0xFF86909C))),
const Spacer(),
Text(
value,
style: const TextStyle(
fontSize: 13,
color: Color(0xFF1D2129),
fontWeight: FontWeight.w500,
),
),
if (status != null) ...[
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: const Color(0xFF00B42A).withOpacity(0.1),
borderRadius: BorderRadius.circular(4),
),
child: Text(
status,
style: const TextStyle(
fontSize: 11,
color: Color(0xFF00B42A),
fontWeight: FontWeight.w500,
),
),
),
],
Flexible(child: Text(value, style: const TextStyle(fontSize: 13, color: Color(0xFF1D2129), fontWeight: FontWeight.w500), textAlign: TextAlign.right)),
],
);
}
/// 带进度条的状态行
Widget _buildStatusRowWithProgress(String label, String value, String progress) {
Widget _buildCameraListRow(String label, List<CameraInfo> cameras) {
String value = cameras.map((c) => '${c.cameraIndex}:${c.cameraPosition}').join(' | ');
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: const TextStyle(
fontSize: 13,
color: Color(0xFF86909C),
),
),
Text(label, style: const TextStyle(fontSize: 13, color: Color(0xFF86909C))),
const Spacer(),
Text(
value,
style: const TextStyle(
fontSize: 13,
color: Color(0xFF1D2129),
fontWeight: FontWeight.w500,
),
),
const SizedBox(width: 8),
Text(
progress,
style: const TextStyle(
fontSize: 13,
color: Color(0xFF165DFF),
fontWeight: FontWeight.w600,
),
),
const SizedBox(width: 4),
const Icon(
Icons.arrow_forward_ios,
size: 12,
color: Color(0xFF86909C),
),
Flexible(child: Text(value, style: const TextStyle(fontSize: 13, color: Color(0xFF1D2129), fontWeight: FontWeight.w500), textAlign: TextAlign.right)),
],
);
}
/// 气象条件行
Widget _buildWeatherRow() {
return Row(
children: [
const Text(
'气象条件',
style: TextStyle(
fontSize: 13,
color: Color(0xFF86909C),
),
),
const Spacer(),
Row(
children: [
const Icon(Icons.wb_sunny, size: 16, color: Color(0xFFFF7D00)),
const SizedBox(width: 4),
const Text(
'晴',
style: TextStyle(
fontSize: 13,
color: Color(0xFF1D2129),
fontWeight: FontWeight.w500,
),
),
const SizedBox(width: 8),
const Text(
'25°C',
style: TextStyle(
fontSize: 13,
color: Color(0xFF1D2129),
),
),
const SizedBox(width: 8),
const Text(
'东南风 2级',
style: TextStyle(
fontSize: 13,
color: Color(0xFF1D2129),
),
),
],
),
],
);
}
/// 无人机电量行
Widget _buildDroneBatteryRow() {
return Row(
children: [
const Text(
'电量',
style: TextStyle(
fontSize: 13,
color: Color(0xFF86909C),
),
),
const SizedBox(width: 8),
Expanded(
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: LinearProgressIndicator(
value: 0.78,
backgroundColor: const Color(0xFFF2F3F5),
valueColor: const AlwaysStoppedAnimation<Color>(Color(0xFF00B42A)),
minHeight: 6,
),
),
),
const SizedBox(width: 8),
const Text(
'78%',
style: TextStyle(
fontSize: 13,
color: Color(0xFF00B42A),
fontWeight: FontWeight.w600,
),
),
],
);
}
}
}

View File

@@ -182,12 +182,12 @@ class DroneStationStatusPage extends StatelessWidget {
),
],
),
const SizedBox(height: 12),
_buildStatusRow('飞行模式', '待命'),
const SizedBox(height: 12),
_buildStatusRow('机身状态', '正常'),
const SizedBox(height: 12),
_buildStatusRow('上次任务', '逆变器区巡检(05-20 10:30)'),
// const SizedBox(height: 12),
// _buildStatusRow('飞行模式', '待命'),
// const SizedBox(height: 12),
// _buildStatusRow('机身状态', '正常'),
// const SizedBox(height: 12),
// _buildStatusRow('上次任务', '逆变器区巡检(05-20 10:30)'),
],
),
);

View File

@@ -1,12 +1,19 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/site_entity.dart';
import 'package:maibu_satabot_v2/features/v2/home/domain/usecases/get_home_data_usecase.dart';
import 'package:maibu_satabot_v2/features/v2/home/domain/usecases/get_site_list_usecase.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_event.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_state.dart';
class HomeV2Bloc extends Bloc<HomeV2Event, HomeV2State> {
final GetHomeDataUseCase getHomeDataUseCase;
final GetSiteListUseCase getSiteListUseCase;
final AppUserCubit appUserCubit;
final SiteCubit siteCubit;
HomeV2Bloc(this.getHomeDataUseCase) : super(const HomeV2Initial()) {
HomeV2Bloc(this.getHomeDataUseCase, this.getSiteListUseCase, this.appUserCubit, this.siteCubit) : super(const HomeV2Initial()) {
on<HomeV2LoadData>(_onLoadData);
on<HomeV2Refresh>(_onRefresh);
on<HomeV2ToggleTrendType>(_onToggleTrendType);
@@ -18,11 +25,55 @@ class HomeV2Bloc extends Bloc<HomeV2Event, HomeV2State> {
) async {
emit(const HomeV2Loading());
final result = await getHomeDataUseCase(const NoParams());
final user = appUserCubit.state.user;
if (user == null) {
emit(const HomeV2Error('用户未登录'));
return;
}
result.fold(
// 并行加载首页数据和场站列表
final homeResult = await getHomeDataUseCase(const NoParams());
final siteResult = await getSiteListUseCase(user.orgId); // 使用用户的 orgId
homeResult.fold(
(failure) => emit(HomeV2Error(failure.message)),
(data) => emit(HomeV2Loaded(homeData: data)),
(homeData) {
List<SiteEntity> sites = [];
SiteEntity? selectedSite;
siteResult.fold(
(failure) {
print('加载场站列表失败: ${failure.message}');
},
(siteList) {
sites = siteList;
// 从全局 SiteCubit 获取之前选中的场站
final savedSelectedSite = siteCubit.state.selectedSite;
// 尝试找到之前选中的场站
if (savedSelectedSite != null && siteList.isNotEmpty) {
selectedSite = siteList.firstWhere(
(site) => site.id == savedSelectedSite.id,
orElse: () => siteList.first,
);
} else {
// 没有选中过,默认选中第一个
selectedSite = siteList.isNotEmpty ? siteList.first : null;
}
// 更新全局 SiteCubit 的选中状态
if (selectedSite != null) {
siteCubit.selectSite(selectedSite!);
}
},
);
emit(HomeV2Loaded(
homeData: homeData,
sites: sites,
selectedSite: selectedSite,
));
},
);
}
@@ -31,14 +82,20 @@ class HomeV2Bloc extends Bloc<HomeV2Event, HomeV2State> {
Emitter<HomeV2State> emit,
) async {
if (state is HomeV2Loaded) {
final result = await getHomeDataUseCase(const NoParams());
final currentState = state as HomeV2Loaded;
final homeResult = await getHomeDataUseCase(const NoParams());
result.fold(
homeResult.fold(
(failure) => emit(HomeV2Error(failure.message)),
(data) => emit(HomeV2Loaded(
homeData: data,
trendType: (state as HomeV2Loaded).trendType,
)),
(homeData) {
emit(HomeV2Loaded(
homeData: homeData,
trendType: currentState.trendType,
sites: currentState.sites,
selectedSite: currentState.selectedSite,
));
},
);
}
}

View File

@@ -1,4 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/site_entity.dart';
abstract class HomeV2Event extends Equatable {
const HomeV2Event();
@@ -23,3 +24,12 @@ class HomeV2ToggleTrendType extends HomeV2Event {
@override
List<Object?> get props => [type];
}
class HomeV2SelectSite extends HomeV2Event {
final SiteEntity site;
const HomeV2SelectSite(this.site);
@override
List<Object?> get props => [site];
}

View File

@@ -1,5 +1,6 @@
import 'package:equatable/equatable.dart';
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/home_entity.dart';
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/site_entity.dart';
abstract class HomeV2State extends Equatable {
const HomeV2State();
@@ -19,24 +20,32 @@ class HomeV2Loading extends HomeV2State {
class HomeV2Loaded extends HomeV2State {
final HomeEntity homeData;
final String trendType;
final List<SiteEntity> sites;
final SiteEntity? selectedSite;
const HomeV2Loaded({
required this.homeData,
this.trendType = 'kW',
this.sites = const [],
this.selectedSite,
});
HomeV2Loaded copyWith({
HomeEntity? homeData,
String? trendType,
List<SiteEntity>? sites,
SiteEntity? selectedSite,
}) {
return HomeV2Loaded(
homeData: homeData ?? this.homeData,
trendType: trendType ?? this.trendType,
sites: sites ?? this.sites,
selectedSite: selectedSite ?? this.selectedSite,
);
}
@override
List<Object?> get props => [homeData, trendType];
List<Object?> get props => [homeData, trendType, sites, selectedSite];
}
class HomeV2Error extends HomeV2State {

View File

@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:maibu_satabot_v2/core/di/injection.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_bloc.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_event.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_state.dart';
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/power_card.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/stats_grid.dart';
import 'package:maibu_satabot_v2/features/v2/home/presentation/widgets/work_order_card.dart';
@@ -19,13 +21,6 @@ class HomeV2Page extends StatefulWidget {
class _HomeV2PageState extends State<HomeV2Page> {
late HomeV2Bloc _bloc;
String _selectedPlant = '示例光伏电站';
final List<String> _plantList = [
'示例光伏电站',
'一号光伏电站',
'二号光伏电站',
'三号光伏电站',
];
@override
void initState() {
@@ -82,15 +77,21 @@ class _HomeV2PageState extends State<HomeV2Page> {
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(
_selectedPlant,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
child: StreamBuilder<SiteState>(
stream: sl<SiteCubit>().stream,
builder: (context, snapshot) {
final siteState = snapshot.data ?? sl<SiteCubit>().state;
return Text(
siteState.selectedSite?.siteName ?? '选择电站',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
);
},
),
),
const SizedBox(width: 4),
@@ -210,6 +211,18 @@ class _HomeV2PageState extends State<HomeV2Page> {
}
void _showPlantSelector() {
if (_bloc.state is! HomeV2Loaded) return;
final currentState = _bloc.state as HomeV2Loaded;
final sites = currentState.sites;
if (sites.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('暂无可用电站')),
);
return;
}
showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
@@ -217,34 +230,60 @@ class _HomeV2PageState extends State<HomeV2Page> {
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (context) {
return Container(
padding: const EdgeInsets.all(14),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'选择电站',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
return BlocBuilder<HomeV2Bloc, HomeV2State>(
bloc: _bloc,
builder: (context, state) {
if (state is! HomeV2Loaded) return Container();
return Container(
padding: const EdgeInsets.all(14),
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.6,
),
const SizedBox(height: 14),
..._plantList.map((plant) => ListTile(
title: Text(plant),
trailing: _selectedPlant == plant
? const Icon(Icons.check, color: Color(0xFF165DFF))
: null,
onTap: () {
setState(() {
_selectedPlant = plant;
});
Navigator.pop(context);
},
)),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'选择电站',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF1D2129),
),
),
const SizedBox(height: 14),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: state.sites.length,
itemBuilder: (context, index) {
final site = state.sites[index];
final isSelected = state.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: () {
// 更新全局选中的场站
sl<SiteCubit>().selectSite(site);
Navigator.pop(context);
// 切换场站后,重新加载首页数据
_bloc.add(const HomeV2LoadData());
},
);
},
),
),
],
),
);
},
);
},
);

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/services.dart';
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/cubit/my_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/states/my_state.dart';
import 'package:maibu_satabot_v2/features/v2/my/di/my_di.dart';
@@ -9,6 +10,7 @@ import 'package:maibu_satabot_v2/features/v2/my/presentation/widgets/user_profil
import 'package:maibu_satabot_v2/features/v2/my/presentation/widgets/quick_action_card.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/widgets/menu_item_card.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/pages/system_settings_page.dart';
import 'package:maibu_satabot_v2/features/v2/my/presentation/pages/profile_detail_page.dart';
/// 我的页面(100% 还原设计稿)
class MyPage extends StatelessWidget {
@@ -53,15 +55,28 @@ class _MyPageContent extends StatelessWidget {
if (state is MyLoaded) {
final cubit = context.read<MyCubit>();
final appUserState = context.watch<AppUserCubit>().state;
final user = appUserState.user;
// 获取用户信息(优先使用昵称,其次用户名)
final userName = user?.nickname ?? user?.username ?? '未知用户';
final userRole = user?.email ?? user?.phone ?? '未设置';
return Column(
children: [
// 用户信息卡片(延伸到状态栏)
UserProfileCard(
name: state.userProfile.name,
role: state.userProfile.role,
name: userName,
role: userRole,
avatar: user?.avatar,
onTap: () {
// TODO: 跳转到个人信息页面
debugPrint('点击个人信息');
// 跳转到个人信息详情页
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ProfileDetailPage(),
),
);
},
),
// 快捷入口卡片(负margin向上重叠)
@@ -125,7 +140,19 @@ class _MyPageContent extends StatelessWidget {
/// 处理菜单项点击
void _handleMenuItemTap(BuildContext context, MyCubit cubit, dynamic item) {
debugPrint('🔍 点击菜单项 ID: ${item.id}, 标题: ${item.title}');
switch (item.id) {
case 'personal_info':
debugPrint('✅ 准备跳转到个人信息详情页');
// 跳转到个人信息详情页
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ProfileDetailPage(),
),
);
debugPrint('✅ 已调用 Navigator.push');
break;
case 'offline_cache':
_showClearCacheDialog(context, cubit);
break;

View File

@@ -7,92 +7,110 @@ class UserProfileCard extends StatelessWidget {
super.key,
required this.name,
required this.role,
this.avatar,
this.onTap,
});
final String name;
final String role;
final String? avatar;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(20, 70, 20, 50),
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFF165DFF),
Color(0xFF0E42CC),
return InkWell(
onTap: onTap,
child: Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(20, 70, 20, 50),
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFF165DFF),
Color(0xFF0E42CC),
],
),
),
child: Row(
children: [
// 头像
Container(
width: 56,
height: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 2,
),
),
child: ClipOval(
child: _buildAvatar(),
),
),
const SizedBox(width: 14),
// 用户信息
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
letterSpacing: 0.5,
),
),
const SizedBox(height: 6),
Text(
role,
style: TextStyle(
fontSize: 13,
color: Colors.white.withOpacity(0.85),
letterSpacing: 0.3,
),
),
],
),
),
// 箭头
Icon(
Icons.chevron_right,
color: Colors.white.withOpacity(0.9),
size: 24,
),
],
),
),
child: Row(
children: [
// 头像
Container(
width: 56,
height: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 2,
),
),
child: ClipOval(
child: Image.asset(
'assets/images/app_logo.png',
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Container(
color: Colors.white,
child: Icon(
Icons.person,
size: 32,
color: const Color(0xFF165DFF),
),
);
},
),
),
),
const SizedBox(width: 14),
// 用户信息
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
letterSpacing: 0.5,
),
),
const SizedBox(height: 6),
Text(
role,
style: TextStyle(
fontSize: 13,
color: Colors.white.withOpacity(0.85),
letterSpacing: 0.3,
),
),
],
),
),
// 箭头
Icon(
Icons.chevron_right,
color: Colors.white.withOpacity(0.9),
size: 24,
),
],
);
}
Widget _buildAvatar() {
// 如果有头像 URL,显示网络图片
if (avatar != null && avatar!.isNotEmpty) {
return Image.network(
avatar!,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return _buildDefaultAvatar();
},
);
}
// 否则显示默认头像
return _buildDefaultAvatar();
}
Widget _buildDefaultAvatar() {
return Container(
color: Colors.white,
child: Icon(
Icons.person,
size: 32,
color: const Color(0xFF165DFF),
),
);
}