feat: 添加举报功能前端支持
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 2m45s
Frontend CI / ota-android (push) Successful in 12m44s
Frontend CI / build-android-apk (push) Successful in 52m27s

- 新增 reportService API 服务
- 新增 ReportDialog 举报对话框组件
- 集成举报入口到 PostCard、CommentItem、LongPressMenu

Made-with: Cursor
This commit is contained in:
lafay
2026-03-29 20:18:49 +08:00
parent 584d98307c
commit e0ee29caf8
7 changed files with 425 additions and 1 deletions

View 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;