调整列表字段和枚举值转换

This commit is contained in:
Eamon
2026-01-05 09:14:41 +08:00
parent a27e856f07
commit 054b8954c4
23 changed files with 571 additions and 222 deletions

View File

@@ -1,35 +1,106 @@
"use client"
import { format } from "date-fns"
import { Suspense } from "react"
import { getPageChannel } from "@/actions/channel"
import { DataTable, useDataTable } from "@/components/data-table"
import type { User } from "@/models/user"
import { Badge } from "@/components/ui/badge"
import type { Channel } from "@/models/channel"
export default function UserPage() {
const table = useDataTable<User>((page, size) =>
export default function ChannelPage() {
const table = useDataTable<Channel>((page, size) =>
getPageChannel({ page, size }),
)
console.log(table, "table")
return (
<Suspense>
<DataTable<User>
<DataTable<Channel>
{...table}
columns={[
{ header: "ID", accessorKey: "id" },
{ header: "批次号", accessorKey: "batch_no" },
{ header: "边缘节点", accessorKey: "edge_ref" },
{ header: "省份", accessorKey: "filter_prov" },
{ header: "城市", accessorKey: "filter_city" },
{ header: "运营商", accessorKey: "filter_isp" },
{ header: "主机", accessorKey: "host" },
{ header: "端口", accessorKey: "port" },
{ header: "密码", accessorKey: "password" },
{ header: "代理号", accessorKey: "proxy_id" },
{ header: "可用资源", accessorKey: "resource_id" },
{ header: "用户名", accessorKey: "username" },
{ header: "创建时间", accessorKey: "created_at" },
{ header: "更新时间", accessorKey: "updated_at" },
{ header: "过期时间", accessorKey: "expired_at" },
{
header: "运营商",
accessorKey: "filter_isp",
cell: ({ row }) => {
const value = row.getValue("filter_isp")
if (!value || value === "all") return "不限"
if (value === 1) return "电信"
if (value === 2) return "联通"
if (value === 3) return "移动"
return String(value)
},
},
{
header: "代理地址",
accessorKey: "host",
cell: ({ row }) => {
const ip = row.original.host
const port = row.original.port
return (
<span>
{ip}:{port}{" "}
</span>
)
},
},
{
header: "认证方式",
cell: ({ row }) => {
const channel = row.original
console.log(channel, "channel")
const hasWhitelist =
channel.whitelists && channel.whitelists.trim() !== ""
const hasAuth = channel.username && channel.password
return (
<div className="flex flex-col gap-1 min-w-0">
{hasWhitelist ? (
<div className="flex flex-col">
<span></span>
<div className="flex flex-wrap gap-1 max-w-50">
{channel.whitelists.split(",").map(ip => (
<Badge key={ip.trim()} variant="secondary">
{ip.trim()}
</Badge>
))}
</div>
</div>
) : hasAuth ? (
<div className="flex flex-col">
<span></span>
<Badge variant="secondary">
{channel.username}:{channel.password}
</Badge>
</div>
) : (
<span className="text-sm text-gray-400"></span>
)}
</div>
)
},
},
{ header: "资源数量", accessorKey: "resource_id" },
{
header: "创建时间",
accessorKey: "created_at",
cell: ({ row }) =>
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
},
{
header: "更新时间",
accessorKey: "updated_at",
cell: ({ row }) =>
format(new Date(row.original.updated_at), "yyyy-MM-dd HH:mm"),
},
{
header: "过期时间",
accessorKey: "expired_at",
cell: ({ row }) =>
format(new Date(row.original.expired_at), "yyyy-MM-dd HH:mm"),
},
]}
/>
</Suspense>