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