108 lines
3.6 KiB
TypeScript
108 lines
3.6 KiB
TypeScript
"use client"
|
|
import { format } from "date-fns"
|
|
import { Suspense } from "react"
|
|
import { getPageChannel } from "@/actions/channel"
|
|
import { DataTable, useDataTable } from "@/components/data-table"
|
|
import { Badge } from "@/components/ui/badge"
|
|
import type { Channel } from "@/models/channel"
|
|
|
|
export default function ChannelPage() {
|
|
const table = useDataTable<Channel>((page, size) =>
|
|
getPageChannel({ page, size }),
|
|
)
|
|
|
|
return (
|
|
<Suspense>
|
|
<DataTable<Channel>
|
|
{...table}
|
|
columns={[
|
|
{ header: "ID", accessorKey: "id" },
|
|
{ header: "批次号", accessorKey: "batch_no" },
|
|
{ header: "省份", accessorKey: "filter_prov" },
|
|
{ header: "城市", accessorKey: "filter_city" },
|
|
{
|
|
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
|
|
|
|
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>
|
|
)
|
|
}
|