mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 19:16:24 +00:00
✨ feat: 添加评论功能,包括评论输入、评论列表和评论项组件,支持层级深度和私密评论
This commit is contained in:
41
web/src/api/comment.ts
Normal file
41
web/src/api/comment.ts
Normal 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
|
||||
}
|
@ -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 {
|
||||
|
@ -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 }>> {
|
||||
|
Reference in New Issue
Block a user