Browse Source

feat(举报): 添加AI内容举报功能

- 在API服务中添加举报接口
- 创建ReportController处理举报逻辑
- 重构举报表单为独立组件
- 实现举报原因选择和提交功能
newdev_shunjiawei
lxm 1 year ago
parent
commit
ee6babf4aa
  1. 9
      lib/data/services/network/api.dart
  2. 4
      lib/modules/agent/bindings/agent_binding.dart
  3. 74
      lib/modules/agent/controllers/report_controller.dart
  4. 460
      lib/modules/agent/views/agent_view.dart

9
lib/data/services/network/api.dart

@ -89,4 +89,13 @@ class Api {
params: params,
);
}
//举报AI内容
static reportAiContext([params]) {
return DioManager().request(
NWMethod.post,
'/api/home/user_reportaicontext',
params: params,
);
}
}

4
lib/modules/agent/bindings/agent_binding.dart

@ -1,9 +1,11 @@
import 'package:get/get.dart';
import '../controllers/agent_controller.dart';
import '../controllers/report_controller.dart';
class AgentBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<AgentController>(() => AgentController());
Get.lazyPut<ReportController>(() => ReportController());
}
}
}

74
lib/modules/agent/controllers/report_controller.dart

@ -0,0 +1,74 @@
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': reportingMessage.value,
'reportContext': reportingMessage.value,
'reporttype': selectedReasons.toList(),
};
print('提交举报数据: ${reportData}');
//调用API提交举报:
final Response = Api.reportAiContext(reportData);
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),
);
}
}

