feat: 支持配置微信用户已通关关卡

This commit is contained in:
richarjiang
2026-04-19 14:28:36 +08:00
parent 6e19bfa661
commit f3f27def2b
19 changed files with 7095 additions and 545 deletions

View File

@@ -0,0 +1,171 @@
'use client'
import { useMemo } from 'react'
import {
useReactTable,
getCoreRowModel,
getPaginationRowModel,
flexRender,
} from '@tanstack/react-table'
import { Level } from '@/types'
import { createColumns } from './level-columns'
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import { Button } from '@/components/ui/button'
import {
ChevronLeft,
ChevronRight,
ChevronsLeft,
ChevronsRight,
} from 'lucide-react'
interface LevelTableProps {
levels: Level[]
onEdit: (level: Level) => void
onDelete: (id: string) => void
deleteConfirmId: string | null
}
export function LevelTable({
levels,
onEdit,
onDelete,
deleteConfirmId,
}: LevelTableProps) {
const columns = useMemo(
() => createColumns({ onEdit, onDelete, deleteConfirmId }),
[onEdit, onDelete, deleteConfirmId]
)
const table = useReactTable({
data: levels,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
initialState: {
pagination: {
pageSize: 10,
},
},
})
if (levels.length === 0) {
return (
<div className="text-center py-12 text-gray-500">
<p></p>
<p className="text-sm mt-2">
&ldquo;&rdquo;
</p>
</div>
)
}
return (
<div className="space-y-4">
<div className="rounded-md border">
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<TableHead key={header.id}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</TableHead>
))}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows.map((row) => (
<TableRow key={row.id}>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</div>
{/* 分页控制栏 */}
<div className="flex items-center justify-between px-2">
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<span></span>
<select
className="h-8 rounded-md border border-input bg-background px-2 text-sm"
value={table.getState().pagination.pageSize}
onChange={(e) => {
table.setPageSize(Number(e.target.value))
}}
>
{[10, 20, 50].map((pageSize) => (
<option key={pageSize} value={pageSize}>
{pageSize}
</option>
))}
</select>
<span></span>
</div>
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground">
{table.getState().pagination.pageIndex + 1} /{' '}
{table.getPageCount()} {levels.length}
</span>
<div className="flex items-center gap-1">
<Button
variant="outline"
size="icon"
className="h-8 w-8"
onClick={() => table.setPageIndex(0)}
disabled={!table.getCanPreviousPage()}
>
<ChevronsLeft className="h-4 w-4" />
</Button>
<Button
variant="outline"
size="icon"
className="h-8 w-8"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
<ChevronLeft className="h-4 w-4" />
</Button>
<Button
variant="outline"
size="icon"
className="h-8 w-8"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
<ChevronRight className="h-4 w-4" />
</Button>
<Button
variant="outline"
size="icon"
className="h-8 w-8"
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
disabled={!table.getCanNextPage()}
>
<ChevronsRight className="h-4 w-4" />
</Button>
</div>
</div>
</div>
</div>
)
}