97 lines
2.4 KiB
TypeScript
97 lines
2.4 KiB
TypeScript
import type { ColumnDef } from "@tanstack/react-table"
|
|
import { Badge } from "@/components/ui/badge"
|
|
import type { User, UserTier } from "@/types/user"
|
|
|
|
const TIER_LABELS: Record<UserTier, string> = {
|
|
free: "免费",
|
|
pro: "Pro",
|
|
proplus: "Pro+",
|
|
}
|
|
|
|
const TIER_VARIANTS: Record<UserTier, "secondary" | "default" | "destructive"> = {
|
|
free: "secondary",
|
|
pro: "default",
|
|
proplus: "destructive",
|
|
}
|
|
|
|
const AUTH_TYPE_LABELS: Record<string, string> = {
|
|
huawei: "华为",
|
|
guest: "游客",
|
|
phone: "手机",
|
|
apple: "Apple",
|
|
google: "Google",
|
|
}
|
|
|
|
export function getColumns(): ColumnDef<User>[] {
|
|
return [
|
|
{
|
|
accessorKey: "nickname",
|
|
header: "昵称",
|
|
cell: ({ row }) => {
|
|
const nickname = row.getValue("nickname") as string | null
|
|
return (
|
|
<span className="font-medium">
|
|
{nickname || <span className="text-muted-foreground">未设置</span>}
|
|
</span>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "authType",
|
|
header: "登录方式",
|
|
cell: ({ row }) => {
|
|
const authType = row.getValue("authType") as string
|
|
return (
|
|
<span className="text-muted-foreground">
|
|
{AUTH_TYPE_LABELS[authType] ?? authType}
|
|
</span>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "tier",
|
|
header: "订阅",
|
|
cell: ({ row }) => {
|
|
const tier = row.getValue("tier") as UserTier
|
|
return <Badge variant={TIER_VARIANTS[tier]}>{TIER_LABELS[tier]}</Badge>
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "xpTotal",
|
|
header: "总 XP",
|
|
cell: ({ row }) => (
|
|
<span className="text-muted-foreground">
|
|
{(row.getValue("xpTotal") as number).toLocaleString()}
|
|
</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "streakDays",
|
|
header: "连续天数",
|
|
cell: ({ row }) => (
|
|
<span className="text-muted-foreground">
|
|
{row.getValue("streakDays")} 天
|
|
</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "heartsRemaining",
|
|
header: "红心",
|
|
cell: ({ row }) => (
|
|
<span className="text-muted-foreground">
|
|
{row.getValue("heartsRemaining")}
|
|
</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "createdAt",
|
|
header: "注册时间",
|
|
cell: ({ row }) => (
|
|
<span className="text-muted-foreground text-xs">
|
|
{new Date(row.getValue("createdAt") as string).toLocaleDateString("zh-CN")}
|
|
</span>
|
|
),
|
|
},
|
|
]
|
|
}
|