import type { Prop } from "./types" import { mockResponse, type PaginatedResponse, type PaginationParams } from "./client" // 模拟道具数据 const mockProps: Prop[] = [ { id: "PRP001", name: "魔法麦克风", type: "演出道具", rarity: "稀有", description: "洛天依的经典原创道具,可以增强歌声的魔力,让听众更加沉浸在音乐中。", releaseDate: "2023-11-15", status: "已发布", activatedCount: 1245, image: "/placeholder.svg?height=300&width=300", }, { id: "PRP002", name: "星光魔杖", type: "互动道具", rarity: "史诗", description: "挥舞魔杖可以创造出美丽的星光效果,增加互动时的好感度。", releaseDate: "2023-12-01", status: "已发布", activatedCount: 876, image: "/placeholder.svg?height=300&width=300", }, { id: "PRP003", name: "音乐盒", type: "收藏品", rarity: "传说", description: "精美的音乐盒,打开后会播放洛天依的经典歌曲,是珍贵的收藏品。", releaseDate: "2024-01-10", status: "已发布", activatedCount: 532, image: "/placeholder.svg?height=300&width=300", }, { id: "PRP004", name: "虚拟相机", type: "互动道具", rarity: "稀有", description: "可以捕捉洛天依的精彩瞬间,保存为虚拟照片。", releaseDate: "2024-02-05", status: "已发布", activatedCount: 967, image: "/placeholder.svg?height=300&width=300", }, { id: "PRP005", name: "节日礼盒", type: "限定道具", rarity: "史诗", description: "节日限定礼盒,内含多种惊喜道具和装饰品。", releaseDate: "", status: "未发布", activatedCount: 0, image: "/placeholder.svg?height=300&width=300", }, ] // 获取道具列表 export const getProps = async (params?: PaginationParams): Promise> => { let filteredProps = [...mockProps] // 搜索过滤 if (params?.search) { const search = params.search.toLowerCase() filteredProps = filteredProps.filter( (prop) => prop.name.toLowerCase().includes(search) || prop.id.toLowerCase().includes(search) || prop.type.toLowerCase().includes(search), ) } // 排序 if (params?.sortBy) { filteredProps.sort((a: any, b: any) => { const aValue = a[params.sortBy!] const bValue = b[params.sortBy!] if (typeof aValue === "string" && typeof bValue === "string") { return params.sortOrder === "desc" ? bValue.localeCompare(aValue) : aValue.localeCompare(bValue) } return params.sortOrder === "desc" ? bValue - aValue : aValue - bValue }) } // 分页 const page = params?.page || 1 const pageSize = params?.pageSize || 10 const startIndex = (page - 1) * pageSize const paginatedProps = filteredProps.slice(startIndex, startIndex + pageSize) return mockResponse({ items: paginatedProps, total: filteredProps.length, page, pageSize, totalPages: Math.ceil(filteredProps.length / pageSize), }) } // 获取单个道具 export const getProp = async (id: string): Promise => { const prop = mockProps.find((prop) => prop.id === id) if (!prop) { return mockResponse({} as Prop, "道具不存在") } return mockResponse(prop) } // 创建道具 export const createProp = async (propData: Partial): Promise => { // 生成新的道具ID const propId = "PRP" + String(mockProps.length + 1).padStart(3, "0") const newProp: Prop = { id: propId, name: propData.name || "", type: propData.type || "", rarity: propData.rarity || "", description: propData.description || "", releaseDate: propData.releaseDate || "", status: propData.status || "未发布", activatedCount: 0, image: propData.image || "/placeholder.svg?height=300&width=300", } mockProps.push(newProp) return mockResponse(newProp) } // 更新道具 export const updateProp = async (id: string, propData: Partial): Promise => { const propIndex = mockProps.findIndex((prop) => prop.id === id) if (propIndex === -1) { return mockResponse({} as Prop, "道具不存在") } const updatedProp = { ...mockProps[propIndex], ...propData, } mockProps[propIndex] = updatedProp return mockResponse(updatedProp) } // 删除道具 export const deleteProp = async (id: string): Promise => { const propIndex = mockProps.findIndex((prop) => prop.id === id) if (propIndex === -1) { return mockResponse(false, "道具不存在") } // 已发布的道具不能删除 if (mockProps[propIndex].status === "已发布") { return mockResponse(false, "已发布的道具不能删除") } mockProps.splice(propIndex, 1) return mockResponse(true) } // 发布道具 export const publishProp = async (id: string): Promise => { const propIndex = mockProps.findIndex((prop) => prop.id === id) if (propIndex === -1) { return mockResponse({} as Prop, "道具不存在") } mockProps[propIndex].status = "已发布" mockProps[propIndex].releaseDate = new Date().toISOString().split("T")[0] return mockResponse(mockProps[propIndex]) }