"use client" import { useState } from "react" import { useRouter } from "next/navigation" 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, Video, Eye, Plus, Trash2 } from "lucide-react" import { AddDanceDialog } from "@/components/dances/add-dance-dialog" import { DeleteConfirmationDialog } from "@/components/delete-confirmation-dialog" import { useToast } from "@/hooks/use-toast" import type { Dance } from "@/lib/api/types" // 初始舞蹈数据 const initialDances: Dance[] = [ { id: "1", name: "千本樱", choreographer: "洛天依工作室", duration: "3:45", difficulty: "中等", videoUrl: "/placeholder.svg?height=300&width=400", coverUrl: "/placeholder.svg?height=300&width=400", description: "基于《千本樱》歌曲的经典舞蹈编排,动作流畅优美,适合中等水平的舞者。", motionFile: "senbonzakura_motion.fbx", category: "日式", tags: ["经典", "流行", "日式"], createdAt: "2023-01-15T08:30:00Z", updatedAt: "2023-02-20T14:15:00Z", }, { id: "2", name: "权御天下", choreographer: "洛天依动作组", duration: "4:20", difficulty: "高级", videoUrl: "/placeholder.svg?height=300&width=400", coverUrl: "/placeholder.svg?height=300&width=400", description: "中国风舞蹈,动作幅度大,需要较高的舞蹈基础,展现古风韵味。", motionFile: "quanyutianxia_motion.fbx", category: "中国风", tags: ["高难度", "中国风", "古风"], createdAt: "2023-03-10T10:45:00Z", updatedAt: "2023-04-05T16:30:00Z", }, { id: "3", name: "达拉崩吧", choreographer: "洛天依舞蹈工作室", duration: "3:10", difficulty: "初级", videoUrl: "/placeholder.svg?height=300&width=400", coverUrl: "/placeholder.svg?height=300&width=400", description: "轻松欢快的舞蹈,适合初学者,动作简单易学。", motionFile: "dalabengba_motion.fbx", category: "流行", tags: ["简单", "欢快", "流行"], createdAt: "2023-05-20T09:15:00Z", updatedAt: "2023-05-25T11:20:00Z", }, { id: "4", name: "普通DISCO", choreographer: "洛天依动作设计组", duration: "3:30", difficulty: "中等", videoUrl: "/placeholder.svg?height=300&width=400", coverUrl: "/placeholder.svg?height=300&width=400", description: "现代disco风格舞蹈,节奏感强,动作活力四射。", motionFile: "disco_motion.fbx", category: "现代", tags: ["活力", "现代", "disco"], createdAt: "2023-06-05T14:30:00Z", updatedAt: "2023-06-10T17:45:00Z", }, { id: "5", name: "华灯宴", choreographer: "古风舞蹈团队", duration: "4:50", difficulty: "高级", videoUrl: "/placeholder.svg?height=300&width=400", coverUrl: "/placeholder.svg?height=300&width=400", description: "古风舞蹈,动作优美细腻,需要较高的舞蹈技巧和表现力。", motionFile: "hualangyan_motion.fbx", category: "中国风", tags: ["古风", "优美", "高难度"], createdAt: "2023-07-12T11:20:00Z", updatedAt: "2023-07-18T13:40:00Z", }, ] export default function DancesPage() { const { toast } = useToast() const router = useRouter() const [dances, setDances] = useState(initialDances) const [searchTerm, setSearchTerm] = useState("") const [currentPage, setCurrentPage] = useState(1) const [isAddDialogOpen, setIsAddDialogOpen] = useState(false) const [danceToEdit, setDanceToEdit] = useState(undefined) const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false) const [danceToDelete, setDanceToDelete] = useState(null) const itemsPerPage = 5 // 过滤和分页 const filteredDances = dances.filter( (dance) => dance.name.toLowerCase().includes(searchTerm.toLowerCase()) || dance.id.toLowerCase().includes(searchTerm.toLowerCase()) || (dance.choreographer && dance.choreographer.toLowerCase().includes(searchTerm.toLowerCase())) || (dance.category && dance.category.toLowerCase().includes(searchTerm.toLowerCase())) || (dance.tags && dance.tags.some((tag) => tag.toLowerCase().includes(searchTerm.toLowerCase()))), ) const totalPages = Math.ceil(filteredDances.length / itemsPerPage) const paginatedDances = filteredDances.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage) // 处理添加舞蹈 const handleAddDance = (newDance: Dance) => { setDances((prevDances) => [...prevDances, newDance]) toast({ title: "添加成功", description: `舞蹈 ${newDance.name} 已成功添加`, }) } // 处理编辑舞蹈 const handleEditDance = (updatedDance: Dance) => { setDances((prevDances) => prevDances.map((dance) => (dance.id === updatedDance.id ? updatedDance : dance))) setDanceToEdit(undefined) setIsAddDialogOpen(false) toast({ title: "更新成功", description: `舞蹈 ${updatedDance.name} 已成功更新`, }) } // 处理删除舞蹈 const handleDeleteDance = () => { if (!danceToDelete) return setDances((prevDances) => prevDances.filter((dance) => dance.id !== danceToDelete.id)) setDanceToDelete(null) setIsDeleteDialogOpen(false) toast({ title: "删除成功", description: `舞蹈 ${danceToDelete.name} 已成功删除`, variant: "destructive", }) } // 打开编辑对话框 const openEditDialog = (dance: Dance) => { setDanceToEdit(dance) setIsAddDialogOpen(true) } // 查看舞蹈详情 const viewDanceDetails = (dance: Dance) => { router.push(`/dances/${dance.id}`) } // 打开删除确认对话框 const openDeleteDialog = (dance: Dance) => { setDanceToDelete(dance) setIsDeleteDialogOpen(true) } return (
{ setSearchTerm(e.target.value) setCurrentPage(1) // 重置到第一页 }} />
舞蹈列表
管理洛天依可以表演的舞蹈
ID 舞蹈名称 编舞者 难度 分类 时长 操作 {paginatedDances.map((dance) => (
{dance.id} {dance.name} {dance.choreographer || "未知"} {dance.difficulty || "未知"} {dance.category || "未分类"} {dance.duration || "未知"}
))} {paginatedDances.length === 0 && ( 没有找到匹配的舞蹈 )}
显示 {paginatedDances.length > 0 ? (currentPage - 1) * itemsPerPage + 1 : 0}- {Math.min(currentPage * itemsPerPage, filteredDances.length)} 共 {filteredDances.length} 个舞蹈
{/* 添加/编辑舞蹈对话框 */} {/* 删除确认对话框 */}
) }