feat: 重构评论功能,支持删除和点赞,更新国际化文本,优化组件结构

This commit is contained in:
2025-09-09 20:11:31 +08:00
parent dd7641bf6e
commit ad9dfb0c4c
15 changed files with 504 additions and 85 deletions

View File

@ -1,15 +1,33 @@
import axiosClient from './client'
import { CreateCommentRequest, UpdateCommentRequest, Comment } from '@/models/comment'
import type { PaginationParams } from '@/models/common'
import { UpdateCommentRequest, Comment } from '@/models/comment'
import { PaginationParams } from '@/models/common'
import { OrderBy } from '@/models/common'
import type { BaseResponse } from '@/models/resp'
import { TargetType } from '@/models/types'
export async function createComment(
data: CreateCommentRequest,
{
targetType,
targetId,
content,
replyId = null,
isPrivate = false
}: {
targetType: TargetType
targetId: number
content: string
replyId: number | null
isPrivate: boolean
}
): Promise<BaseResponse<Comment>> {
const res = await axiosClient.post<BaseResponse<Comment>>('/comment/c', data)
const res = await axiosClient.post<BaseResponse<Comment>>('/comment/c', {
targetType,
targetId,
content,
replyId,
isPrivate
})
return res.data
}
@ -24,28 +42,23 @@ export async function deleteComment(id: number): Promise<void> {
await axiosClient.delete(`/comment/c/${id}`)
}
export interface ListCommentsParams {
export async function listComments({
targetType,
targetId,
depth = 0,
commentId = 0,
orderBy = OrderBy.CreatedAt,
desc = true,
page = 1,
size = 10,
}: {
targetType: TargetType
targetId: number
depth?: number
orderBy?: OrderBy
desc?: boolean
page?: number
size?: number
commentId?: number
}
export async function listComments(params: ListCommentsParams): Promise<BaseResponse<Comment[]>> {
const {
targetType,
targetId,
depth = 0,
orderBy = OrderBy.CreatedAt,
desc = true,
page = 1,
size = 10,
commentId = 0,
} = params
depth: number
commentId: number
} & PaginationParams
) {
const res = await axiosClient.get<BaseResponse<Comment[]>>(`/comment/list`, {
params: {
targetType,