Files
live-hub-py/web/frontend/src/pages/accounts/components/AccountToolbar.tsx
T
yml2213 f101414f5e feat(accounts): 新增登录异常分型统计、多选/全量导出、筛选记忆及页面组件模块化拆分
- 新增登录失败异常分型统计:支持「必须绑定手机号」、「极验滑块」、「凭证错误」、「邮箱取码失败」、「邮箱配额已满」、「网络异常」分型识别、生命周期联动(待人工)与一键筛选;
- 新增账号名单与明细导出功能:支持勾选多选或按当前筛选条件全选,可导出纯用户名名单 (TXT) 或 UTF-8 BOM 结构化明细报表 (CSV),并支持一键复制到剪贴板;
- 优化筛选条件记忆机制:支持页面切换/返回后自动保留所有筛选与排序状态,新增顶部「重置全部筛选」快捷按钮;
- 模块化拆分 AccountsPage:将 2100+ 行的大文件拆解至 pages/accounts/ 子目录(包含状态卡片、筛选面板、工具栏、操作弹窗与表格构建器),提升可维护性;
- 验证方式:新增 5 个后端自动化单测 (test_account_failure_and_export.py),全量 694 个测试用例通过,前端 TypeScript 编译与 pre-commit 代码规范检查全部通过。
2026-10-07 17:23:39 +08:00

263 lines
7.0 KiB
TypeScript

