update: 更新页面,修复添加资源的问题

This commit is contained in:
ctwj
2025-07-27 01:45:04 +08:00
parent 312ecb041a
commit cf3376eb31
7 changed files with 196 additions and 39 deletions

View File

@@ -18,6 +18,11 @@ export const parseApiResponse = <T>(response: any): T => {
}
}
// 检查是否是包含items字段的响应格式如分类接口
if (response && typeof response === 'object' && 'items' in response) {
return response
}
// 检查是否是包含success字段的响应格式如登录接口
if (response && typeof response === 'object' && 'success' in response && 'data' in response) {
if (response.success) {
@@ -66,7 +71,7 @@ export const useAuthApi = () => {
}
export const useCategoryApi = () => {
const getCategories = () => useApiFetch('/categories').then(parseApiResponse)
const getCategories = (params?: any) => useApiFetch('/categories', { params }).then(parseApiResponse)
const createCategory = (data: any) => useApiFetch('/categories', { method: 'POST', body: data }).then(parseApiResponse)
const updateCategory = (id: number, data: any) => useApiFetch(`/categories/${id}`, { method: 'PUT', body: data }).then(parseApiResponse)
const deleteCategory = (id: number) => useApiFetch(`/categories/${id}`, { method: 'DELETE' }).then(parseApiResponse)
@@ -93,7 +98,7 @@ export const useCksApi = () => {
}
export const useTagApi = () => {
const getTags = () => useApiFetch('/tags').then(parseApiResponse)
const getTags = (params?: any) => useApiFetch('/tags', { params }).then(parseApiResponse)
const getTagsByCategory = (categoryId: number, params?: any) => useApiFetch(`/categories/${categoryId}/tags`, { params }).then(parseApiResponse)
const getTag = (id: number) => useApiFetch(`/tags/${id}`).then(parseApiResponse)
const createTag = (data: any) => useApiFetch('/tags', { method: 'POST', body: data }).then(parseApiResponse)