"use client" import { useState } from "react" import { DashboardShell } from "@/components/dashboard-shell" import { DashboardHeader } from "@/components/dashboard-header" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Badge } from "@/components/ui/badge" import { Search, Edit, Eye } from "lucide-react" import { AddPropDialog } from "@/components/props/add-prop-dialog" import type { Prop } from "@/components/props/prop-detail-dialog" import { DeleteConfirmationDialog } from "@/components/delete-confirmation-dialog" import { useToast } from "@/components/ui/use-toast" import Link from "next/link" // 初始道具数据 const initialProps: 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 default function PropsPage() { const { toast } = useToast() const [props, setProps] = useState(initialProps) const [searchTerm, setSearchTerm] = useState("") const [currentPage, setCurrentPage] = useState(1) const [selectedProp, setSelectedProp] = useState(null) const [isEditDialogOpen, setIsEditDialogOpen] = useState(false) const itemsPerPage = 5 // 过滤和分页 const filteredProps = props.filter( (prop) => prop.name.toLowerCase().includes(searchTerm.toLowerCase()) || prop.id.toLowerCase().includes(searchTerm.toLowerCase()) || prop.type.toLowerCase().includes(searchTerm.toLowerCase()), ) const totalPages = Math.ceil(filteredProps.length / itemsPerPage) const paginatedProps = filteredProps.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage) // 处理添加道具 const handleAddProp = (newProp: Prop) => { setProps((prevProps) => [...prevProps, newProp]) toast({ title: "添加成功", description: `道具 ${newProp.name} 已成功添加`, }) } // 处理编辑道具 const handleEditProp = (updatedProp: Prop) => { setProps((prevProps) => prevProps.map((prop) => (prop.id === updatedProp.id ? updatedProp : prop))) setSelectedProp(null) setIsEditDialogOpen(false) toast({ title: "更新成功", description: `道具 ${updatedProp.name} 已成功更新`, }) } // 处理删除道具 const handleDeleteProp = async (propId: string) => { // 模拟API请求 await new Promise((resolve) => setTimeout(resolve, 1000)) setProps((prevProps) => prevProps.filter((prop) => prop.id !== propId)) toast({ title: "删除成功", description: "道具已成功删除", variant: "destructive", }) } // 打开编辑对话框 const openEditDialog = (prop: Prop) => { setSelectedProp(prop) setIsEditDialogOpen(true) } return (
{ setSearchTerm(e.target.value) setCurrentPage(1) // 重置到第一页 }} />
道具列表
管理洛天依可以使用的道具
ID 道具名称 类型 稀有度 发布日期 状态 激活数量 操作 {paginatedProps.map((prop) => ( {prop.id} {prop.name} {prop.type} {prop.rarity} {prop.releaseDate || "-"} {prop.status} {prop.activatedCount} {/* 将详情对话框替换为链接按钮 */} {prop.status !== "已发布" && ( <> handleDeleteProp(prop.id)} /> )} ))} {paginatedProps.length === 0 && ( 没有找到匹配的道具 )}
显示 {paginatedProps.length > 0 ? (currentPage - 1) * itemsPerPage + 1 : 0}- {Math.min(currentPage * itemsPerPage, filteredProps.length)} 共 {filteredProps.length} 个道具
{/* 编辑道具对话框 - 当选中道具时显示 */} {selectedProp && isEditDialogOpen && ( )}
) }