feat: 添加举报功能前端支持
- 新增 reportService API 服务 - 新增 ReportDialog 举报对话框组件 - 集成举报入口到 PostCard、CommentItem、LongPressMenu Made-with: Cursor
This commit is contained in:
83
src/services/reportService.ts
Normal file
83
src/services/reportService.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* 举报服务
|
||||
* 处理帖子、评论、消息的举报功能
|
||||
*/
|
||||
|
||||
import { api } from './api';
|
||||
|
||||
// 举报原因类型
|
||||
export type ReportReason = 'spam' | 'inappropriate' | 'harassment' | 'misinformation' | 'other';
|
||||
|
||||
// 举报目标类型
|
||||
export type ReportTargetType = 'post' | 'comment' | 'message';
|
||||
|
||||
// 创建举报请求
|
||||
interface CreateReportRequest {
|
||||
target_type: ReportTargetType;
|
||||
target_id: string;
|
||||
reason: ReportReason;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
// 举报响应
|
||||
export interface ReportResponse {
|
||||
id: string;
|
||||
reporter_id: string;
|
||||
target_type: ReportTargetType;
|
||||
target_id: string;
|
||||
reason: ReportReason;
|
||||
description?: string;
|
||||
status: 'pending' | 'processing' | 'resolved' | 'rejected';
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
// 举报原因选项
|
||||
export const REPORT_REASONS: { value: ReportReason; label: string }[] = [
|
||||
{ value: 'spam', label: '垃圾广告' },
|
||||
{ value: 'inappropriate', label: '违规内容' },
|
||||
{ value: 'harassment', label: '辱骂/攻击' },
|
||||
{ value: 'misinformation', label: '虚假信息' },
|
||||
{ value: 'other', label: '其他' },
|
||||
];
|
||||
|
||||
// 举报服务类
|
||||
class ReportService {
|
||||
/**
|
||||
* 创建举报
|
||||
* @param targetType 举报目标类型
|
||||
* @param targetId 目标ID
|
||||
* @param reason 举报原因
|
||||
* @param description 详细描述(可选)
|
||||
*/
|
||||
async createReport(
|
||||
targetType: ReportTargetType,
|
||||
targetId: string,
|
||||
reason: ReportReason,
|
||||
description?: string
|
||||
): Promise<ReportResponse | null> {
|
||||
try {
|
||||
const request: CreateReportRequest = {
|
||||
target_type: targetType,
|
||||
target_id: targetId,
|
||||
reason,
|
||||
description,
|
||||
};
|
||||
const response = await api.post<ReportResponse>('/reports', request);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('创建举报失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取举报原因标签
|
||||
*/
|
||||
getReasonLabel(reason: ReportReason): string {
|
||||
const item = REPORT_REASONS.find(r => r.value === reason);
|
||||
return item?.label ?? reason;
|
||||
}
|
||||
}
|
||||
|
||||
export const reportService = new ReportService();
|
||||
export default reportService;
|
||||
Reference in New Issue
Block a user