import React from 'react';
import { Space, Select, Input, Dropdown, Button, Tooltip, Popconfirm, type MenuProps } from 'antd';
import {
FilterOutlined,
DownloadOutlined,
DownOutlined,
EyeInvisibleOutlined,
EyeOutlined,
TagOutlined,
UsergroupAddOutlined,
DeleteOutlined,
ThunderboltOutlined,
ImportOutlined,
ClearOutlined,
} from '@ant-design/icons';
import {
CK_OPTIONS,
FAILURE_KIND_OPTIONS,
BIND_OPTIONS,
} from '../types';
export interface AccountToolbarProps {
tags: string[];
tagFilter: string;
setTagFilter: (val: string) => void;
ckFilter: string;
setCkFilter: (val: string) => void;
failureKindFilter: string;
setFailureKindFilter: (val: string) => void;
bindFilter: string;
setBindFilter: (val: string) => void;
assignFilter: string;
setAssignFilter: (val: string) => void;
assignFilterOptions: Array<{ value: string; label: string }>;
searchText: string;
setSearchText: (val: string) => void;
hasAnyFilter: boolean;
onResetAllFilters: () => void;
exportMenuItems: MenuProps['items'];
exporting: boolean;
selectedCount: number;
canViewFull: boolean;
sensitiveVisible: boolean;
onToggleSensitive: () => void;
canTag: boolean;
onOpenBatchTag: () => void;
canAssign: boolean;
onOpenBatchAssign: () => void;
canDelete: boolean;
selectedAllMatching: boolean;
onBatchDelete: () => void;
selectedRowKeys: React.Key[];
batchQuerying: boolean;
onBatchOverview: () => void;
canImport: boolean;
onOpenImport: () => void;
setCurrentPage: (page: number) => void;
}
export function AccountToolbar({
tags,
tagFilter,
setTagFilter,
ckFilter,
setCkFilter,
failureKindFilter,
setFailureKindFilter,
bindFilter,
setBindFilter,
assignFilter,
setAssignFilter,
assignFilterOptions,
searchText,
setSearchText,
hasAnyFilter,
onResetAllFilters,
exportMenuItems,
exporting,
selectedCount,
canViewFull,
sensitiveVisible,
onToggleSensitive,
canTag,
onOpenBatchTag,
canAssign,
onOpenBatchAssign,
canDelete,
selectedAllMatching,
onBatchDelete,
selectedRowKeys,
batchQuerying,
onBatchOverview,
canImport,
onOpenImport,
setCurrentPage,
}: AccountToolbarProps) {
return (
<div
style={{
marginBottom: 16,
display: 'flex',
justifyContent: 'space-between',
flexWrap: 'wrap',
gap: 8,
}}
>
<h2>账号管理</h2>
<Space wrap>
<Select
allowClear
showSearch
optionFilterProp="label"
placeholder="按标签筛选"
style={{ width: 140 }}
value={tagFilter || undefined}
onChange={(val) => {
setTagFilter(val || '');
setCurrentPage(1);
}}
options={tags.map((t) => ({ value: t, label: t }))}
prefix={<FilterOutlined />}
/>
<Select
allowClear
size="small"
placeholder="按 CK 筛选"
style={{ width: 110 }}
value={ckFilter || undefined}
onChange={(val) => {
setCkFilter(val || '');
setCurrentPage(1);
}}
options={CK_OPTIONS}
/>
<Select
allowClear
size="small"
placeholder="登录异常分类"
style={{ width: 150 }}
value={failureKindFilter || undefined}
onChange={(val) => {
setFailureKindFilter(val || '');
setCurrentPage(1);
}}
options={FAILURE_KIND_OPTIONS}
/>
<Select
allowClear
size="small"
placeholder="按绑定筛选"
style={{ width: 110 }}
value={bindFilter || undefined}
onChange={(val) => {
setBindFilter(val || '');
setCurrentPage(1);
}}
options={BIND_OPTIONS}
/>
<Select
allowClear
showSearch
optionFilterProp="label"
size="small"
placeholder="按分配筛选"
style={{ width: 130 }}
value={assignFilter || undefined}
onChange={(val) => {
setAssignFilter(val || '');
setCurrentPage(1);
}}
options={assignFilterOptions}
/>
<Input.Search
allowClear
size="small"
placeholder="搜索账号/标签/备注"
style={{ width: 200 }}
value={searchText}
onChange={(e) => {
setSearchText(e.target.value);
setCurrentPage(1);
}}
/>
{hasAnyFilter && (
<Button
danger
icon={<ClearOutlined />}
onClick={onResetAllFilters}
title="清空所有筛选与搜索条件并恢复默认排序"
>
重置全部筛选
</Button>
)}
<Dropdown menu={{ items: exportMenuItems }} placement="bottomLeft">
<Button icon={<DownloadOutlined />} loading={exporting}>
导出账号 {selectedCount > 0 ? `(${selectedCount})` : ''}{' '}
<DownOutlined style={{ fontSize: 10 }} />
</Button>
</Dropdown>
{canViewFull && (
<Button
icon={sensitiveVisible ? <EyeInvisibleOutlined /> : <EyeOutlined />}
onClick={onToggleSensitive}
>
{sensitiveVisible ? '隐藏凭据' : '显示凭据'}
</Button>
)}
{canTag && (
<Button
disabled={selectedCount === 0}
icon={<TagOutlined />}
onClick={onOpenBatchTag}
>
批量打标签
</Button>
)}
{canAssign && (
<Button
disabled={selectedCount === 0}
icon={<UsergroupAddOutlined />}
onClick={onOpenBatchAssign}
>
批量分配
</Button>
)}
{canDelete && (
<Popconfirm
title={`确认删除${selectedAllMatching ? '当前筛选下' : '选中的'} ${selectedCount} 个账号?`}
description="将同时删除关联的登录任务"
onConfirm={onBatchDelete}
okText="删除"
okButtonProps={{ danger: true }}
cancelText="取消"
>
<Button danger disabled={selectedCount === 0} icon={<DeleteOutlined />}>
批量删除
</Button>
</Popconfirm>
)}
<Tooltip title="实时向斗鱼查这些账号的鱼翅/积分/开通状态/兑换记录,并标出高价值套装是否已拥有">
<Button
disabled={selectedRowKeys.length === 0}
loading={batchQuerying}
icon={<ThunderboltOutlined />}
onClick={onBatchOverview}
>
批量一键查询
</Button>
</Tooltip>
{canImport && (
<Button
type="primary"
icon={<ImportOutlined />}
onClick={onOpenImport}
>
批量导入
</Button>
)}
</Space>
</div>
);
}