'use client' import { ColumnDef } from '@tanstack/react-table' import { Level } from '@/types' import { Button } from '@/components/ui/button' import { Pencil, Trash2 } from 'lucide-react' import Image from 'next/image' interface ColumnCallbacks { onEdit: (level: Level) => void onDelete: (id: string) => void deleteConfirmId: string | null } export function createColumns({ onEdit, onDelete, deleteConfirmId, }: ColumnCallbacks): ColumnDef[] { return [ { accessorKey: 'sortOrder', header: '序号', cell: ({ row }) => ( {row.original.sortOrder + 1} ), size: 60, }, { id: 'images', header: '图片', cell: ({ row }) => { const { image1Url, image2Url } = row.original return (
{image1Url ? ( 图片1 ) : (
)}
{image2Url ? ( 图片2 ) : (
)}
) }, size: 120, }, { accessorKey: 'answer', header: '答案', cell: ({ row }) => ( {row.original.answer} ), }, { accessorKey: 'punchline', header: '谐音梗', cell: ({ row }) => { const punchline = row.original.punchline return punchline ? ( {punchline} ) : ( ) }, }, { id: 'hints', header: '提示', cell: ({ row }) => { const { hint1, hint2, hint3 } = row.original const hints = [hint1, hint2, hint3].filter(Boolean) return hints.length > 0 ? ( {hints.join('、')} ) : ( ) }, }, { accessorKey: 'createdAt', header: '创建时间', cell: ({ row }) => { const date = new Date(row.original.createdAt) return ( {date.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', })} ) }, size: 120, }, { id: 'actions', header: '操作', cell: ({ row }) => { const level = row.original const isConfirming = deleteConfirmId === level.id return (
) }, size: 100, }, ] }