import type { TableProps } from 'antd'; import { Space, Button, Typography, Tag, Tooltip, Select, Popconfirm } from 'antd'; import { CopyOutlined, DeleteOutlined } from '@ant-design/icons'; import type { NavigateFunction } from 'react-router-dom'; import type { AccountItem, HighValueAssetState, HighValueStatus } from '../../../api/modules'; import { message } from '../../../utils/antdMessage'; import { copyTextToClipboard } from '../../../utils/clipboard'; import { formatTimeShort } from '../../../utils/time'; import { type AccountSortKey, STATUS_TONES, FAILURE_KIND_LABELS, } from '../types'; const { Text } = Typography; function BindChip({ scope, status }: { scope: string; status?: string }) { const tone = status === 'bound' ? 'green' : status === 'pending' ? 'orange' : status === 'unbound' ? 'red' : 'default'; const mark = status === 'bound' ? '✓' : status === 'pending' ? '…' : status === 'unbound' ? '✗' : '?'; return ( {scope} {mark} ); } function highValueAssetTag( shortName: string, state: HighValueAssetState, ) { if (state === 'owned') { return {shortName}已换; } if (state === 'available') { return {shortName}可换; } return {shortName}待确认; } function renderHighValueStatus(highValue: HighValueStatus | undefined) { if (!highValue || highValue.state === 'never') { return ( 未查询 ); } if (highValue.state === 'stale') { return ( 数据已过期 ); } const checked = highValue.checked_at ? `官方 storehome 检查于 ${formatTimeShort(highValue.checked_at)}` : '官方 storehome 状态'; return ( {highValueAssetTag('白日梦', highValue.bairimeng)} {highValueAssetTag('萌兔', highValue.mengtu)} ); } export interface UseAccountColumnsOptions { navigate: NavigateFunction; sortKey: AccountSortKey | ''; sortOrder: 'ascend' | 'descend' | null; canViewFull: boolean; canTag: boolean; canDelete: boolean; canAssign: boolean; sensitiveVisible: boolean; tags: string[]; tagColorMap: Record; onOpenExchangeRecords: (record: AccountItem) => void; onOpenAssignModal: (recordId: number) => void; onSetTag: (accountId: number, tag: string) => void; onDelete: (id: number) => void; } export function buildAccountColumns({ navigate, sortKey, sortOrder, canViewFull, canTag, canDelete, canAssign, sensitiveVisible, tags, tagColorMap, onOpenExchangeRecords, onOpenAssignModal, onSetTag, onDelete, }: UseAccountColumnsOptions): TableProps['columns'] { const sortProps = (key: AccountSortKey, tip?: string) => ({ key, sorter: true, sortOrder: sortKey === key ? sortOrder : null, showSorterTooltip: tip ? { title: tip } : true, }); const columns: TableProps['columns'] = [ { title: '账号', dataIndex: 'username', ...sortProps('username'), width: 200, ellipsis: true, render: (username: string, record: AccountItem) => (
#{record.id}
), }, { title: '状态', dataIndex: 'status', ...sortProps('status', '正常在前'), width: 190, render: (status: string, record: AccountItem) => { const tone = STATUS_TONES[status] ?? 'default'; const ckNote = !record.has_cookie ? '无 CK' : record.ck_check_status === 'error' ? '检测异常' : record.ck_checked_at ? `检测 ${formatTimeShort(record.ck_checked_at)}` : '未检测'; const fkMeta = record.relogin_failure_kind ? FAILURE_KIND_LABELS[record.relogin_failure_kind] : null; return ( {record.status_label || status || '-'} {record.auto_managed === false && ( 不自动 )} {record.relogin_failure_kind && ( {record.relogin_failure_label || fkMeta?.label || record.relogin_failure_kind} )} {ckNote} ); }, }, { title: '绑定', dataIndex: 'role_bind_status', ...sortProps('bind', '已绑定在前,先看精英,再看电竞和小店'), width: 150, render: (_, record: AccountItem) => { const allUnknown = [ record.role_bind_status, record.esports_bind_status, record.xpd_bind_status, ].every((s) => !s || s === 'unknown'); if (allUnknown) { const queried = Boolean(record.overview_queried_at); return ( {queried ? '未能判定' : '未查询'} ); } return ( ); }, }, { title: '分配', dataIndex: 'assigned_username', width: 110, render: (name: string | null, record: AccountItem) => { if (name) { return ( {name} ); } return canAssign ? ( ) : ( 未分配 ); }, }, { title: '积分 / 鱼翅', dataIndex: 'points', ...sortProps('points', '按积分排,没查过的在后;积分相同再看鱼翅'), width: 120, render: (_, record: AccountItem) => ( 积分 {record.points ?? '-'} 鱼翅 {record.gold_balance ?? '-'} ), }, { title: '高价值套装', dataIndex: 'high_value', ...sortProps('high_value', '两个都可兑换在前,未查询在后'), width: 190, render: (_, record: AccountItem) => renderHighValueStatus(record.high_value), }, { title: '官方兑换记录', dataIndex: 'exchange_count', ...sortProps('exchange', '没有官方记录在前'), width: 170, render: (_, record: AccountItem) => { if (!record.exchange_count) { return ( 无官方记录 ); } return (
onOpenExchangeRecords(record)} onKeyDown={(event) => { if (event.key === 'Enter') onOpenExchangeRecords(record); }} > {record.exchange_count} 次 {formatTimeShort(record.last_exchange_at)} {record.last_exchange_name ? ` ${record.last_exchange_name.replace(/^兑换\s*/, '')}` : ''}
); }, }, { title: '标签', dataIndex: 'tag', ...sortProps('tag'), width: 190, render: (tag: string, record: AccountItem) => { if (canTag) { return (