You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.0 KiB
80 lines
2.0 KiB
import 'package:get/get.dart';
|
|
//import 'agent_controller.dart'; // 确保导入Message模型
|
|
import 'package:flutter/material.dart';
|
|
import '../../../data/services/network/api.dart';
|
|
import '../../../data/models/message_model.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),
|
|
);
|
|
}
|
|
}
|
|
|