feat: AI 意图路由/草稿存储 + Prompts 模块化 + UI 视觉统一 + AI 同意门 + 资源更新

后端:
- 新增 ai_intent_router 意图路由
- 新增 AiEntryDraft 草稿存储 + EF 迁移
- 新增 Prompts 模块化(global/modules/rag/router)
- AI Agent handlers 扩展

前端:
- 新增 AI 同意门 (ai_consent_gate/provider/details_page)
- HealthMetricVisuals 视觉统一
- 设备扫描/管理页面优化
- agent 插图替换 + 趋势指标图标

配置:
- DeepSeek 模型改 deepseek-v4-flash
- .gitignore 加 artifacts/audit
- build.gradle.kts 签名配置调整
This commit is contained in:
MingNian
2026-07-28 15:03:38 +08:00
parent 25a4078688
commit b4bc15b9b9
88 changed files with 5527 additions and 1240 deletions

View File

@@ -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),
],
),
),