460
lib/modules/agent/views/agent_view.dart

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/agent_controller.dart';
import '../controllers/report_controller.dart';
import 'message_bubble.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -609,163 +610,187 @@ class AgentView extends StatelessWidget {
isDarkMode ? Colors.red[700]! : Colors.red,
() {
// 实现举报功能
showModalBottomSheet(
context: context,
isScrollControlled: true, // 关键:允许弹窗随键盘移动
backgroundColor:
isDarkMode ? AppColors.cardBackground : Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16.r)),
),
builder: (BuildContext context) {
return Padding(
// 添加底部内边距以容纳键盘
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: Container(
padding: EdgeInsets.all(16.w),
child: SingleChildScrollView(
// 添加滚动视图
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Stack(
alignment: Alignment.center,
children: [
Center(
child: Text(
'举报',
style: TextStyle(
fontSize: 18.sp,
fontWeight: FontWeight.bold,
color: isDarkMode
? Colors.white
: Colors.black,
),
),
),
SizedBox(
height: 20.w,
),
Positioned(
right: 0,
child: IconButton(
icon: Icon(
Icons.close,
color: isDarkMode
? Colors.grey[400]
: Colors.black54,
),
onPressed: () => Navigator.pop(context),
),
),
],
),
Container(
padding: EdgeInsets.symmetric(horizontal: 12.w),
margin: EdgeInsets.only(bottom: 10.w),
child: Divider(
height: 1,
color: Colors.grey[300],
),
),
Wrap(
spacing: 8.w,
runSpacing: 8.h,
children: [
_buildReportChip('有害/不安全', isDarkMode),
_buildReportChip('色情低俗', isDarkMode),
_buildReportChip('误导攻击', isDarkMode),
_buildReportChip('违法犯罪', isDarkMode),
_buildReportChip('隐私相关', isDarkMode),
_buildReportChip('侵犯我的著作权、名誉权等', isDarkMode),
_buildReportChip('其他', isDarkMode),
],
),
SizedBox(height: 16.h),
Container(
padding: EdgeInsets.all(12.w),
decoration: BoxDecoration(
color: isDarkMode
? Colors.grey[800]
: Colors.grey[200],
borderRadius: BorderRadius.circular(8.r),
),
child: TextField(
maxLines: 3,
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black,
),
decoration: InputDecoration(
hintText: '我们想知道你举报的原因,你可以描述你遇到的问题。',
hintStyle: TextStyle(
color: isDarkMode
? Colors.white70
: Colors.black54,
fontSize: 14.sp,
),
border: InputBorder.none,
),
),
),
SizedBox(height: 14.h),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(vertical: 12.h),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.r),
),
),
child: Text('提交'),
onPressed: () {
Navigator.pop(context);
Get.snackbar(
'提示',
'举报已提交,我们会尽快处理',
backgroundColor: Colors.green.withOpacity(0.8),
colorText: Colors.white,
);
},
),
SizedBox(height: 8.h),
],
),
),
),
);
},
);
final reportController = Get.find<ReportController>();
reportController.initReport(message);
_showReportForm(context, isDarkMode);
// showModalBottomSheet(
// context: context,
// isScrollControlled: true, // 关键:允许弹窗随键盘移动
// backgroundColor:
// isDarkMode ? AppColors.cardBackground : Colors.white,
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.vertical(top: Radius.circular(16.r)),
// ),
// builder: (BuildContext context) {
// return Padding(
// // 添加底部内边距以容纳键盘
// padding: EdgeInsets.only(
// bottom: MediaQuery.of(context).viewInsets.bottom,
// ),
// child: Container(
// padding: EdgeInsets.all(16.w),
// child: SingleChildScrollView(
// // 添加滚动视图
// child: Column(
// mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.stretch,
// children: [
// Stack(
// alignment: Alignment.center,
// children: [
// Center(
// child: Text(
// '举报',
// style: TextStyle(
// fontSize: 18.sp,
// fontWeight: FontWeight.bold,
// color: isDarkMode
// ? Colors.white
// : Colors.black,
// ),
// ),
// ),
// SizedBox(
// height: 20.w,
// ),
// Positioned(
// right: 0,
// child: IconButton(
// icon: Icon(
// Icons.close,
// color: isDarkMode
// ? Colors.grey[400]
// : Colors.black54,
// ),
// onPressed: () => Navigator.pop(context),
// ),
// ),
// ],
// ),
// Container(
// padding: EdgeInsets.symmetric(horizontal: 12.w),
// margin: EdgeInsets.only(bottom: 10.w),
// child: Divider(
// height: 1,
// color: Colors.grey[300],
// ),
// ),
// Wrap(
// spacing: 8.w,
// runSpacing: 8.h,
// children: [
// _buildReportChip('有害/不安全', isDarkMode),
// _buildReportChip('色情低俗', isDarkMode),
// _buildReportChip('误导攻击', isDarkMode),
// _buildReportChip('违法犯罪', isDarkMode),
// _buildReportChip('隐私相关', isDarkMode),
// _buildReportChip('侵犯我的著作权、名誉权等', isDarkMode),
// _buildReportChip('其他', isDarkMode),
// ],
// ),
// SizedBox(height: 16.h),
// Container(
// padding: EdgeInsets.all(12.w),
// decoration: BoxDecoration(
// color: isDarkMode
// ? Colors.grey[800]
// : Colors.grey[200],
// borderRadius: BorderRadius.circular(8.r),
// ),
// child: TextField(
// maxLines: 3,
// style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black,
// ),
// decoration: InputDecoration(
// hintText: '我们想知道你举报的原因,你可以描述你遇到的问题。',
// hintStyle: TextStyle(
// color: isDarkMode
// ? Colors.white70
// : Colors.black54,
// fontSize: 14.sp,
// ),
// border: InputBorder.none,
// ),
// ),
// ),
// SizedBox(height: 14.h),
// ElevatedButton(
// style: ElevatedButton.styleFrom(
// backgroundColor: Colors.blue,
// foregroundColor: Colors.white,
// padding: EdgeInsets.symmetric(vertical: 12.h),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(8.r),
// ),
// ),
// child: Text('提交'),
// onPressed: () {
// Navigator.pop(context);
// Get.snackbar(
// '提示',
// '举报已提交,我们会尽快处理',
// backgroundColor: Colors.green.withOpacity(0.8),
// colorText: Colors.white,
// );
// },
// ),
// SizedBox(height: 8.h),
// ],
// ),
// ),
// ),
// );
// },
// );
},
),
],
);
}
// 添加这个辅助方法来创建举报选项
Widget _buildReportChip(String label, bool isDarkMode) {
return ChoiceChip(
label: Text(
label,
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black87,
fontSize: 14.sp,
),
),
selected: false,
backgroundColor: isDarkMode ? Colors.grey[800] : Colors.grey[200],
// 更新_showReportForm方法
void _showReportForm(BuildContext context, bool isDarkMode) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: isDarkMode ? AppColors.cardBackground : Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.r),
borderRadius: BorderRadius.vertical(top: Radius.circular(16.r)),
),
onSelected: (bool selected) {
// 可以在这里处理选择逻辑
builder: (BuildContext context) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: _ReportForm(isDarkMode: isDarkMode),
);
},
);
}
// // 添加这个辅助方法来创建举报选项
// Widget _buildReportChip(String label, bool isDarkMode) {
// return ChoiceChip(
// label: Text(
// label,
// style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black87,
// fontSize: 14.sp,
// ),
// ),
// selected: false,
// backgroundColor: isDarkMode ? Colors.grey[800] : Colors.grey[200],
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(16.r),
// ),
// onSelected: (bool selected) {
// // 可以在这里处理选择逻辑
// },
// );
// }
PopupMenuEntry _popupMenuEntry(
Icon icon,
String title,
@ -838,6 +863,151 @@ class AgentView extends StatelessWidget {
}
}
class _ReportForm extends StatelessWidget {
final bool isDarkMode;
final ReportController reportController = Get.find<ReportController>();
_ReportForm({required this.isDarkMode});
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(16.w),
child: SingleChildScrollView(
child: GetBuilder<ReportController>(
builder: (_) => Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Stack(
alignment: Alignment.center,
children: [
Center(
child: Text(
'举报',
style: TextStyle(
fontSize: 18.sp,
fontWeight: FontWeight.bold,
color: isDarkMode ? Colors.white : Colors.black,
),
),
),
Positioned(
right: 0,
child: IconButton(
icon: Icon(
Icons.close,
color: isDarkMode ? Colors.grey[400] : Colors.black54,
),
onPressed: () => Navigator.pop(context),
),
),
],
),
Container(
padding: EdgeInsets.symmetric(horizontal: 12.w),
margin: EdgeInsets.only(bottom: 10.w),
child: Divider(
height: 1,
color: Colors.grey[300],
),
),
GetBuilder<ReportController>(
builder: (controller) {
return Wrap(
spacing: 8.w,
runSpacing: 8.h,
children: [
_buildReportChip('有害/不安全', isDarkMode, controller),
_buildReportChip('色情低俗', isDarkMode, controller),
_buildReportChip('误导攻击', isDarkMode, controller),
_buildReportChip('违法犯罪', isDarkMode, controller),
_buildReportChip('隐私相关', isDarkMode, controller),
_buildReportChip('侵犯我的著作权、名誉权等', isDarkMode, controller),
_buildReportChip('其他', isDarkMode, controller),
],
);
},
),
SizedBox(height: 16.h),
Container(
padding: EdgeInsets.all(12.w),
decoration: BoxDecoration(
color: isDarkMode ? Colors.grey[800] : Colors.grey[200],
borderRadius: BorderRadius.circular(8.r),
),
child: TextField(
maxLines: 3,
onChanged: reportController.updateDescription,
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black,
),
decoration: InputDecoration(
hintText: '我们想知道你举报的原因,你可以描述你遇到的问题。',
hintStyle: TextStyle(
color: isDarkMode ? Colors.white70 : Colors.black54,
fontSize: 14.sp,
),
border: InputBorder.none,
),
),
),
SizedBox(height: 14.h),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(vertical: 12.h),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.r),
),
),
child: Text('提交'),
onPressed: () => reportController.submitReport(),
),
SizedBox(height: 8.h),
],
),
),
),
);
}
Widget _buildReportChip(
String label, bool isDarkMode, ReportController controller) {
final isSelected = reportController.selectedReasons.contains(label);
return GestureDetector(
onTap: () => reportController.toggleReason(label),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.h),
decoration: BoxDecoration(
color: isSelected
? Colors.red
: (isDarkMode ? Colors.grey[800] : Colors.grey[200]),
borderRadius: BorderRadius.circular(16.r),
border: Border.all(
color: isSelected
? Colors.red[700]!
: (isDarkMode ? Colors.grey[700]! : Colors.grey[300]!),
width: isSelected ? 1.0 : 0.5,
),
),
child: Text(
label,
style: TextStyle(
color: isSelected
? Colors.white
: (isDarkMode ? Colors.white : Colors.black87),
fontSize: 14.sp,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
),
),
);
}
}
// 声音柱动画组件
class _SoundBar extends StatefulWidget {
final double delay;

Loading…
Cancel
Save