This repository was archived by the owner on May 29, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathposts.ts
More file actions
57 lines (46 loc) · 1.49 KB
/
Copy pathposts.ts
File metadata and controls
57 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type { PaginateResult } from '~/models/base'
import type { PostModel } from '~/models/post'
import { request } from '~/utils/request'
export type PostSortKey = 'createdAt' | 'modifiedAt' | 'pinAt'
export type SortOrder = 'asc' | 'desc'
export interface GetPostsParams {
page?: number
size?: number
sort_by?: PostSortKey
sort_order?: SortOrder
categoryIds?: string[]
}
export interface CreatePostData {
title: string
text: string
categoryId: string
slug?: string
tags?: string[]
summary?: string | null
copyright?: boolean
isPublished?: boolean
pin?: string | null
pinOrder?: number
relatedId?: string[]
meta?: Record<string, unknown>
/** 关联的草稿 ID,发布时传递以标记草稿为已发布 */
draftId?: string
}
export interface UpdatePostData extends Partial<CreatePostData> {}
export const postsApi = {
// 获取文章列表
getList: (params?: GetPostsParams) =>
request.get<PaginateResult<PostModel>>('/posts', { params }),
// 获取单篇文章
getById: (id: string) => request.get<PostModel>(`/posts/${id}`),
// 创建文章
create: (data: CreatePostData) => request.post<PostModel>('/posts', { data }),
// 更新文章
update: (id: string, data: UpdatePostData) =>
request.put<PostModel>(`/posts/${id}`, { data }),
// 删除文章
delete: (id: string) => request.delete<void>(`/posts/${id}`),
// 更新发布状态
patch: (id: string, data: Partial<PostModel>) =>
request.patch<PostModel>(`/posts/${id}`, { data }),
}