blob: 13e5baef3e4267ccd6ed6ae142c625d7627558ff [file] [log] [blame]
崔向南464e19d2025-06-05 17:46:27 +08001// @ts-ignore
meisiyu1d4aade2025-06-02 20:10:36 +08002import { request } from '@umijs/max';
3
4export interface PostListParams {
5 pageNum?: number;
6 pageSize?: number;
7 title?: string;
8 status?: string;
9 tags?: string;
10}
11
12export interface PostDetailResponse {
13 post: API.Post.PostInfo;
14 tags: API.Post.PostTag[];
15 comments: any[];
16 authorPosts: API.Post.PostInfo[];
17 similarPosts: API.Post.PostInfo[];
18 recommendedPosts: API.Post.PostInfo[];
19 favorited: boolean;
20}
21
22export interface CommentAddParams {
23 postId: number;
24 content: string;
25 parentId?: number;
26}
27
28// 获取帖子列表
29export async function getPostList(params: PostListParams) {
崔向南464e19d2025-06-05 17:46:27 +080030 console.log('getPostList', params);
meisiyu1d4aade2025-06-02 20:10:36 +080031 return request<API.TableDataInfo>('/api/post-center/list', {
32 method: 'GET',
33 params,
34 });
35}
36
37// 获取帖子详情
38export async function getPostDetail(postId: number) {
39 console.log('getPostDetail', postId);
40 return request<API.AjaxResult<PostDetailResponse>>(`/api/post-center/${postId}`, {
41 method: 'GET',
42 });
43}
44
45// 添加评论
46export async function addComment(data: CommentAddParams) {
47 console.log('addComment', data);
48 return request<API.AjaxResult>('/api/post-center/comment', {
49 method: 'POST',
50 data,
51 });
52}
53
54// 收藏/取消收藏帖子
55export async function toggleFavorite(postId: number, favorite: boolean) {
56 console.log('toggleFavorite', postId, favorite);
57 return request<API.AjaxResult>(`/api/post-center/favorite/${postId}`, {
58 method: 'POST',
59 params: { favorite },
60 });
61}
62
63// 获取热门标签
64export async function getHotTags(): Promise<API.AjaxResult<API.Post.PostTag[]>> {
65 return request('/api/post-center/tags/hot', {
66 method: 'GET',
67 });
68}
69
70// 根据标签获取帖子
71export async function getPostsByTag(tagId: number) {
72 console.log('getPostsByTag', tagId);
73 return request<API.TableDataInfo>(`/api/post-center/bytag/${tagId}`, {
74 method: 'GET',
75 });
76}
77
78// 发布帖子
79export async function publishPost(data: {
80 title: string;
81 content: string;
82 summary: string;
83 tags: string;
84 promotionPlan?: number;
85}): Promise<API.AjaxResult> {
86 return request('/api/post-center/publish', {
87 method: 'POST',
88 data,
89 });
90}
91
92// 获取我的帖子列表
93export async function getMyPosts(params: {
94 pageNum?: number;
95 pageSize?: number;
96}): Promise<API.TableDataInfo<API.Post.PostInfo>> {
97 return request('/api/post-center/my-posts', {
98 method: 'GET',
99 params,
100 });
101}
102
103// 获取我的收藏列表
104export async function getMyFavorites(params: {
105 pageNum?: number;
106 pageSize?: number;
107}): Promise<API.TableDataInfo<API.Post.PostInfo>> {
108 return request('/api/post-center/my-favorites', {
109 method: 'GET',
110 params,
111 });
112}
113
114// 更新帖子
115export async function updatePost(data: API.Post.PostInfo): Promise<API.AjaxResult> {
116 return request('/api/post-center/update', {
117 method: 'PUT',
118 data,
119 });
120}
121
122// 删除帖子
123export async function deletePost(postId: number): Promise<API.AjaxResult> {
124 return request(`/api/post-center/delete/${postId}`, {
125 method: 'DELETE',
126 });
127}
128
129// 获取可用标签列表(用于下拉选择)
130export async function getAvailableTags(): Promise<API.AjaxResult<API.Post.PostTag[]>> {
131 return request('/api/post-center/tags/available', {
132 method: 'GET',
133 });
134}
135
136// 上传图片
137export async function uploadImage(file: FormData): Promise<API.AjaxResult<{url: string}>> {
138 return request('/api/post-center/upload', {
139 method: 'POST',
140 data: file,
141 });
崔向南464e19d2025-06-05 17:46:27 +0800142}
meisiyu1d4aade2025-06-02 20:10:36 +0800143
144// 删除图片
145export async function deleteImage(filename: string): Promise<API.AjaxResult> {
146 return request('/api/post-center/upload', {
147 method: 'DELETE',
148 params: { filename },
149 });
150}
151
152// 获取推广计划列表
153export async function getPromotionPlans(): Promise<API.AjaxResult<any[]>> {
154 return request('/api/post-center/promotion-plans', {
155 method: 'GET',
156 });
157}
158
159// 创建支付记录
160export async function createPayment(data: {
161 postId: number;
162 planId: number;
163 amount: number;
164}): Promise<API.AjaxResult> {
165 return request('/api/post-center/payment', {
166 method: 'POST',
167 data,
168 });
169}
170
171// 点赞/取消点赞帖子
172export async function toggleLike(postId: number, like: boolean) {
173 console.log('toggleLike', postId, like);
174 return request<API.AjaxResult>(`/api/post-center/like/${postId}`, {
175 method: 'POST',
176 params: { like },
177 });
178}
179
180// 获取推广帖子列表(用于轮播展示)
181export async function getPromotionPosts(): Promise<API.AjaxResult<API.Post.PostInfo[]>> {
182 return request('/api/post-center/promotion', {
183 method: 'GET',
184 });
185}
186
187// 点赞/取消点赞评论
188export async function toggleCommentLike(commentId: number, like: boolean) {
189 console.log('toggleCommentLike', commentId, like);
190 return request<API.AjaxResult>(`/api/post-center/comment/like/${commentId}`, {
191 method: 'POST',
192 params: { like },
193 });
194}
195
196// 获取待审核帖子列表
197export async function getReviewPosts(params: PostListParams): Promise<API.TableDataInfo<API.Post.PostInfo>> {
198 return request('/api/post/review/list', {
199 method: 'GET',
200 params,
201 });
202}
203
204// 审核帖子(通过/拒绝)
205export async function reviewPost(postId: number, action: 'approve' | 'reject', reason?: string): Promise<API.AjaxResult> {
206 return request(`/api/post/review/${postId}`, {
207 method: 'PUT',
208 data: { action, reason },
209 });
210}
211
212// 强制下架帖子
213export async function takeDownPost(postId: number, reason?: string): Promise<API.AjaxResult> {
214 return request(`/api/post/takedown/${postId}`, {
215 method: 'PUT',
216 data: { reason },
217 });
218}
219
220// 检查帖子推广状态
221export async function getPromotionStatus(postId: number): Promise<API.AjaxResult> {
222 return request(`/api/post-center/promotion-status/${postId}`, {
223 method: 'GET',
224 });
225}
226
227// 确认支付成功
228export async function confirmPayment(paymentId: number): Promise<API.AjaxResult> {
229 return request(`/api/post-center/payment/confirm/${paymentId}`, {
230 method: 'POST',
231 });
232}
233
234// 取消支付
235export async function cancelPayment(paymentId: number): Promise<API.AjaxResult> {
236 return request(`/api/post-center/payment/cancel/${paymentId}`, {
237 method: 'POST',
238 });
239}
240
241// 举报帖子
242export async function reportPost(postId: number, reason: string): Promise<API.AjaxResult> {
243 return request(`/api/post-center/report/${postId}`, {
244 method: 'POST',
245 data: { reason },
246 });
247}
248
249// 获取举报列表
250export async function getReportList(params: PostListParams): Promise<API.TableDataInfo> {
251 return request('/api/post/report/list', {
252 method: 'GET',
253 params,
254 });
255}
256
257// 处理举报
258export async function handleReport(reportId: number, action: 'approve' | 'reject', postId: number, reason?: string): Promise<API.AjaxResult> {
259 return request(`/api/post/report/handle/${reportId}`, {
260 method: 'PUT',
261 data: { action, postId, reason },
262 });
崔向南464e19d2025-06-05 17:46:27 +0800263}