feat: 本次提交更新内容如下

场景获客列表搞定
This commit is contained in:
笔记本里的永平
2025-07-07 17:08:27 +08:00
parent 6543da9167
commit 5ff15472f5
352 changed files with 24040 additions and 18575 deletions

View File

@@ -1,125 +1,156 @@
import type { ApiResponse, PaginatedResponse } from "@/types/common"
import type { ContentLibrary, ContentItem } from "@/types/content-library"
// 内容库管理API模块
import { apiClient } from "./client"
const API_BASE = "/api/content"
// 内容库API
export const contentApi = {
// 创建内容库
async createLibrary(data: Partial<ContentLibrary>): Promise<ApiResponse<ContentLibrary>> {
const response = await fetch(`${API_BASE}/libraries`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
return response.json()
},
// 获取内容库列表
async getLibraries(params: {
page?: number
pageSize?: number
search?: string
type?: string
}): Promise<ApiResponse<PaginatedResponse<ContentLibrary>>> {
const queryString = new URLSearchParams()
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== "") {
queryString.append(key, String(value))
}
})
const response = await fetch(`${API_BASE}/libraries?${queryString.toString()}`)
return response.json()
},
// 获取内容库详情
async getLibraryById(id: string): Promise<ApiResponse<ContentLibrary>> {
const response = await fetch(`${API_BASE}/libraries/${id}`)
return response.json()
},
// 更新内容库
async updateLibrary(id: string, data: Partial<ContentLibrary>): Promise<ApiResponse<ContentLibrary>> {
const response = await fetch(`${API_BASE}/libraries/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
return response.json()
},
// 删除内容库
async deleteLibrary(id: string): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/libraries/${id}`, {
method: "DELETE",
})
return response.json()
},
// 创建内容项
async createItem(libraryId: string, data: Partial<ContentItem>): Promise<ApiResponse<ContentItem>> {
const response = await fetch(`${API_BASE}/libraries/${libraryId}/items`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
return response.json()
},
// 获取内容项列表
async getItems(
libraryId: string,
params: {
page?: number
pageSize?: number
search?: string
type?: string
},
): Promise<ApiResponse<PaginatedResponse<ContentItem>>> {
const queryString = new URLSearchParams()
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== "") {
queryString.append(key, String(value))
}
})
const response = await fetch(`${API_BASE}/libraries/${libraryId}/items?${queryString.toString()}`)
return response.json()
},
// 获取内容项详情
async getItemById(libraryId: string, itemId: string): Promise<ApiResponse<ContentItem>> {
const response = await fetch(`${API_BASE}/libraries/${libraryId}/items/${itemId}`)
return response.json()
},
// 更新内容项
async updateItem(libraryId: string, itemId: string, data: Partial<ContentItem>): Promise<ApiResponse<ContentItem>> {
const response = await fetch(`${API_BASE}/libraries/${libraryId}/items/${itemId}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
return response.json()
},
// 删除内容项
async deleteItem(libraryId: string, itemId: string): Promise<ApiResponse<void>> {
const response = await fetch(`${API_BASE}/libraries/${libraryId}/items/${itemId}`, {
method: "DELETE",
})
return response.json()
},
// 内容数据类型定义
export interface Content {
id: string
title: string
type: "text" | "image" | "video" | "audio" | "document"
content: string
thumbnail?: string
fileUrl?: string
tags: string[]
category: string
status: "draft" | "published" | "archived"
viewCount: number
useCount: number
createTime: string
updateTime: string
creator: string
size?: number
duration?: number
}
export interface ContentStats {
total: number
published: number
draft: number
archived: number
totalViews: number
totalUses: number
}
export interface CreateContentRequest {
title: string
type: "text" | "image" | "video" | "audio" | "document"
content: string
tags?: string[]
category: string
fileUrl?: string
}
// 获取内容列表
export async function getContents(): Promise<Content[]> {
try {
const response = await apiClient.get("/v1/content")
return response.data || []
} catch (error) {
console.error("获取内容列表失败:", error)
// 返回模拟数据作为降级处理
return [
{
id: "1",
title: "产品介绍文案",
type: "text",
content: "这是一个优秀的产品介绍文案...",
tags: ["产品", "介绍", "营销"],
category: "营销文案",
status: "published",
viewCount: 1250,
useCount: 89,
createTime: "2024-01-01 10:00:00",
updateTime: "2024-01-07 14:30:00",
creator: "内容团队",
},
{
id: "2",
title: "品牌宣传图片",
type: "image",
content: "品牌宣传图片素材",
thumbnail: "/placeholder.svg?height=100&width=100",
fileUrl: "/placeholder.svg?height=400&width=600",
tags: ["品牌", "宣传", "图片"],
category: "视觉素材",
status: "published",
viewCount: 890,
useCount: 156,
createTime: "2024-01-02 11:00:00",
updateTime: "2024-01-07 13:45:00",
creator: "设计团队",
size: 2048000,
},
{
id: "3",
title: "产品演示视频",
type: "video",
content: "产品功能演示视频",
thumbnail: "/placeholder.svg?height=100&width=100",
fileUrl: "/placeholder.mp4",
tags: ["产品", "演示", "视频"],
category: "视频素材",
status: "published",
viewCount: 567,
useCount: 78,
createTime: "2024-01-03 09:30:00",
updateTime: "2024-01-07 10:20:00",
creator: "视频团队",
size: 15728640,
duration: 120,
},
]
}
}
// 获取内容统计
export async function getContentStats(): Promise<ContentStats> {
try {
const response = await apiClient.get("/v1/content/stats")
return response.data || { total: 0, published: 0, draft: 0, archived: 0, totalViews: 0, totalUses: 0 }
} catch (error) {
console.error("获取内容统计失败:", error)
return {
total: 156,
published: 128,
draft: 23,
archived: 5,
totalViews: 45620,
totalUses: 2340,
}
}
}
// 创建内容
export async function createContent(content: CreateContentRequest): Promise<{ success: boolean; message?: string }> {
try {
const response = await apiClient.post("/v1/content", content)
return { success: true, message: "内容创建成功" }
} catch (error) {
console.error("创建内容失败:", error)
return { success: false, message: "创建内容失败" }
}
}
// 删除内容
export async function deleteContent(contentId: string): Promise<{ success: boolean; message?: string }> {
try {
const response = await apiClient.delete(`/v1/content/${contentId}`)
return { success: true, message: "内容删除成功" }
} catch (error) {
console.error("删除内容失败:", error)
return { success: false, message: "删除内容失败" }
}
}
// 更新内容
export async function updateContent(
contentId: string,
updates: Partial<CreateContentRequest>,
): Promise<{ success: boolean; message?: string }> {
try {
const response = await apiClient.put(`/v1/content/${contentId}`, updates)
return { success: true, message: "内容更新成功" }
} catch (error) {
console.error("更新内容失败:", error)
return { success: false, message: "更新内容失败" }
}
}