feat: 为CK页面增加标签筛选

This commit is contained in:
yml2213
2026-08-13 16:24:35 +08:00
parent 47ded2bc3e
commit a223cb726d
6 changed files with 157 additions and 23 deletions
+45 -14
View File
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from 'react';
import { Button, Input, Popconfirm, Space, Table, Tag, Typography } from 'antd';
import { Button, Input, Popconfirm, Select, Space, Table, Tag, Typography } from 'antd';
import { message } from '../utils/antdMessage';
import { LoadingOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
import { cookieApi, type CookieOperationCheckResult, type CookieOperationItem } from '../api/modules';
@@ -12,6 +12,8 @@ export default function CookieOperationsPage() {
const [items, setItems] = useState<CookieOperationItem[]>([]);
const [loading, setLoading] = useState(false);
const [search, setSearch] = useState('');
const [tagFilter, setTagFilter] = useState('');
const [tags, setTags] = useState<string[]>([]);
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
const [checkingIds, setCheckingIds] = useState<Set<number>>(new Set());
const [reloginIds, setReloginIds] = useState<Set<number>>(new Set());
@@ -30,6 +32,7 @@ export default function CookieOperationsPage() {
page: currentPage,
page_size: pageSize,
search: search.trim() || undefined,
tag: tagFilter || undefined,
});
setItems(data.items);
setTotal(data.total);
@@ -50,12 +53,18 @@ export default function CookieOperationsPage() {
} finally {
setLoading(false);
}
}, [currentPage, pageSize, search]);
}, [currentPage, pageSize, search, tagFilter]);
useEffect(() => {
void loadItems();
}, [loadItems]);
useEffect(() => {
cookieApi.listOperationTags().then(setTags).catch(() => {
// 标签加载失败不影响 CK 检测与重登。
});
}, []);
const handleCheck = async (ids: number[]) => {
if (ids.length === 0) return;
setCheckingIds((previous) => new Set([...previous, ...ids]));
@@ -103,6 +112,13 @@ export default function CookieOperationsPage() {
const selectedIds = selectedRowKeys.map((key) => Number(key));
const columns = [
{ title: '账号', dataIndex: 'account_username', ellipsis: true },
{
title: '标签',
dataIndex: 'tag',
width: 140,
ellipsis: true,
render: (tag: string) => tag ? <Tag color="blue">{tag}</Tag> : <Text type="secondary">-</Text>,
},
{
title: '有效性',
width: 110,
@@ -168,18 +184,33 @@ export default function CookieOperationsPage() {
</Popconfirm>
</Space>
</div>
<Input.Search
allowClear
prefix={<SearchOutlined />}
placeholder="搜索账号"
style={{ width: 280, marginBottom: 12 }}
value={search}
onChange={(event) => {
setSearch(event.target.value);
setCurrentPage(1);
setSelectedRowKeys([]);
}}
/>
<Space wrap style={{ marginBottom: 12 }}>
<Select
allowClear
showSearch
placeholder="按标签筛选"
style={{ width: 160 }}
value={tagFilter || undefined}
onChange={(value) => {
setTagFilter(value || '');
setCurrentPage(1);
setSelectedRowKeys([]);
}}
options={tags.map((tag) => ({ value: tag, label: tag }))}
/>
<Input.Search
allowClear
prefix={<SearchOutlined />}
placeholder="搜索账号或标签"
style={{ width: 280 }}
value={search}
onChange={(event) => {
setSearch(event.target.value);
setCurrentPage(1);
setSelectedRowKeys([]);
}}
/>
</Space>
<Table
rowKey="id"
size="small"