feat: AI 提示词模块化 + AI 同意门控 + AI 草稿存储 + 意图路由 + 医疗引用知识库 + 多页面 UI 优化
- AI 提示词拆分为 markdown 模块(Prompts/global + modules + rag + router) - 新增 AI 同意门控(用户需同意后才能使用 AI 功能) - 新增 AI 录入草稿存储(AiEntryDraftContracts/EfAiEntryDraftStore/AiEntryDraftRecord) - 新增 AI 意图路由(ai_intent_router) - 新增医疗引用知识库(MedicalCitationKnowledge) - 重构 prompt_manager 和 ai_chat_endpoints - 优化聊天/趋势/档案/抽屉/医生端等多个页面 UI - 新增 agent 插画和趋势指标图标资源 - 删除 HANDOFF-2026-07-17.md
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../core/app_colors.dart';
|
||||
import '../../core/app_design_tokens.dart';
|
||||
@@ -7,12 +11,79 @@ import '../../core/app_module_visuals.dart';
|
||||
import '../../core/app_theme.dart';
|
||||
import '../../core/navigation_provider.dart';
|
||||
import '../../providers/auth_provider.dart';
|
||||
import '../../providers/data_providers.dart';
|
||||
import '../../widgets/app_toast.dart';
|
||||
import '../../widgets/authenticated_network_image.dart';
|
||||
|
||||
class ProfilePage extends ConsumerWidget {
|
||||
class ProfilePage extends ConsumerStatefulWidget {
|
||||
const ProfilePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
ConsumerState<ProfilePage> createState() => _ProfilePageState();
|
||||
}
|
||||
|
||||
class _ProfilePageState extends ConsumerState<ProfilePage> {
|
||||
bool _uploadingAvatar = false;
|
||||
|
||||
Future<void> _changeAvatar() async {
|
||||
final source = await showModalBottomSheet<ImageSource>(
|
||||
context: context,
|
||||
builder: (sheetContext) => SafeArea(
|
||||
child: Wrap(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.photo_library_outlined),
|
||||
title: const Text('从相册选择'),
|
||||
onTap: () => Navigator.pop(sheetContext, ImageSource.gallery),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.camera_alt_outlined),
|
||||
title: const Text('拍照上传'),
|
||||
onTap: () => Navigator.pop(sheetContext, ImageSource.camera),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (source == null || !mounted) return;
|
||||
|
||||
final picked = await ImagePicker().pickImage(
|
||||
source: source,
|
||||
imageQuality: 85,
|
||||
maxWidth: 1200,
|
||||
);
|
||||
if (picked == null || !mounted) return;
|
||||
|
||||
setState(() => _uploadingAvatar = true);
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
final avatarUrl = await api.uploadFile(
|
||||
'/api/files/upload',
|
||||
File(picked.path),
|
||||
);
|
||||
if (avatarUrl == null) throw StateError('上传未返回头像地址');
|
||||
final updatedProfile = await ref
|
||||
.read(userServiceProvider)
|
||||
.updateProfile(avatarUrl: avatarUrl);
|
||||
final savedAvatarUrl = updatedProfile?['avatarUrl']?.toString();
|
||||
if (savedAvatarUrl == null || savedAvatarUrl != avatarUrl) {
|
||||
throw StateError('头像地址未保存到个人资料');
|
||||
}
|
||||
await ref.read(authProvider.notifier).applyProfile(updatedProfile!);
|
||||
if (mounted) {
|
||||
AppToast.show(context, '头像已更新', type: AppToastType.success);
|
||||
}
|
||||
} catch (_) {
|
||||
if (mounted) {
|
||||
AppToast.show(context, '头像上传失败,请稍后重试', type: AppToastType.error);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _uploadingAvatar = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = ref.watch(authProvider.select((state) => state.user));
|
||||
final name = user?.name?.trim().isNotEmpty == true ? user!.name! : '未设置昵称';
|
||||
final phone = user?.phone.trim().isNotEmpty == true
|
||||
@@ -36,8 +107,10 @@ class ProfilePage extends ConsumerWidget {
|
||||
name: name,
|
||||
phone: phone,
|
||||
avatarUrl: user?.avatarUrl,
|
||||
uploading: _uploadingAvatar,
|
||||
onChangeAvatar: _uploadingAvatar ? null : _changeAvatar,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 24),
|
||||
const _SectionTitle('资料管理'),
|
||||
const SizedBox(height: 9),
|
||||
_SettingsGroup(
|
||||
@@ -50,7 +123,7 @@ class ProfilePage extends ConsumerWidget {
|
||||
onTap: () => pushRoute(ref, 'profileEdit'),
|
||||
),
|
||||
_ActionRow(
|
||||
icon: AppModuleVisuals.health.icon,
|
||||
icon: LucideIcons.folderHeart,
|
||||
iconColor: AppModuleVisuals.health.color,
|
||||
title: '健康档案',
|
||||
subtitle: '疾病、手术、过敏和生活习惯',
|
||||
@@ -58,19 +131,25 @@ class ProfilePage extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const _SectionTitle('账号操作'),
|
||||
const SizedBox(height: 9),
|
||||
_SettingsGroup(
|
||||
children: [
|
||||
_ActionRow(
|
||||
icon: Icons.logout_rounded,
|
||||
iconColor: AppColors.textSecondary,
|
||||
title: '退出登录',
|
||||
showChevron: false,
|
||||
onTap: () => _logout(context, ref),
|
||||
const SizedBox(height: 28),
|
||||
SizedBox(
|
||||
height: 52,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => _logout(context, ref),
|
||||
icon: const Icon(Icons.logout_rounded),
|
||||
label: const Text('退出登录'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: AppColors.errorText,
|
||||
side: const BorderSide(color: Color(0xFFFECACA)),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: AppRadius.mdBorder,
|
||||
),
|
||||
textStyle: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -108,59 +187,100 @@ class _AccountSummary extends StatelessWidget {
|
||||
final String name;
|
||||
final String phone;
|
||||
final String? avatarUrl;
|
||||
final bool uploading;
|
||||
final VoidCallback? onChangeAvatar;
|
||||
|
||||
const _AccountSummary({
|
||||
required this.name,
|
||||
required this.phone,
|
||||
required this.avatarUrl,
|
||||
required this.uploading,
|
||||
required this.onChangeAvatar,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Container(
|
||||
padding: const EdgeInsets.all(18),
|
||||
padding: const EdgeInsets.fromLTRB(20, 22, 20, 20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: AppRadius.lgBorder,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: AppModuleVisuals.health.lightColor,
|
||||
borderRadius: AppRadius.lgBorder,
|
||||
),
|
||||
child: avatarUrl?.isNotEmpty == true
|
||||
? Image.network(
|
||||
avatarUrl!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) =>
|
||||
const _AvatarFallback(),
|
||||
)
|
||||
: const _AvatarFallback(),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withValues(alpha: 0.06),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppTextStyles.summaryTitle.copyWith(fontSize: 20),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Container(
|
||||
width: 92,
|
||||
height: 92,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: AppModuleVisuals.health.lightColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(phone, style: AppTextStyles.listSubtitle),
|
||||
const SizedBox(height: 5),
|
||||
const Text(
|
||||
'头像由账号系统统一管理',
|
||||
style: TextStyle(fontSize: 12, color: AppColors.textHint),
|
||||
child: avatarUrl?.isNotEmpty == true
|
||||
? AuthenticatedNetworkImage(
|
||||
imageUrl: avatarUrl!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, _, _) => const _AvatarFallback(),
|
||||
)
|
||||
: const _AvatarFallback(),
|
||||
),
|
||||
Positioned(
|
||||
right: -2,
|
||||
bottom: -2,
|
||||
child: Material(
|
||||
color: AppColors.primary,
|
||||
shape: const CircleBorder(),
|
||||
child: InkWell(
|
||||
onTap: onChangeAvatar,
|
||||
customBorder: const CircleBorder(),
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: Center(
|
||||
child: uploading
|
||||
? const SizedBox(
|
||||
width: 17,
|
||||
height: 17,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.camera_alt_outlined,
|
||||
color: Colors.white,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Text(
|
||||
name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppTextStyles.summaryTitle.copyWith(fontSize: 21),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(phone, style: AppTextStyles.listSubtitle),
|
||||
const SizedBox(height: 12),
|
||||
TextButton.icon(
|
||||
onPressed: onChangeAvatar,
|
||||
icon: const Icon(Icons.edit_outlined, size: 17),
|
||||
label: const Text('更换头像'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -169,19 +289,17 @@ class _AccountSummary extends StatelessWidget {
|
||||
|
||||
class _AvatarFallback extends StatelessWidget {
|
||||
const _AvatarFallback();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Icon(
|
||||
Icons.person_rounded,
|
||||
color: AppModuleVisuals.health.color,
|
||||
size: 34,
|
||||
size: 48,
|
||||
);
|
||||
}
|
||||
|
||||
class _SectionTitle extends StatelessWidget {
|
||||
final String text;
|
||||
const _SectionTitle(this.text);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||
@@ -199,7 +317,6 @@ class _SectionTitle extends StatelessWidget {
|
||||
class _SettingsGroup extends StatelessWidget {
|
||||
final List<Widget> children;
|
||||
const _SettingsGroup({required this.children});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -226,18 +343,14 @@ class _ActionRow extends StatelessWidget {
|
||||
final Color iconColor;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final bool showChevron;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _ActionRow({
|
||||
required this.icon,
|
||||
required this.iconColor,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
this.showChevron = true,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Material(
|
||||
color: Colors.transparent,
|
||||
@@ -264,7 +377,7 @@ class _ActionRow extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
@@ -277,11 +390,7 @@ class _ActionRow extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (showChevron)
|
||||
const Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
const Icon(Icons.chevron_right_rounded, color: AppColors.textHint),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user