高价值套装的准入判定改为只认官方精英宝典 storehome 里账号级的 status:0=可兑换、1=已达兑换上限,商品缺失/接口异常=unknown。 兑换记录和积分记录只作历史展示,不参与是否拥有的判定。 原来的 high_value_owned(JSON 名单)无法区分「确认可兑换」和 「官方接口没返回商品」,也无法表达部分失败。改为两套独立状态 + 检查时间(迁移 20261106_0065),旧快照保守回填:status 缺失的 一律 unknown,不猜。 CK 判定失效时在数据层作废结论(降为 unknown),不是展示层降级。 官方 status 是账号维度的,但 CK 失效那段时间账号可能被别人手工 登录并兑换(这些号共享给客服),缓存里的「可兑换」就不成立了; 只在展示层降级的话,CK 恢复后那条陈旧的「可换」会重新变绿。 error(查不到)不作废 —— 查不到不等于账号出问题了。 高价值结论有自己的时钟:资料刷新除了看 overview_queried_at,还看 high_value_checked_at。两者会脱钩(商品接口单独失败时资料时间被刷新、 高价值时间停在原地),少了这一条这类账号会永久停在旧结论。作废的 结论按 6 小时慢速重试,但「从来没查到过」不因此重选 —— 那是接口对 该账号稳定失败,每轮都重选只会反复撞墙。 商城商品列表改用精英宝典的 manualID 拉取,不再寄生在电竞手册分支里 (否则没配电竞手册的配置就永远拉不到商城,三态全部停在待确认)。 筛选拆成三类「查不到」:unqueried(未查资料,旧口径不变)、 high_value_never(从未读到商城)、high_value_unknown(查过但结论 未知/过期)。之前第二类无处可寻 —— 它既不满足 unqueried 也不满足 high_value_unknown。
415 lines
13 KiB
TypeScript
415 lines
13 KiB
TypeScript
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 (
|
|
<Tag color={tone} style={{ marginInlineEnd: 0 }}>
|
|
{scope}
|
|
{mark}
|
|
</Tag>
|
|
);
|
|
}
|
|
|
|
function highValueAssetTag(
|
|
shortName: string,
|
|
state: HighValueAssetState,
|
|
) {
|
|
if (state === 'owned') {
|
|
return <Tag color="orange" style={{ marginInlineEnd: 0 }}>{shortName}已换</Tag>;
|
|
}
|
|
if (state === 'available') {
|
|
return <Tag color="green" style={{ marginInlineEnd: 0 }}>{shortName}可换</Tag>;
|
|
}
|
|
return <Tag style={{ marginInlineEnd: 0 }}>{shortName}待确认</Tag>;
|
|
}
|
|
|
|
function renderHighValueStatus(highValue: HighValueStatus | undefined) {
|
|
if (!highValue || highValue.state === 'never') {
|
|
return (
|
|
<Tooltip title="尚未成功读取官方商城准入状态,点工具栏「批量一键查询」">
|
|
<Text type="secondary">未查询</Text>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
if (highValue.state === 'stale') {
|
|
return (
|
|
<Tooltip
|
|
title={`官方商城结果已过期,上次检查:${formatTimeShort(highValue.checked_at)}`}
|
|
>
|
|
<Tag>数据已过期</Tag>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
const checked = highValue.checked_at
|
|
? `官方 storehome 检查于 ${formatTimeShort(highValue.checked_at)}`
|
|
: '官方 storehome 状态';
|
|
return (
|
|
<Tooltip title={checked}>
|
|
<Space size={4} wrap>
|
|
{highValueAssetTag('白日梦', highValue.bairimeng)}
|
|
{highValueAssetTag('萌兔', highValue.mengtu)}
|
|
</Space>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
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<string, string>;
|
|
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<AccountItem>['columns'] {
|
|
const sortProps = (key: AccountSortKey, tip?: string) => ({
|
|
key,
|
|
sorter: true,
|
|
sortOrder: sortKey === key ? sortOrder : null,
|
|
showSorterTooltip: tip ? { title: tip } : true,
|
|
});
|
|
|
|
const columns: TableProps<AccountItem>['columns'] = [
|
|
{
|
|
title: '账号',
|
|
dataIndex: 'username',
|
|
...sortProps('username'),
|
|
width: 200,
|
|
ellipsis: true,
|
|
render: (username: string, record: AccountItem) => (
|
|
<Space direction="vertical" size={0} style={{ maxWidth: '100%' }}>
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: 2,
|
|
maxWidth: '100%',
|
|
minWidth: 0,
|
|
}}
|
|
>
|
|
<Button
|
|
type="link"
|
|
size="small"
|
|
style={{
|
|
padding: 0,
|
|
minWidth: 0,
|
|
flex: '0 1 auto',
|
|
overflow: 'hidden',
|
|
textOverflow: 'ellipsis',
|
|
whiteSpace: 'nowrap',
|
|
}}
|
|
title={username}
|
|
onClick={() => navigate(`/accounts/${record.id}`)}
|
|
>
|
|
{username}
|
|
</Button>
|
|
<Tooltip title="复制账号名">
|
|
<Button
|
|
type="text"
|
|
size="small"
|
|
aria-label="复制账号名"
|
|
icon={<CopyOutlined style={{ fontSize: 12, color: '#8c8c8c' }} />}
|
|
style={{ padding: 0, width: 18, height: 18, minWidth: 18, flex: 'none' }}
|
|
onClick={async () => {
|
|
try {
|
|
await copyTextToClipboard(username);
|
|
message.success('账号名已复制');
|
|
} catch {
|
|
message.error('复制失败');
|
|
}
|
|
}}
|
|
/>
|
|
</Tooltip>
|
|
</div>
|
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
#{record.id}
|
|
</Text>
|
|
</Space>
|
|
),
|
|
},
|
|
{
|
|
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 (
|
|
<Space direction="vertical" size={2}>
|
|
<Space size={4} wrap>
|
|
<Tag color={tone} style={{ marginInlineEnd: 0 }}>
|
|
{record.status_label || status || '-'}
|
|
</Tag>
|
|
{record.auto_managed === false && (
|
|
<Tag color="orange" style={{ marginInlineEnd: 0 }}>
|
|
不自动
|
|
</Tag>
|
|
)}
|
|
{record.relogin_failure_kind && (
|
|
<Tooltip
|
|
title={
|
|
record.relogin_last_error
|
|
? `失败原因: ${record.relogin_last_error}`
|
|
: record.relogin_failure_label || record.relogin_failure_kind
|
|
}
|
|
>
|
|
<Tag
|
|
color={fkMeta?.color || 'red'}
|
|
style={{ marginInlineEnd: 0, cursor: 'pointer' }}
|
|
>
|
|
{record.relogin_failure_label || fkMeta?.label || record.relogin_failure_kind}
|
|
</Tag>
|
|
</Tooltip>
|
|
)}
|
|
</Space>
|
|
<Text
|
|
type={status === 'active' && record.ck_check_status === 'error' ? 'warning' : 'secondary'}
|
|
style={{ fontSize: 12 }}
|
|
>
|
|
{ckNote}
|
|
</Text>
|
|
</Space>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
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 (
|
|
<Tooltip
|
|
title={
|
|
queried
|
|
? '已查询过,但斗鱼这次没给出绑定结论(既非已绑也非未绑)'
|
|
: '还没查询过绑定 —— 点工具栏「批量一键查询」'
|
|
}
|
|
>
|
|
<Text type="secondary">{queried ? '未能判定' : '未查询'}</Text>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
return (
|
|
<Space size={2} wrap>
|
|
<BindChip scope="精" status={record.role_bind_status} />
|
|
<BindChip scope="电" status={record.esports_bind_status} />
|
|
<BindChip scope="店" status={record.xpd_bind_status} />
|
|
</Space>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: '分配',
|
|
dataIndex: 'assigned_username',
|
|
width: 110,
|
|
render: (name: string | null, record: AccountItem) => {
|
|
if (name) {
|
|
return (
|
|
<Tag color="green" style={{ marginInlineEnd: 0 }}>
|
|
{name}
|
|
</Tag>
|
|
);
|
|
}
|
|
return canAssign ? (
|
|
<Button
|
|
type="link"
|
|
size="small"
|
|
style={{ padding: 0 }}
|
|
onClick={() => onOpenAssignModal(record.id)}
|
|
>
|
|
未分配
|
|
</Button>
|
|
) : (
|
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
未分配
|
|
</Text>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: '积分 / 鱼翅',
|
|
dataIndex: 'points',
|
|
...sortProps('points', '按积分排,没查过的在后;积分相同再看鱼翅'),
|
|
width: 120,
|
|
render: (_, record: AccountItem) => (
|
|
<Space direction="vertical" size={0}>
|
|
<Text>积分 {record.points ?? '-'}</Text>
|
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
鱼翅 {record.gold_balance ?? '-'}
|
|
</Text>
|
|
</Space>
|
|
),
|
|
},
|
|
{
|
|
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 (
|
|
<Tooltip title="官方兑换列表当前没有记录;官方会清理历史,不能据此推断账号没换过">
|
|
<Text type="secondary">无官方记录</Text>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
return (
|
|
<Tooltip title="点击查看全部官方兑换记录">
|
|
<div
|
|
role="button"
|
|
tabIndex={0}
|
|
style={{ cursor: 'pointer' }}
|
|
onClick={() => onOpenExchangeRecords(record)}
|
|
onKeyDown={(event) => {
|
|
if (event.key === 'Enter') onOpenExchangeRecords(record);
|
|
}}
|
|
>
|
|
<Space direction="vertical" size={0} style={{ maxWidth: '100%' }}>
|
|
<Text>{record.exchange_count} 次</Text>
|
|
<Text type="secondary" style={{ fontSize: 12 }} ellipsis>
|
|
{formatTimeShort(record.last_exchange_at)}
|
|
{record.last_exchange_name
|
|
? ` ${record.last_exchange_name.replace(/^兑换\s*/, '')}`
|
|
: ''}
|
|
</Text>
|
|
</Space>
|
|
</div>
|
|
</Tooltip>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: '标签',
|
|
dataIndex: 'tag',
|
|
...sortProps('tag'),
|
|
width: 190,
|
|
render: (tag: string, record: AccountItem) => {
|
|
if (canTag) {
|
|
return (
|
|
<Select
|
|
mode="tags"
|
|
maxCount={1}
|
|
allowClear
|
|
showSearch
|
|
optionFilterProp="label"
|
|
size="small"
|
|
placeholder="选择或输入标签"
|
|
style={{ width: 150 }}
|
|
value={tag ? [tag] : []}
|
|
onChange={(values) => {
|
|
const value = values.at(-1)?.trim() || '';
|
|
if (value !== tag) onSetTag(record.id, value);
|
|
}}
|
|
options={tags.map((value) => ({ value, label: value }))}
|
|
/>
|
|
);
|
|
}
|
|
return tag ? <Tag color={tagColorMap[tag]}>{tag}</Tag> : <Text type="secondary">-</Text>;
|
|
},
|
|
},
|
|
];
|
|
|
|
if (canViewFull && sensitiveVisible) {
|
|
columns.push(
|
|
{ title: '密码', dataIndex: 'password', width: 120 },
|
|
{ title: '邮箱', dataIndex: 'email' },
|
|
{ title: '邮箱密码', dataIndex: 'email_password', width: 120 },
|
|
);
|
|
}
|
|
|
|
if (canDelete) {
|
|
columns.push({
|
|
title: '操作',
|
|
width: 90,
|
|
align: 'center',
|
|
render: (_: unknown, record: AccountItem) => (
|
|
<Popconfirm title="确认删除?" onConfirm={() => onDelete(record.id)}>
|
|
<Button danger size="small" icon={<DeleteOutlined />}>
|
|
删除
|
|
</Button>
|
|
</Popconfirm>
|
|
),
|
|
});
|
|
}
|
|
|
|
return columns;
|
|
}
|