优化页面、修复BUG
This commit is contained in:
@@ -166,6 +166,7 @@ export interface Post {
|
||||
content?: string
|
||||
isPublished?: number
|
||||
readCount?: number
|
||||
snippets?: SnippetBrief[]
|
||||
}
|
||||
|
||||
export interface PostHistory {
|
||||
@@ -255,9 +256,22 @@ export const deleteCodeType = async (id: number): Promise<void> => {
|
||||
await parseApiResponse(response)
|
||||
}
|
||||
|
||||
// 文章/代码片段简要类型
|
||||
export interface PostBrief {
|
||||
id: number
|
||||
title: string
|
||||
}
|
||||
|
||||
export interface SnippetBrief {
|
||||
id: number
|
||||
title: string
|
||||
type: string
|
||||
codeType?: CodeType
|
||||
}
|
||||
|
||||
// 代码片段相关类型
|
||||
export interface Snippet {
|
||||
id: string
|
||||
id: number
|
||||
title: string
|
||||
code: string
|
||||
type: string
|
||||
@@ -265,6 +279,7 @@ export interface Snippet {
|
||||
codeType?: CodeType
|
||||
description?: string
|
||||
viewCount?: number
|
||||
posts?: PostBrief[]
|
||||
}
|
||||
|
||||
// 系统配置相关类型
|
||||
@@ -1075,14 +1090,14 @@ export const fetchSnippets = async (): Promise<Snippet[]> => {
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchSnippet = async (id: string): Promise<Snippet> => {
|
||||
export const fetchSnippet = async (id: number | string): Promise<Snippet> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/snippets/${id}`)
|
||||
return await parseApiResponse(response)
|
||||
} catch (error) {
|
||||
console.error(`Error fetching snippet ${id}:`, error)
|
||||
return {
|
||||
id: id,
|
||||
id: typeof id === 'number' ? id : 0,
|
||||
title: '默认代码片段',
|
||||
code: 'console.log("Hello World");',
|
||||
type: 'js'
|
||||
@@ -1090,21 +1105,22 @@ export const fetchSnippet = async (id: string): Promise<Snippet> => {
|
||||
}
|
||||
}
|
||||
|
||||
export const createSnippet = async (snippetData: Omit<Snippet, 'id' | 'viewCount' | 'codeType' | 'type'> & { type?: string }): Promise<void> => {
|
||||
export const createSnippet = async (snippetData: Omit<Snippet, 'id' | 'viewCount' | 'codeType' | 'type' | 'posts'> & { type?: string; postIds?: number[] }): Promise<{ id: number }> => {
|
||||
try {
|
||||
const response = await authFetch(`${API_BASE}/admin/snippets`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
body: JSON.stringify(snippetData)
|
||||
})
|
||||
await parseApiResponse(response)
|
||||
const data = await parseApiResponse<{ id: number }>(response)
|
||||
return data || { id: 0 }
|
||||
} catch (error) {
|
||||
console.error('Create snippet error:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const updateSnippet = async (id: string, snippetData: Omit<Snippet, 'id' | 'viewCount' | 'codeType' | 'type'> & { type?: string }): Promise<void> => {
|
||||
export const updateSnippet = async (id: number | string, snippetData: Omit<Snippet, 'id' | 'viewCount' | 'codeType' | 'type' | 'posts'> & { type?: string; postIds?: number[] }): Promise<void> => {
|
||||
try {
|
||||
const response = await authFetch(`${API_BASE}/admin/snippets/${id}`, {
|
||||
method: 'PUT',
|
||||
@@ -1118,7 +1134,7 @@ export const updateSnippet = async (id: string, snippetData: Omit<Snippet, 'id'
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteSnippet = async (id: string): Promise<void> => {
|
||||
export const deleteSnippet = async (id: number | string): Promise<void> => {
|
||||
try {
|
||||
const response = await authFetch(`${API_BASE}/admin/snippets/${id}`, {
|
||||
method: 'DELETE',
|
||||
|
||||
Reference in New Issue
Block a user