fix: VLM识别修复 + 饮食CRUD + 侧边栏美化 + UI优化
- VLM: ChatMessage.Content string→object, 修复视觉content双重序列化 - 饮食: diet/medication端点 record→手动JSON解析, 修复循环引用 - 饮食记录: 左滑删除 + 去评分 + AI饮食评语(DeepSeek) - 侧边栏: 功能区统一Row+Expanded, 服务包compact模式 - 历史对话: 点击加载历史消息 - 登录页: 居中布局, 去底部空白 - UI: 主色加深#6C5CE7, maxWidth:1024防图片超大
This commit is contained in:
@@ -82,7 +82,7 @@ final conversationListProvider = FutureProvider<List<ConversationItem>>((ref) as
|
||||
if (token == null) return [];
|
||||
|
||||
try {
|
||||
final res = await api.get('/api/conversations');
|
||||
final res = await api.get('/api/ai/conversations');
|
||||
final list = res.data['data'] as List? ?? [];
|
||||
return list.map((item) {
|
||||
final data = item as Map<String, dynamic>;
|
||||
@@ -177,6 +177,36 @@ class ChatNotifier extends Notifier<ChatState> {
|
||||
state = state.copyWith(activeAgent: a);
|
||||
}
|
||||
|
||||
Future<void> loadConversation(String convId) async {
|
||||
_subscription?.cancel();
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
final res = await api.get('/api/ai/conversations/$convId');
|
||||
final rawMessages = (res.data['data'] as List?) ?? [];
|
||||
final messages = rawMessages.map((m) {
|
||||
final map = m as Map<String, dynamic>;
|
||||
return ChatMessage(
|
||||
id: map['id']?.toString() ?? '',
|
||||
role: map['role']?.toString() ?? 'user',
|
||||
content: map['content']?.toString() ?? '',
|
||||
createdAt: DateTime.tryParse(map['createdAt']?.toString() ?? '') ?? DateTime.now(),
|
||||
type: MessageType.text,
|
||||
);
|
||||
}).toList();
|
||||
|
||||
// 从对话列表中找到对应的 agent 类型
|
||||
final convList = ref.read(conversationListProvider).value ?? [];
|
||||
final conv = convList.firstWhere((c) => c.id == convId, orElse: () => ConversationItem(id: convId, title: '', lastMessage: '', updatedAt: DateTime.now(), agent: ActiveAgent.default_));
|
||||
|
||||
state = state.copyWith(
|
||||
messages: messages,
|
||||
conversationId: convId,
|
||||
activeAgent: conv.agent,
|
||||
);
|
||||
ref.read(selectedAgentProvider.notifier).select(conv.agent);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
void insertAgentWelcome(ActiveAgent agent) {
|
||||
state = state.copyWith(messages: [...state.messages, ChatMessage(
|
||||
id: 'welcome_${agent.name}_${DateTime.now().millisecondsSinceEpoch}',
|
||||
|
||||
Reference in New Issue
Block a user