【后端修复】 - 删除diet/consultation agent假工具声明 - 修复DayOfWeek实体注释 - 修复Vision API content序列化 - cleanup_service级联删除修复 - 用药提醒时区偏差修复 - 统一DateTime处理(UtcNow+8) - 新增UTC DateTime JSON转换器 【前端UI重构】 - 配色体系全面更新(#8B5CF6淡紫+#F0ECFF背景) - 登录页重设计 - 首页重设计(透明顶栏、渐变背景、胶囊输入区) - 聊天卡片加白蓝边框、渐变标题 - 侧边栏重构(渐变背景、合并顶部、删除底部设置) - 确认卡片可编辑字段恢复 - 所有子页面加返回按钮 - catch异常加日志 - 删除后refresh provider缓存
242 lines
10 KiB
Dart
242 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../core/app_colors.dart';
|
|
import '../../core/app_theme.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../core/navigation_provider.dart';
|
|
import 'report_pages.dart';
|
|
|
|
/// AI 解读页 — 从服务器获取真实报告数据
|
|
class AiAnalysisPage extends ConsumerStatefulWidget {
|
|
final String id;
|
|
const AiAnalysisPage({super.key, required this.id});
|
|
|
|
@override
|
|
ConsumerState<AiAnalysisPage> createState() => _AiAnalysisPageState();
|
|
}
|
|
|
|
class _AiAnalysisPageState extends ConsumerState<AiAnalysisPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
ref.read(reportProvider.notifier).loadReports();
|
|
ref.read(reportProvider.notifier).fetchReportDetail(widget.id);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final analysis = ref.watch(reportProvider.select((s) => s.currentAnalysis));
|
|
final reports = ref.watch(reportProvider.select((s) => s.reports));
|
|
final reportItem = reports.where((r) => r.id == widget.id).firstOrNull;
|
|
|
|
if (analysis == null) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('AI 解读')),
|
|
body: const Center(child: CircularProgressIndicator(color: AppTheme.primary)),
|
|
);
|
|
}
|
|
|
|
return Scaffold(
|
|
backgroundColor: AppTheme.bg,
|
|
appBar: AppBar(
|
|
title: const Text('AI 智能解读'),
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back),
|
|
onPressed: () {
|
|
ref.read(reportProvider.notifier).clearAnalysis();
|
|
popRoute(ref);
|
|
},
|
|
),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
// 报告标题
|
|
_buildHeader(analysis),
|
|
const SizedBox(height: 16),
|
|
// 审核状态
|
|
if (reportItem != null) _buildStatusBadge(reportItem),
|
|
if (reportItem != null) const SizedBox(height: 16),
|
|
// 指标分析
|
|
_buildIndicators(analysis),
|
|
const SizedBox(height: 16),
|
|
// AI 总结
|
|
_buildSummary(analysis),
|
|
const SizedBox(height: 16),
|
|
// 医生审核意见
|
|
if (reportItem != null && reportItem.status == 'DoctorReviewed')
|
|
_buildDoctorReview(reportItem),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: AppTheme.surface, borderRadius: BorderRadius.circular(AppTheme.rLg),
|
|
boxShadow: [AppTheme.shadowCard]),
|
|
child: Row(children: [
|
|
Container(width: 48, height: 48, decoration: BoxDecoration(color: AppTheme.primaryLight, borderRadius: BorderRadius.circular(12)),
|
|
child: const Icon(Icons.auto_awesome, size: 28, color: AppTheme.primary)),
|
|
const SizedBox(width: 14),
|
|
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(analysis.reportType, style: const TextStyle(fontSize: 21, fontWeight: FontWeight.w700)),
|
|
const SizedBox(height: 4),
|
|
const Text('AI 预解读结果 · 待医生确认', style: TextStyle(fontSize: 16, color: AppColors.textSecondary)),
|
|
])),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildStatusBadge(ReportItem report) {
|
|
final isReviewed = report.status == 'DoctorReviewed';
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: isReviewed ? AppColors.successLight : AppColors.warningLight,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
|
Icon(isReviewed ? Icons.check_circle : Icons.hourglass_empty, size: 21,
|
|
color: isReviewed ? AppTheme.success : AppColors.warning),
|
|
const SizedBox(width: 8),
|
|
Text(isReviewed ? '已通过医生审核' : '等待医生审核中',
|
|
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500,
|
|
color: isReviewed ? AppTheme.success : AppColors.warning)),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildIndicators(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(color: AppTheme.surface, borderRadius: BorderRadius.circular(AppTheme.rLg)),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
const Padding(
|
|
padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Text('指标分析', style: TextStyle(fontSize: 19, fontWeight: FontWeight.w700)),
|
|
),
|
|
...analysis.indicators.map((ind) => _buildIndicatorRow(ind)),
|
|
const SizedBox(height: 8),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildIndicatorRow(Indicator ind) {
|
|
final Color color;
|
|
final IconData icon;
|
|
switch (ind.status) {
|
|
case 'high': color = AppTheme.error; icon = Icons.arrow_upward; break;
|
|
case 'low': color = AppColors.warning; icon = Icons.arrow_downward; break;
|
|
default: color = AppTheme.success; icon = Icons.check_circle;
|
|
}
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
decoration: BoxDecoration(border: Border(bottom: BorderSide(color: AppColors.border))),
|
|
child: Row(children: [
|
|
Expanded(
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(ind.name, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
|
|
if (ind.referenceRange != null && ind.referenceRange!.isNotEmpty)
|
|
Text('参考值: ${ind.referenceRange}', style: TextStyle(fontSize: 15, color: AppColors.textHint)),
|
|
]),
|
|
),
|
|
Column(crossAxisAlignment: CrossAxisAlignment.end, children: [
|
|
Text('${ind.value} ${ind.unit}',
|
|
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w600, color: color)),
|
|
Icon(icon, size: 17, color: color),
|
|
]),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildSummary(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: AppColors.warningLight, borderRadius: BorderRadius.circular(AppTheme.rLg),
|
|
border: Border.all(color: AppColors.warning.withAlpha(80))),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Row(children: [
|
|
const Text('💡', style: TextStyle(fontSize: 21)),
|
|
const SizedBox(width: 8),
|
|
Text('综合解读', style: TextStyle(fontSize: 19, fontWeight: FontWeight.w700, color: AppColors.warning)),
|
|
]),
|
|
const SizedBox(height: 10),
|
|
Text(analysis.summary.isNotEmpty ? analysis.summary : '暂无 AI 解读结果',
|
|
style: TextStyle(fontSize: 17, color: AppColors.warning, height: 1.6)),
|
|
const SizedBox(height: 10),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(10),
|
|
decoration: BoxDecoration(color: AppTheme.surface, borderRadius: BorderRadius.circular(AppTheme.rSm)),
|
|
child: Text('⚠️ AI 解读仅供参考,请以医生诊断为准',
|
|
style: TextStyle(fontSize: 15, color: AppColors.warning)),
|
|
),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildDoctorReview(ReportItem report) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: AppColors.successLight, borderRadius: BorderRadius.circular(AppTheme.rLg),
|
|
border: Border.all(color: AppColors.success.withAlpha(80))),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Row(children: [
|
|
const Text('✅', style: TextStyle(fontSize: 21)),
|
|
const SizedBox(width: 8),
|
|
Text('医生审核意见', style: TextStyle(fontSize: 19, fontWeight: FontWeight.w700, color: AppColors.success)),
|
|
]),
|
|
if (report.doctorName != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text('审核医生:${report.doctorName}', style: TextStyle(fontSize: 16, color: AppColors.success)),
|
|
],
|
|
if (report.reviewedAt != null) ...[
|
|
const SizedBox(height: 2),
|
|
Text('审核时间:${report.reviewedAt!.toLocal().toString().substring(0, 16)}',
|
|
style: TextStyle(fontSize: 15, color: AppColors.success.withAlpha(180))),
|
|
],
|
|
if (report.severity != null) ...[
|
|
const SizedBox(height: 8),
|
|
_severityBadge(report.severity!),
|
|
],
|
|
if (report.doctorComment != null && report.doctorComment!.isNotEmpty) ...[
|
|
const SizedBox(height: 10),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(color: AppTheme.surface, borderRadius: BorderRadius.circular(AppTheme.rSm)),
|
|
child: Text('💬 ${report.doctorComment!}',
|
|
style: TextStyle(fontSize: 18, color: AppColors.textPrimary, height: 1.5)),
|
|
),
|
|
],
|
|
if (report.doctorRecommendation != null && report.doctorRecommendation!.isNotEmpty) ...[
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(color: AppTheme.surface, borderRadius: BorderRadius.circular(AppTheme.rSm)),
|
|
child: Text('📝 ${report.doctorRecommendation!}',
|
|
style: TextStyle(fontSize: 17, color: AppColors.textPrimary, height: 1.5)),
|
|
),
|
|
],
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _severityBadge(String severity) {
|
|
final (label, color, bg) = switch (severity) {
|
|
'Normal' => ('🟢 正常', AppTheme.success, AppColors.successLight),
|
|
'Abnormal' => ('🟡 轻度异常', AppColors.warning, AppColors.warningLight),
|
|
'Severe' => ('🟠 中度异常', AppColors.error, AppColors.errorLight),
|
|
'Critical' => ('🔴 重度异常', AppColors.error, AppColors.errorLight),
|
|
_ => (severity, AppColors.textHint, AppColors.borderLight),
|
|
};
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(6)),
|
|
child: Text(label, style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: color)),
|
|
);
|
|
}
|
|
}
|