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, 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 '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());
} }
} }

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

Loading…
Cancel
Save