feat: 添加评论功能,包括评论输入、评论列表和评论项组件,支持层级深度和私密评论

This commit is contained in:
2025-07-31 08:03:19 +08:00
parent 92c2a58e80
commit 94aa4f1b1f
23 changed files with 303 additions and 53 deletions

41
web/src/api/comment.ts Normal file
View File

@ -0,0 +1,41 @@
import axiosClient from './client'
import { CreateCommentRequest, UpdateCommentRequest, Comment } from '@/models/comment'
import type { PaginationParams } from '@/models/common'
import { OrderBy } from '@/models/common'
import type { BaseResponse } from '@/models/resp'
export async function createComment(
data: CreateCommentRequest,
): Promise<BaseResponse<Comment>> {
const res = await axiosClient.post<BaseResponse<Comment>>('/comment/c', data)
return res.data
}
export async function updateComment(
data: UpdateCommentRequest,
): Promise<BaseResponse<Comment>> {
const res = await axiosClient.put<BaseResponse<Comment>>(`/comment/c/${data.id}`, data)
return res.data
}
export async function deleteComment(id: number): Promise<void> {
await axiosClient.delete(`/comment/c/${id}`)
}
export async function listComments(
targetType: 'post' | 'page',
targetId: number,
pagination: PaginationParams = { orderBy: OrderBy.CreatedAt, desc: false, page: 1, size: 10 },
depth: number = 1
): Promise<BaseResponse<Comment[]>> {
const res = await axiosClient.get<BaseResponse<Comment[]>>(`/comment/list`, {
params: {
targetType,
targetId,
...pagination,
depth
}
})
return res.data
}

View File

@ -1,14 +1,8 @@
import type { Post } from '@/models/post'
import type { BaseResponse } from '@/models/resp'
import axiosClient from './client'
import type { ListPostsParams } from '@/models/post'
interface ListPostsParams {
page?: number
size?: number
orderBy?: string
desc?: boolean
keywords?: string
}
export async function getPostById(id: string, token: string=""): Promise<Post | null> {
try {

View File

@ -1,23 +1,8 @@
import type { OidcConfig } from '@/models/oidc-config'
import type { BaseResponse } from '@/models/resp'
import type { User } from '@/models/user'
import type { LoginRequest, RegisterRequest, User } from '@/models/user'
import axiosClient from './client'
export interface LoginRequest {
username: string
password: string
rememberMe?: boolean // 可以轻松添加新字段
captcha?: string
}
export interface RegisterRequest {
username: string
password: string
nickname: string
email: string
verificationCode?: string
}
export async function userLogin(
data: LoginRequest,
): Promise<BaseResponse<{ token: string, user: User }>> {