feat(accounts): 新增登录异常分型统计、多选/全量导出、筛选记忆及页面组件模块化拆分
- 新增登录失败异常分型统计:支持「必须绑定手机号」、「极验滑块」、「凭证错误」、「邮箱取码失败」、「邮箱配额已满」、「网络异常」分型识别、生命周期联动(待人工)与一键筛选; - 新增账号名单与明细导出功能:支持勾选多选或按当前筛选条件全选,可导出纯用户名名单 (TXT) 或 UTF-8 BOM 结构化明细报表 (CSV),并支持一键复制到剪贴板; - 优化筛选条件记忆机制:支持页面切换/返回后自动保留所有筛选与排序状态,新增顶部「重置全部筛选」快捷按钮; - 模块化拆分 AccountsPage:将 2100+ 行的大文件拆解至 pages/accounts/ 子目录(包含状态卡片、筛选面板、工具栏、操作弹窗与表格构建器),提升可维护性; - 验证方式:新增 5 个后端自动化单测 (test_account_failure_and_export.py),全量 694 个测试用例通过,前端 TypeScript 编译与 pre-commit 代码规范检查全部通过。
This commit is contained in:
@@ -0,0 +1,351 @@
|
||||
import type { TableProps } from 'antd';
|
||||
import { Space, Button, Typography, Tag, Tooltip, Select, Popconfirm } from 'antd';
|
||||
import { DeleteOutlined } from '@ant-design/icons';
|
||||
import type { NavigateFunction } from 'react-router-dom';
|
||||
import type { AccountItem } from '../../../api/modules';
|
||||
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>
|
||||
);
|
||||
}
|
||||
|
||||
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%' }}>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
style={{ padding: 0, maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis' }}
|
||||
title={username}
|
||||
onClick={() => navigate(`/accounts/${record.id}`)}
|
||||
>
|
||||
{username}
|
||||
</Button>
|
||||
<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_owned',
|
||||
...sortProps('high_value', '两个都可兑换在前,未查询在后'),
|
||||
width: 170,
|
||||
render: (owned: string[] | null | undefined, record: AccountItem) => {
|
||||
if (owned === null || owned === undefined || !record.overview_queried_at) {
|
||||
return (
|
||||
<Tooltip title="尚未查询高价值套装准入状态,点工具栏「批量一键查询」">
|
||||
<Text type="secondary">未查询</Text>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
if (owned.length === 0) {
|
||||
return <Tag color="green">两个都可兑换</Tag>;
|
||||
}
|
||||
return (
|
||||
<Space size={4} wrap>
|
||||
{owned.map((n) => (
|
||||
<Tag key={n} color="orange">
|
||||
{n.replace(/^套装-/, '')} 已达上限
|
||||
</Tag>
|
||||
))}
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '兑换记录',
|
||||
dataIndex: 'exchange_count',
|
||||
...sortProps('exchange', '未兑换在前'),
|
||||
width: 170,
|
||||
render: (_, record: AccountItem) => {
|
||||
if (!record.exchange_count) {
|
||||
return <Text type="secondary">未兑换</Text>;
|
||||
}
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user