7 changed files with 729 additions and 42 deletions
@ -1,58 +1,77 @@ |
|||||
class Message { |
class Message { |
||||
final String role; // 'user' or 'assistant' |
final bool isUser; //标识信息是否来自用户还是AI |
||||
final String content; |
final String text; //信息文本内容 |
||||
final DateTime timestamp; |
final DateTime timestamp; // 消息时间戳 |
||||
final bool isLoading; |
final bool isRecognizing; // 是否为语音识别中的临时消息 |
||||
|
final bool hasImage; // 是否包含图片 |
||||
|
final String? imagePath; // 图片路径 |
||||
|
final Map? meta; //卡片数据 |
||||
|
|
||||
Message({ |
Message({ |
||||
required this.role, |
// 构造函数 |
||||
required this.content, |
required this.isUser, |
||||
required this.timestamp, |
required this.text, |
||||
this.isLoading = false, |
DateTime? timestamp, |
||||
}); |
this.isRecognizing = false, |
||||
|
this.hasImage = false, |
||||
|
this.imagePath, |
||||
|
this.meta, |
||||
|
}) : this.timestamp = timestamp ?? DateTime.now(); |
||||
|
|
||||
// 从JSON构造函数 |
// 从JSON构造函数 |
||||
factory Message.fromJson(Map<String, dynamic> json) { |
factory Message.fromJson(Map<String, dynamic> json) { |
||||
return Message( |
return Message( |
||||
role: json['role'] as String, |
isUser: json['isUser'] as bool, |
||||
content: json['content'] as String, |
text: json['text'] as String, |
||||
timestamp: DateTime.parse(json['timestamp'] as String), |
timestamp: DateTime.parse(json['timestamp'] as String), |
||||
isLoading: json['isLoading'] as bool? ?? false, |
isRecognizing: json['isRecognizing'] as bool? ?? false, |
||||
|
hasImage: json['hasImage'] as bool? ?? false, |
||||
|
imagePath: json['imagePath'] as String?, |
||||
|
meta: json['meta'] as Map?, |
||||
); |
); |
||||
} |
} |
||||
|
|
||||
// 转换为JSON |
// 转换为JSON |
||||
Map<String, dynamic> toJson() { |
Map<String, dynamic> toJson() { |
||||
return { |
return { |
||||
'role': role, |
'isUser': isUser, |
||||
'content': content, |
'text': text, |
||||
'timestamp': timestamp.toIso8601String(), |
'timestamp': timestamp.toIso8601String(), |
||||
'isLoading': isLoading, |
'isRecognizing': isRecognizing, |
||||
|
'hasImage': hasImage, |
||||
|
'imagePath': imagePath, |
||||
|
'meta': meta, |
||||
}; |
}; |
||||
} |
} |
||||
|
|
||||
// 创建一个加载中的消息 |
// 创建一个加载中的消息 |
||||
factory Message.loading() { |
factory Message.loading() { |
||||
return Message( |
return Message( |
||||
role: 'assistant', |
isUser: false, |
||||
content: '', |
text: '', |
||||
timestamp: DateTime.now(), |
timestamp: DateTime.now(), |
||||
isLoading: true, |
isRecognizing: true, |
||||
); |
); |
||||
} |
} |
||||
|
|
||||
// 复制并修改 |
// 复制并修改 |
||||
Message copyWith({ |
Message copyWith({ |
||||
String? role, |
bool? isUser, |
||||
String? content, |
String? text, |
||||
DateTime? timestamp, |
DateTime? timestamp, |
||||
bool? isLoading, |
bool? isRecognizing, |
||||
|
bool? hasImage, |
||||
|
String? imagePath, |
||||
|
Map? meta, |
||||
}) { |
}) { |
||||
return Message( |
return Message( |
||||
role: role ?? this.role, |
isUser: isUser ?? this.isUser, |
||||
content: content ?? this.content, |
text: text ?? this.text, |
||||
timestamp: timestamp ?? this.timestamp, |
timestamp: timestamp ?? this.timestamp, |
||||
isLoading: isLoading ?? this.isLoading, |
isRecognizing: isRecognizing ?? this.isRecognizing, |
||||
|
hasImage: hasImage ?? this.hasImage, |
||||
|
imagePath: imagePath ?? this.imagePath, |
||||
|
meta: meta ?? this.meta, |
||||
); |
); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,9 +1,11 @@ |
|||||
import 'package:get/get.dart'; |
import 'package:get/get.dart'; |
||||
import '../controllers/agent_controller.dart'; |
import '../controllers/agent_controller.dart'; |
||||
|
import '../controllers/report_controller.dart'; |
||||
|
|
||||
class AgentBinding extends Bindings { |
class AgentBinding extends Bindings { |
||||
@override |
@override |
||||
void dependencies() { |
void dependencies() { |
||||
Get.lazyPut<AgentController>(() => AgentController()); |
Get.lazyPut<AgentController>(() => AgentController()); |
||||
|
Get.lazyPut<ReportController>(() => ReportController()); |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
import 'package:get/get.dart'; |
||||
|
import 'agent_controller.dart'; // 确保导入Message模型 |
||||
|
import 'package:flutter/material.dart'; |
||||
|
import '../../../data/services/network/api.dart'; |
||||
|
|
||||
|
class ReportController extends GetxController { |
||||
|
// 当前举报的消息 |
||||
|
final reportingMessage = Rxn<Message>(); |
||||
|
|
||||
|
// 选择的举报原因 |
||||
|
List<String> selectedReasons = []; |
||||
|
|
||||
|
// 举报描述 |
||||
|
final reportDescription = ''.obs; |
||||
|
|
||||
|
// 初始化举报状态 |
||||
|
void initReport(Message message) { |
||||
|
reportingMessage.value = message; |
||||
|
selectedReasons.clear(); |
||||
|
reportDescription.value = ''; |
||||
|
} |
||||
|
|
||||
|
// 切换举报原因选择状态 |
||||
|
void toggleReason(String reason) { |
||||
|
if (selectedReasons.contains(reason)) { |
||||
|
selectedReasons.remove(reason); |
||||
|
} else { |
||||
|
selectedReasons.add(reason); |
||||
|
} |
||||
|
update(); |
||||
|
} |
||||
|
|
||||
|
// 更新举报描述 |
||||
|
void updateDescription(String text) { |
||||
|
reportDescription.value = text; |
||||
|
} |
||||
|
|
||||
|
// 提交举报 |
||||
|
Future<void> submitReport() async { |
||||
|
if (reportingMessage.value == null) return; |
||||
|
|
||||
|
// 构建举报数据 |
||||
|
final reportData = { |
||||
|
'describe': reportDescription.value, |
||||
|
// 将Message对象转换为可序列化的Map |
||||
|
'message': [], |
||||
|
// 同样处理reportContext |
||||
|
'reportContext': reportingMessage.value!.text, |
||||
|
|
||||
|
'reporttype': selectedReasons.toString(), |
||||
|
}; |
||||
|
|
||||
|
print('提交举报数据: ${reportData}'); |
||||
|
|
||||
|
//调用API提交举报: |
||||
|
var response = await Api.reportAiContent(reportData); |
||||
|
|
||||
|
if (response != null) { |
||||
|
print('提交举报响应: $response'); |
||||
|
} |
||||
|
|
||||
|
// 提交成功后重置状态 |
||||
|
selectedReasons.clear(); |
||||
|
reportDescription.value = ''; |
||||
|
reportingMessage.value = null; |
||||
|
|
||||
|
// 关闭举报表单 |
||||
|
Navigator.of(Get.context!).pop(); |
||||
|
|
||||
|
// 显示成功通知 |
||||
|
Get.snackbar( |
||||
|
'提交成功', |
||||
|
'举报已提交,我们会尽快处理', |
||||
|
backgroundColor: Colors.green.withOpacity(0.8), |
||||
|
colorText: Colors.white, |
||||
|
duration: const Duration(seconds: 2), |
||||
|
); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue