feat(douyu): 查询工作台区分导入/查询数据、导入后自动查CK并修复登录刷新闪烁 (v0.4.29)
1) 闪烁修复:轮询(loadAccountsPage/loadManualBudget)改为静默模式, 不再每 2.2s 点亮表格 loading 遮罩与预算 Tag spinner;活动结束后保留 12s 宽限期继续静默刷新,避免登录刚完成就停刷导致行上残留「登录队列中」。 2) 导入后自动检测 CK:工作台 PUT 返回 imported_account_ids,前端分片 并发检测并显示进度,失效/无 CK 账号直接标红;/accounts/ck-check 对 无 CK、登录中的账号改为跳过(返回 checked/skipped)而不是整批报错。 行内新增「重登/人工登录该账号」入口,走既有人工登录预算。 3) 数据来源区分:douyu_workbench_accounts 新增 data_state/imported_at/ queried_at/relogin_at(迁移 20261130_0142)。导入标 imported,查询任务 成功由 _mark_task 标 queried,人工重登入队标 stale;PUT 工作台改为 upsert,不再整删整建以免重置状态。账号列表新增 workbench_scope/ workbench_state 入参与 workbench_* 回填字段。 4) 重登后只查重登账号:新增 /query-workbench/pending-ids(导入未查 + 重登待重查,仅含有可用 CK 者)与「只查待查询(N)」下拉;一键查询改为 尊重当前筛选(跨页),修正原来无视筛选直接查整台的问题。 5) CSV 末尾追加「数据来源 / 数据更新说明」两列,保持原有列序不变。
This commit is contained in:
@@ -11,6 +11,7 @@ import type {
|
||||
DouyuQueryWorkbenchInvalidIdsResult,
|
||||
DouyuQueryWorkbenchLookupResult,
|
||||
DouyuQueryWorkbenchManualBudget,
|
||||
DouyuQueryWorkbenchPendingIdsResult,
|
||||
DouyuQueryWorkbenchReloginResult,
|
||||
DouyuRechargeChannel,
|
||||
DouyuSupplyTarget,
|
||||
@@ -69,14 +70,41 @@ export const douyuApi = {
|
||||
api.put<DouyuSupplyTarget, DouyuSupplyTarget>(`/douyu/supply-targets/${targetId}`, data),
|
||||
listAccounts: (params?: { search?: string; tag?: string; ids?: string; include_all?: boolean; ck_status?: string }) =>
|
||||
api.get<DouyuTaskAccountItem[], DouyuTaskAccountItem[]>('/douyu/accounts', { params }),
|
||||
listAccountsPaged: (params: PageParams & { ids?: string; tag?: string; include_all?: boolean; ck_status?: string }) =>
|
||||
listAccountsPaged: (params: PageParams & {
|
||||
ids?: string;
|
||||
tag?: string;
|
||||
include_all?: boolean;
|
||||
ck_status?: string;
|
||||
workbench_scope?: 'elite' | 'esports' | 'peace' | 'query';
|
||||
workbench_state?: 'imported' | 'queried' | 'stale';
|
||||
}) =>
|
||||
api.get<PaginatedResponse<DouyuTaskAccountItem>, PaginatedResponse<DouyuTaskAccountItem>>('/douyu/accounts', { params }),
|
||||
listAccountIds: (params: { search?: string; tag?: string; account_names?: string; include_all?: boolean; ck_status?: string } = {}) =>
|
||||
listAccountIds: (params: {
|
||||
search?: string;
|
||||
tag?: string;
|
||||
account_names?: string;
|
||||
include_all?: boolean;
|
||||
ck_status?: string;
|
||||
workbench_scope?: 'elite' | 'esports' | 'peace' | 'query';
|
||||
workbench_state?: 'imported' | 'queried' | 'stale';
|
||||
} = {}) =>
|
||||
api.get<{ account_ids: number[]; total: number }, { account_ids: number[]; total: number }>('/douyu/accounts/ids', { params }),
|
||||
checkAccountsCk: (ids: number[]) =>
|
||||
api.post<
|
||||
{ results: Array<{ id: number; valid: boolean; checked_at: string }>; success: boolean },
|
||||
{ results: Array<{ id: number; valid: boolean; checked_at: string }>; success: boolean }
|
||||
{
|
||||
results: Array<{ id: number; valid: boolean; checked_at: string }>;
|
||||
success: boolean;
|
||||
checked?: number;
|
||||
skipped?: number;
|
||||
message?: string;
|
||||
},
|
||||
{
|
||||
results: Array<{ id: number; valid: boolean; checked_at: string }>;
|
||||
success: boolean;
|
||||
checked?: number;
|
||||
skipped?: number;
|
||||
message?: string;
|
||||
}
|
||||
>('/douyu/accounts/ck-check', null, { params: { ids: ids.join(',') } }),
|
||||
reloginInvalidAccounts: (ids: number[]) =>
|
||||
api.post<
|
||||
@@ -92,6 +120,10 @@ export const douyuApi = {
|
||||
api.get<DouyuQueryWorkbenchInvalidIdsResult, DouyuQueryWorkbenchInvalidIdsResult>(
|
||||
'/douyu/query-workbench/invalid-ids',
|
||||
),
|
||||
getQueryWorkbenchPendingIds: () =>
|
||||
api.get<DouyuQueryWorkbenchPendingIdsResult, DouyuQueryWorkbenchPendingIdsResult>(
|
||||
'/douyu/query-workbench/pending-ids',
|
||||
),
|
||||
getQueryWorkbenchManualBudget: () =>
|
||||
api.get<DouyuQueryWorkbenchManualBudget, DouyuQueryWorkbenchManualBudget>(
|
||||
'/douyu/query-workbench/manual-budget',
|
||||
@@ -131,7 +163,10 @@ export const douyuApi = {
|
||||
params: { handbook_scope: handbookScope },
|
||||
}),
|
||||
updateWorkbenchAccounts: (handbookScope: 'elite' | 'esports' | 'peace' | 'query', accountIds: number[]) =>
|
||||
api.put<{ account_ids: number[]; success: boolean }, { account_ids: number[]; success: boolean }>(
|
||||
api.put<
|
||||
{ account_ids: number[]; imported_account_ids?: number[]; success: boolean },
|
||||
{ account_ids: number[]; imported_account_ids?: number[]; success: boolean }
|
||||
>(
|
||||
'/douyu/workbench-accounts', { handbook_scope: handbookScope, account_ids: accountIds },
|
||||
),
|
||||
listTasksPaged: (params: PageParams & { batch_id?: string; include_detail?: boolean }) =>
|
||||
|
||||
@@ -803,6 +803,10 @@ export interface DouyuTaskAccountItem {
|
||||
overview_queried_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
in_flight_login?: boolean;
|
||||
workbench_data_state?: DouyuWorkbenchDataState | '';
|
||||
workbench_imported_at?: string | null;
|
||||
workbench_queried_at?: string | null;
|
||||
workbench_relogin_at?: string | null;
|
||||
}
|
||||
|
||||
export interface DouyuSupplyTargetStatus {
|
||||
@@ -1048,6 +1052,15 @@ export interface DouyuQueryWorkbenchLookupResult {
|
||||
total_input: number;
|
||||
}
|
||||
|
||||
export type DouyuWorkbenchDataState = 'imported' | 'queried' | 'stale';
|
||||
|
||||
export interface DouyuQueryWorkbenchPendingIdsResult {
|
||||
account_ids: number[];
|
||||
imported_ids: number[];
|
||||
stale_ids: number[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface DouyuQueryWorkbenchInvalidIdsResult {
|
||||
account_ids: number[];
|
||||
invalid_ck_ids: number[];
|
||||
|
||||
@@ -59,6 +59,8 @@ type StatusFilterValue =
|
||||
| 'cooldown_ready'
|
||||
| 'cooldown_waiting';
|
||||
|
||||
type DataStateFilterValue = '' | 'imported' | 'queried' | 'stale';
|
||||
|
||||
const STATUS_FILTER_OPTIONS: Array<{ label: string; value: StatusFilterValue }> = [
|
||||
{ label: '全部', value: '' },
|
||||
{ label: 'CK 有效', value: 'valid' },
|
||||
@@ -68,6 +70,48 @@ const STATUS_FILTER_OPTIONS: Array<{ label: string; value: StatusFilterValue }>
|
||||
{ label: '冷却中', value: 'cooldown_waiting' },
|
||||
];
|
||||
|
||||
const DATA_STATE_OPTIONS: Array<{ label: string; value: DataStateFilterValue }> = [
|
||||
{ label: '数据:全部', value: '' },
|
||||
{ label: '导入未查询', value: 'imported' },
|
||||
{ label: '已查询', value: 'queried' },
|
||||
{ label: '重登待重查', value: 'stale' },
|
||||
];
|
||||
|
||||
const DATA_STATE_META: Record<
|
||||
Exclude<DataStateFilterValue, ''>,
|
||||
{ label: string; color: string; hint: string }
|
||||
> = {
|
||||
imported: {
|
||||
label: '导入未查询',
|
||||
color: 'default',
|
||||
hint: '仅导入并检测过 CK,鱼翅/积分/宝典/换绑仍是导入前的旧数据',
|
||||
},
|
||||
queried: {
|
||||
label: '已查询',
|
||||
color: 'success',
|
||||
hint: '已在本工作台跑过一键查询,展示的是本次查询结果',
|
||||
},
|
||||
stale: {
|
||||
label: '重登待重查',
|
||||
color: 'orange',
|
||||
hint: '重新登录成功或 CK 重新生效,账号数据已过期,需要单独回查',
|
||||
},
|
||||
};
|
||||
|
||||
/** 账号在本工作台的数据来源:未回填时按「导入未查询」保守处理。 */
|
||||
function resolveDataState(account: DouyuTaskAccountItem): Exclude<DataStateFilterValue, ''> {
|
||||
const state = account.workbench_data_state;
|
||||
if (state === 'queried' || state === 'stale') return state;
|
||||
return 'imported';
|
||||
}
|
||||
|
||||
/** 导入后自动检测 CK 的分片大小:单请求 8 线程并发,20 个约几秒。 */
|
||||
const IMPORT_CK_CHUNK_SIZE = 20;
|
||||
/** 任务/登录进行中时的静默轮询间隔:不打断列表,只在后台替换数据。 */
|
||||
const POLL_INTERVAL_MS = 2500;
|
||||
/** 最后一笔活动结束后继续轮询的宽限期,让登录结果落库并回显。 */
|
||||
const POLL_GRACE_MS = 12000;
|
||||
|
||||
function parseAccountNames(text: string): string[] {
|
||||
const seen = new Set<string>();
|
||||
return text
|
||||
@@ -134,7 +178,12 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const [statusFilter, setStatusFilter] = useState<StatusFilterValue>('');
|
||||
const [dataStateFilter, setDataStateFilter] = useState<DataStateFilterValue>('');
|
||||
const [concurrency, setConcurrency] = useState<number>(5);
|
||||
const [pendingQuery, setPendingQuery] = useState<{ importedIds: number[]; staleIds: number[] }>({
|
||||
importedIds: [],
|
||||
staleIds: [],
|
||||
});
|
||||
|
||||
const [tasks, setTasks] = useState<DouyuTaskItem[]>([]);
|
||||
const [runningBatchIds, setRunningBatchIds] = useState<Set<string>>(() => new Set());
|
||||
@@ -166,6 +215,17 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
|
||||
const [nowSeconds, setNowSeconds] = useState(() => Math.floor(Date.now() / 1000));
|
||||
const tasksLoadingRef = useRef(false);
|
||||
// 指向最新的账号列表加载器:导入后的 CK 刷新不想把整个分页依赖链再串一遍。
|
||||
const loadAccountsPageRef = useRef<((options?: { silent?: boolean }) => Promise<void>) | null>(
|
||||
null,
|
||||
);
|
||||
const reloadAccounts = useCallback(async (options?: { silent?: boolean }) => {
|
||||
await loadAccountsPageRef.current?.(options);
|
||||
}, []);
|
||||
const hasActivityRef = useRef(false);
|
||||
const pollDeadlineRef = useRef(0);
|
||||
const [polling, setPolling] = useState(false);
|
||||
const budgetLoadingRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setInterval(() => {
|
||||
@@ -174,15 +234,31 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
return () => window.clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
const loadManualBudget = useCallback(async () => {
|
||||
setBudgetLoading(true);
|
||||
const loadManualBudget = useCallback(async (options?: { silent?: boolean }) => {
|
||||
// 轮询期间复用同一个请求,且不点亮预算 Tag 的 spinner —— 否则每 2.5 秒闪一次。
|
||||
if (options?.silent && budgetLoadingRef.current) return;
|
||||
if (!options?.silent) setBudgetLoading(true);
|
||||
budgetLoadingRef.current = true;
|
||||
try {
|
||||
const budget = await douyuApi.getQueryWorkbenchManualBudget();
|
||||
setManualBudget(budget);
|
||||
} catch {
|
||||
// 仅用于顶部展示,失败不阻塞主体查询
|
||||
} finally {
|
||||
setBudgetLoading(false);
|
||||
budgetLoadingRef.current = false;
|
||||
if (!options?.silent) setBudgetLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const loadPendingQuery = useCallback(async () => {
|
||||
try {
|
||||
const res = await douyuApi.getQueryWorkbenchPendingIds();
|
||||
setPendingQuery({
|
||||
importedIds: res.imported_ids || [],
|
||||
staleIds: res.stale_ids || [],
|
||||
});
|
||||
} catch {
|
||||
// 仅用于按钮计数,失败不影响主流程
|
||||
}
|
||||
}, []);
|
||||
|
||||
@@ -202,47 +278,122 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
void loadManualBudget();
|
||||
}, [loadManualBudget, loadWorkbench]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!workbenchReady) return;
|
||||
void loadPendingQuery();
|
||||
}, [loadPendingQuery, workbenchIds, workbenchReady]);
|
||||
|
||||
const saveWorkbenchIds = useCallback(async (nextIds: number[], toast?: string) => {
|
||||
const deduped = Array.from(new Set(nextIds.filter((id) => Number.isInteger(id) && id > 0)));
|
||||
const res = await douyuApi.updateWorkbenchAccounts('query', deduped);
|
||||
setWorkbenchIds(res.account_ids);
|
||||
setSelectedIds((prev) => prev.filter((id) => res.account_ids.includes(id)));
|
||||
if (toast) message.success(toast);
|
||||
return res.account_ids;
|
||||
return res;
|
||||
}, []);
|
||||
|
||||
const loadAccountsPage = useCallback(async () => {
|
||||
if (!workbenchReady) return;
|
||||
if (workbenchIds.length === 0) {
|
||||
setAccounts([]);
|
||||
setAccountTotal(0);
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
/**
|
||||
* 导入后默认跑一次 CK 检测(分片并发,带进度)。
|
||||
* 失效/无 CK 的账号会在列表上直接标红,用户可勾选后走人工重登。
|
||||
*/
|
||||
const runImportCkCheck = useCallback(async (accountIds: number[]) => {
|
||||
const ids = Array.from(new Set(accountIds.filter((id) => Number.isInteger(id) && id > 0)));
|
||||
if (ids.length === 0) return;
|
||||
const key = 'query-workbench-import-ck';
|
||||
const total = ids.length;
|
||||
let done = 0;
|
||||
let valid = 0;
|
||||
let invalid = 0;
|
||||
setCkCheckingIds((prev) => {
|
||||
const next = new Set(prev);
|
||||
ids.forEach((id) => next.add(id));
|
||||
return next;
|
||||
});
|
||||
try {
|
||||
const res = await douyuApi.listAccountsPaged({
|
||||
ids: workbenchIds.join(','),
|
||||
search: searchText.trim() || undefined,
|
||||
ck_status: statusFilter || undefined,
|
||||
include_all: true,
|
||||
page: accountPage,
|
||||
page_size: accountPageSize,
|
||||
});
|
||||
setAccounts(res.items);
|
||||
setAccountTotal(res.total);
|
||||
if (accountPage > 1 && res.items.length === 0 && res.total > 0) {
|
||||
setAccountPage(Math.max(1, Math.ceil(res.total / accountPageSize)));
|
||||
for (let offset = 0; offset < ids.length; offset += IMPORT_CK_CHUNK_SIZE) {
|
||||
const chunk = ids.slice(offset, offset + IMPORT_CK_CHUNK_SIZE);
|
||||
message.open({
|
||||
key,
|
||||
type: 'loading',
|
||||
duration: 0,
|
||||
content: `导入完成,正在检测 CK(${Math.min(done, total)}/${total})`,
|
||||
});
|
||||
try {
|
||||
const res = await douyuApi.checkAccountsCk(chunk);
|
||||
const results = res.results || [];
|
||||
valid += results.filter((item) => item.valid).length;
|
||||
invalid += results.filter((item) => !item.valid).length;
|
||||
} catch (error) {
|
||||
// 单片段失败不中断其余片段:CK 检测是导入后的增强步骤
|
||||
message.error(`CK 检测失败: ${getErrorMessage(error)}`);
|
||||
} finally {
|
||||
done += chunk.length;
|
||||
setCkCheckingIds((prev) => {
|
||||
const next = new Set(prev);
|
||||
chunk.forEach((id) => next.delete(id));
|
||||
return next;
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(`加载账号列表失败: ${getErrorMessage(error)}`);
|
||||
message.open({
|
||||
key,
|
||||
type: 'success',
|
||||
duration: 4,
|
||||
content: `导入后 CK 检测完成:有效 ${valid} 个,失效/异常 ${invalid} 个${invalid > 0 ? '(可勾选后人工重登)' : ''}`,
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
await reloadAccounts({ silent: true });
|
||||
void loadPendingQuery();
|
||||
}
|
||||
}, [accountPage, accountPageSize, searchText, statusFilter, workbenchIds, workbenchReady]);
|
||||
}, [loadPendingQuery, reloadAccounts]);
|
||||
|
||||
const loadAccountsPage = useCallback(
|
||||
async (options?: { silent?: boolean }) => {
|
||||
if (!workbenchReady) return;
|
||||
if (workbenchIds.length === 0) {
|
||||
setAccounts([]);
|
||||
setAccountTotal(0);
|
||||
return;
|
||||
}
|
||||
// 静默刷新(轮询)不点亮表格 loading:否则每 2.5 秒整张表变灰闪一下。
|
||||
if (!options?.silent) setLoading(true);
|
||||
try {
|
||||
const res = await douyuApi.listAccountsPaged({
|
||||
ids: workbenchIds.join(','),
|
||||
search: searchText.trim() || undefined,
|
||||
ck_status: statusFilter || undefined,
|
||||
workbench_scope: 'query',
|
||||
workbench_state: dataStateFilter || undefined,
|
||||
include_all: true,
|
||||
page: accountPage,
|
||||
page_size: accountPageSize,
|
||||
});
|
||||
setAccounts(res.items);
|
||||
setAccountTotal(res.total);
|
||||
if (accountPage > 1 && res.items.length === 0 && res.total > 0) {
|
||||
setAccountPage(Math.max(1, Math.ceil(res.total / accountPageSize)));
|
||||
}
|
||||
} catch (error) {
|
||||
if (!options?.silent) {
|
||||
message.error(`加载账号列表失败: ${getErrorMessage(error)}`);
|
||||
}
|
||||
} finally {
|
||||
if (!options?.silent) setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
accountPage,
|
||||
accountPageSize,
|
||||
dataStateFilter,
|
||||
searchText,
|
||||
statusFilter,
|
||||
workbenchIds,
|
||||
workbenchReady,
|
||||
],
|
||||
);
|
||||
|
||||
const loadTasks = useCallback(async () => {
|
||||
if (!workbenchReady || tasksLoadingRef.current) return;
|
||||
tasksLoadingRef.current = true;
|
||||
if (!workbenchReady || tasksLoadingRef.current) return; tasksLoadingRef.current = true;
|
||||
try {
|
||||
const data = await douyuApi.listTasks('query', undefined, true, 300);
|
||||
setTasks(data);
|
||||
@@ -260,6 +411,10 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
}
|
||||
}, [workbenchReady]);
|
||||
|
||||
useEffect(() => {
|
||||
loadAccountsPageRef.current = loadAccountsPage;
|
||||
}, [loadAccountsPage]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadAccountsPage();
|
||||
}, [loadAccountsPage]);
|
||||
@@ -276,15 +431,32 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
[accounts, runningBatchIds, tasks],
|
||||
);
|
||||
|
||||
// 有任何在途任务/登录就开一个轮询窗口;最后一笔活动结束后再宽限片刻,
|
||||
// 让登录结果(CK 状态、数据状态)落库并回显,避免「刚登录完不再刷新」。
|
||||
useEffect(() => {
|
||||
if (!hasInFlightActivity) return undefined;
|
||||
hasActivityRef.current = hasInFlightActivity;
|
||||
if (!hasInFlightActivity) return;
|
||||
pollDeadlineRef.current = Date.now() + POLL_GRACE_MS;
|
||||
setPolling(true);
|
||||
}, [hasInFlightActivity]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!polling) return undefined;
|
||||
const timer = window.setInterval(() => {
|
||||
if (hasActivityRef.current) {
|
||||
pollDeadlineRef.current = Date.now() + POLL_GRACE_MS;
|
||||
}
|
||||
if (!hasActivityRef.current && Date.now() > pollDeadlineRef.current) {
|
||||
setPolling(false);
|
||||
return;
|
||||
}
|
||||
void loadTasks();
|
||||
void loadAccountsPage();
|
||||
void loadManualBudget();
|
||||
}, 2200);
|
||||
void loadAccountsPage({ silent: true });
|
||||
void loadManualBudget({ silent: true });
|
||||
void loadPendingQuery();
|
||||
}, POLL_INTERVAL_MS);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [hasInFlightActivity, loadAccountsPage, loadManualBudget, loadTasks]);
|
||||
}, [loadAccountsPage, loadManualBudget, loadPendingQuery, loadTasks, polling]);
|
||||
|
||||
const latestTaskByAccount = useMemo(() => {
|
||||
const map = new Map<number, DouyuTaskItem>();
|
||||
@@ -302,6 +474,9 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
[accounts],
|
||||
);
|
||||
|
||||
const pendingTotal = pendingQuery.importedIds.length + pendingQuery.staleIds.length;
|
||||
const pendingStaleCount = pendingQuery.staleIds.length;
|
||||
|
||||
// 导入弹窗池查询
|
||||
const loadImportPool = useCallback(async (page = importPage) => {
|
||||
setImportLoading(true);
|
||||
@@ -347,14 +522,15 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
try {
|
||||
const lookup = await douyuApi.lookupQueryWorkbenchAccounts(names);
|
||||
setUnmatchedNames(lookup.unmatched_names || []);
|
||||
let importedIds: number[] = [];
|
||||
if (lookup.account_ids.length > 0) {
|
||||
const beforeSet = new Set(workbenchIds);
|
||||
const addedCount = lookup.account_ids.filter((id) => !beforeSet.has(id)).length;
|
||||
await saveWorkbenchIds([...workbenchIds, ...lookup.account_ids]);
|
||||
const res = await saveWorkbenchIds([...workbenchIds, ...lookup.account_ids]);
|
||||
importedIds = (res.imported_account_ids || []).filter((id) => !beforeSet.has(id));
|
||||
setAccountPage(1);
|
||||
message.success(
|
||||
addedCount > 0
|
||||
? `已匹配 ${lookup.account_ids.length} 个账号,新导入 ${addedCount} 个到查询工作台`
|
||||
importedIds.length > 0
|
||||
? `已匹配 ${lookup.account_ids.length} 个账号,新导入 ${importedIds.length} 个到查询工作台`
|
||||
: `已匹配 ${lookup.account_ids.length} 个账号(均已在工作台中)`,
|
||||
);
|
||||
} else {
|
||||
@@ -364,6 +540,10 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
setPasteNamesText('');
|
||||
setImportOpen(false);
|
||||
}
|
||||
// 导入后默认检测一次 CK:失效/无 CK 账号直接标出来,方便人工重登。
|
||||
if (importedIds.length > 0) {
|
||||
await runImportCkCheck(importedIds);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(`导入失败: ${getErrorMessage(error)}`);
|
||||
} finally {
|
||||
@@ -378,11 +558,15 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
}
|
||||
const beforeSet = new Set(workbenchIds);
|
||||
const addedCount = importSelectedIds.filter((id) => !beforeSet.has(id)).length;
|
||||
await saveWorkbenchIds(
|
||||
const saved = await saveWorkbenchIds(
|
||||
[...workbenchIds, ...importSelectedIds],
|
||||
addedCount > 0 ? `新导入 ${addedCount} 个账号到查询工作台` : '所选账号均已在工作台中',
|
||||
);
|
||||
setImportOpen(false);
|
||||
const importedIds = (saved.imported_account_ids || []).filter((id) => !beforeSet.has(id));
|
||||
if (importedIds.length > 0) {
|
||||
await runImportCkCheck(importedIds);
|
||||
}
|
||||
};
|
||||
|
||||
const handleImportAllFiltered = async () => {
|
||||
@@ -400,11 +584,15 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
}
|
||||
const beforeSet = new Set(workbenchIds);
|
||||
const addedCount = res.account_ids.filter((id) => !beforeSet.has(id)).length;
|
||||
await saveWorkbenchIds(
|
||||
const saved = await saveWorkbenchIds(
|
||||
[...workbenchIds, ...res.account_ids],
|
||||
`已按筛选导入 ${res.account_ids.length} 个账号(新增 ${addedCount} 个)`,
|
||||
);
|
||||
setImportOpen(false);
|
||||
const importedIds = (saved.imported_account_ids || []).filter((id) => !beforeSet.has(id));
|
||||
if (importedIds.length > 0) {
|
||||
await runImportCkCheck(importedIds);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(`按筛选导入失败: ${getErrorMessage(error)}`);
|
||||
} finally {
|
||||
@@ -412,8 +600,41 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const hasActiveFilter = Boolean(
|
||||
searchText.trim() || statusFilter || dataStateFilter,
|
||||
);
|
||||
|
||||
/**
|
||||
* 一键查询:优先用勾选,其次用当前筛选结果(跨页),最后才是整个工作台。
|
||||
* 这样「数据:重登待重查 + 一键查询」就只会回查重登过的账号。
|
||||
*/
|
||||
const handleOneClickQuery = async (overrideIds?: number[]) => {
|
||||
const rawTargetIds = overrideIds ?? (selectedIds.length > 0 ? selectedIds : workbenchIds);
|
||||
let rawTargetIds = overrideIds;
|
||||
if (!rawTargetIds) {
|
||||
if (selectedIds.length > 0) {
|
||||
rawTargetIds = selectedIds;
|
||||
} else if (hasActiveFilter) {
|
||||
try {
|
||||
const res = await douyuApi.listAccountIds({
|
||||
search: searchText.trim() || undefined,
|
||||
ck_status: statusFilter || undefined,
|
||||
workbench_scope: 'query',
|
||||
workbench_state: dataStateFilter || undefined,
|
||||
include_all: true,
|
||||
});
|
||||
rawTargetIds = res.account_ids;
|
||||
if (rawTargetIds.length === 0) {
|
||||
message.info('当前筛选条件下没有可查询的账号');
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(`获取筛选账号失败: ${getErrorMessage(error)}`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
rawTargetIds = workbenchIds;
|
||||
}
|
||||
}
|
||||
if (rawTargetIds.length === 0) {
|
||||
message.warning('工作台暂无账号,请先导入斗鱼账号');
|
||||
return;
|
||||
@@ -447,6 +668,19 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 只查「待查询」的账号:导入后未查过 + 重登成功后待重查。
|
||||
* 重登成功后点这里就只会回查重新登录的账号,不会把整个工作台重跑一遍。
|
||||
*/
|
||||
const handleQueryPending = async () => {
|
||||
const targetIds = Array.from(new Set([...pendingQuery.importedIds, ...pendingQuery.staleIds]));
|
||||
if (targetIds.length === 0) {
|
||||
message.info('当前没有待查询的账号(导入后待查 / 重登后待重查)');
|
||||
return;
|
||||
} await handleOneClickQuery(targetIds);
|
||||
void loadPendingQuery();
|
||||
};
|
||||
|
||||
const handleCheckCk = async (overrideIds?: number[]) => {
|
||||
const candidateRows = overrideIds
|
||||
? accounts.filter((a) => overrideIds.includes(a.id))
|
||||
@@ -568,9 +802,10 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
res.skipped_missing_credentials > 0 ? `缺密码/邮箱 ${res.skipped_missing_credentials}` : '',
|
||||
].filter(Boolean);
|
||||
message.success(
|
||||
`已加入人工登录队列:${parts.join(',')}${skipParts.length ? `(${skipParts.join(',')})` : ''}`,
|
||||
`已加入人工登录队列:${parts.join(',')}${skipParts.length ? `(${skipParts.join(',')})` : ''};登录成功后可点「只查待查询」单独回查这批账号`,
|
||||
);
|
||||
await loadAccountsPage();
|
||||
void loadPendingQuery();
|
||||
} catch (error) {
|
||||
message.error(`提交重登失败: ${getErrorMessage(error)}`);
|
||||
} finally {
|
||||
@@ -580,6 +815,28 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
});
|
||||
};
|
||||
|
||||
/** 单行「重登该账号」:走同一人工预算入口,只提交这一行。 */
|
||||
const handleReloginSingle = async (account: DouyuTaskAccountItem) => {
|
||||
if (!canRelogin) {
|
||||
message.error('无权限发起重登(需超级管理员或 login:batch 权限)');
|
||||
return;
|
||||
}
|
||||
setReloginSubmitting(true);
|
||||
try {
|
||||
const res = await douyuApi.reloginQueryWorkbenchInvalid([account.id], false);
|
||||
if (res.manual_budget) setManualBudget(res.manual_budget);
|
||||
message.success(
|
||||
`已将 ${account.username} 加入人工登录队列(重登 ${res.relogin_count} · 登录 ${res.login_count})`,
|
||||
);
|
||||
await loadAccountsPage({ silent: true });
|
||||
void loadPendingQuery();
|
||||
} catch (error) {
|
||||
message.error(`提交重登失败: ${getErrorMessage(error)}`);
|
||||
} finally {
|
||||
setReloginSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleExportCsv = async () => {
|
||||
if (workbenchIds.length === 0) {
|
||||
message.warning('工作台暂无可导出的账号');
|
||||
@@ -706,33 +963,74 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '数据来源',
|
||||
width: 130,
|
||||
render: (_, record) => {
|
||||
const state = resolveDataState(record);
|
||||
const meta = DATA_STATE_META[state];
|
||||
const stamp = state === 'queried'
|
||||
? record.workbench_queried_at
|
||||
: state === 'stale'
|
||||
? record.workbench_relogin_at
|
||||
: record.workbench_imported_at;
|
||||
return (
|
||||
<Tooltip title={meta.hint}>
|
||||
<Space direction="vertical" size={2} style={{ lineHeight: 1.35 }}>
|
||||
<Tag color={meta.color} style={{ marginInlineEnd: 0 }}>
|
||||
{meta.label}
|
||||
</Tag>
|
||||
{stamp ? (
|
||||
<Text type="secondary" style={{ fontSize: 11 }}>
|
||||
{state === 'queried' ? '查询' : state === 'stale' ? '重登' : '导入'}: {formatTime(stamp)}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '鱼翅',
|
||||
width: 115,
|
||||
render: (_, record) => (
|
||||
<Space direction="vertical" size={0} style={{ lineHeight: 1.35 }}>
|
||||
<Text strong>{record.gold_balance != null ? record.gold_balance : '-'}</Text>
|
||||
{record.exchange_balance != null ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
兑换: {record.exchange_balance}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
),
|
||||
render: (_, record) => {
|
||||
const stale = resolveDataState(record) !== 'queried';
|
||||
return (
|
||||
<Tooltip title={stale ? '导入时的历史数据,本工作台尚未查询' : undefined}>
|
||||
<Space direction="vertical" size={0} style={{ lineHeight: 1.35 }}>
|
||||
<Text strong={!stale} type={stale ? 'secondary' : undefined}>
|
||||
{record.gold_balance != null ? record.gold_balance : '-'}
|
||||
</Text>
|
||||
{record.exchange_balance != null ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
兑换: {record.exchange_balance}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '积分',
|
||||
width: 145,
|
||||
render: (_, record) => (
|
||||
<Space direction="vertical" size={0} style={{ lineHeight: 1.35 }}>
|
||||
<Text strong>{record.points != null ? record.points : '-'}</Text>
|
||||
{record.points_expire_at ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
到期: {formatTime(record.points_expire_at)}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
),
|
||||
render: (_, record) => {
|
||||
const stale = resolveDataState(record) !== 'queried';
|
||||
return (
|
||||
<Tooltip title={stale ? '导入时的历史数据,本工作台尚未查询' : undefined}>
|
||||
<Space direction="vertical" size={0} style={{ lineHeight: 1.35 }}>
|
||||
<Text strong={!stale} type={stale ? 'secondary' : undefined}>
|
||||
{record.points != null ? record.points : '-'}
|
||||
</Text>
|
||||
{record.points_expire_at ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
到期: {formatTime(record.points_expire_at)}
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '宝典状态 / 到期',
|
||||
@@ -909,6 +1207,7 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
width: 110,
|
||||
fixed: 'right',
|
||||
render: (_, record) => {
|
||||
const needsRelogin = isInvalidOrNoCookie(record);
|
||||
const items: MenuProps['items'] = [
|
||||
{
|
||||
key: 'copy-username',
|
||||
@@ -923,6 +1222,13 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
disabled: record.has_cookie === false || Boolean(record.in_flight_login),
|
||||
onClick: () => void handleCheckCk([record.id]),
|
||||
},
|
||||
{
|
||||
key: 'relogin',
|
||||
icon: <SyncOutlined />,
|
||||
label: record.has_cookie === false ? '人工登录该账号' : '重登该账号(人工预算)',
|
||||
disabled: !canRelogin || !needsRelogin || Boolean(record.in_flight_login),
|
||||
onClick: () => void handleReloginSingle(record),
|
||||
},
|
||||
{
|
||||
key: 'remove',
|
||||
icon: <DeleteOutlined />,
|
||||
@@ -1019,6 +1325,13 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
斗鱼查询工作台
|
||||
</Title>
|
||||
<Tag color="blue">工作台共 {workbenchIds.length} 个账号</Tag>
|
||||
{pendingTotal > 0 ? (
|
||||
<Tooltip
|
||||
title={`导入未查询 ${pendingQuery.importedIds.length} 个,重登待重查 ${pendingStaleCount} 个;点「只查待查询」只回查这批账号`}
|
||||
>
|
||||
<Tag color="gold">待查询 {pendingTotal}</Tag>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
{hasInFlightActivity ? (
|
||||
<Tag color="processing" icon={<SyncOutlined spin />}>
|
||||
任务/登录进行中,自动刷新
|
||||
@@ -1026,7 +1339,8 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
) : null}
|
||||
</Space>
|
||||
<Text type="secondary" style={{ fontSize: 13 }}>
|
||||
支持导入斗鱼号(含 CK 失效/无 CK 账号),一键查询鱼翅、积分、宝典状态与换绑时间并导出 CSV;失效 CK 可选中后走人工预算重新登录。
|
||||
支持导入斗鱼号(含 CK 失效/无 CK 账号),导入后自动检测一次 CK,一键查询鱼翅、积分、宝典状态与换绑时间并导出 CSV;
|
||||
列表会区分「导入未查询」与「已查询」;失效 CK 可选中后走人工预算重新登录,重登成功后再点「只查待查询」就只回查这些账号。
|
||||
</Text>
|
||||
</Space>
|
||||
|
||||
@@ -1075,7 +1389,9 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
>
|
||||
{selectedIds.length > 0
|
||||
? `一键查询已选(${selectedIds.length})`
|
||||
: '一键查询全部(鱼翅/积分/宝典/换绑)'}
|
||||
: hasActiveFilter
|
||||
? '一键查询筛选结果(鱼翅/积分/宝典/换绑)'
|
||||
: '一键查询全部(鱼翅/积分/宝典/换绑)'}
|
||||
</Button>
|
||||
<Button
|
||||
icon={<SafetyCertificateOutlined />}
|
||||
@@ -1118,6 +1434,36 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
>
|
||||
导出 CSV{selectedIds.length > 0 ? `(已选 ${selectedIds.length})` : ''}
|
||||
</Button>
|
||||
<Dropdown
|
||||
trigger={['click']}
|
||||
menu={{
|
||||
items: [
|
||||
{
|
||||
key: 'imported',
|
||||
label: `导入未查询(${pendingQuery.importedIds.length})`,
|
||||
disabled: pendingQuery.importedIds.length === 0,
|
||||
onClick: () => void handleOneClickQuery(pendingQuery.importedIds),
|
||||
},
|
||||
{
|
||||
key: 'stale',
|
||||
label: `重登待重查(${pendingStaleCount})`,
|
||||
disabled: pendingStaleCount === 0,
|
||||
onClick: () => void handleOneClickQuery(pendingQuery.staleIds),
|
||||
},
|
||||
],
|
||||
}}
|
||||
>
|
||||
<Tooltip title="重登成功后点这里,只回查重新登录的那批账号">
|
||||
<Button
|
||||
icon={<SyncOutlined />}
|
||||
loading={queryStarting}
|
||||
disabled={pendingTotal === 0}
|
||||
onClick={() => void handleQueryPending()}
|
||||
>
|
||||
只查待查询({pendingTotal})
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Dropdown>
|
||||
</Space>
|
||||
|
||||
<Space wrap size={8}>
|
||||
@@ -1184,6 +1530,16 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
}}
|
||||
/>
|
||||
<Space size={8}>
|
||||
<Select
|
||||
size="small"
|
||||
value={dataStateFilter}
|
||||
options={DATA_STATE_OPTIONS}
|
||||
style={{ width: 150 }}
|
||||
onChange={(val) => {
|
||||
setDataStateFilter((val || '') as DataStateFilterValue);
|
||||
setAccountPage(1);
|
||||
}}
|
||||
/>
|
||||
<Input.Search
|
||||
allowClear
|
||||
placeholder="搜索账号名 / UID / 昵称 / 标签 / 角色"
|
||||
@@ -1209,7 +1565,7 @@ export default function DouyuQueryWorkbenchPage() {
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
dataSource={accounts}
|
||||
scroll={{ x: 1680 }}
|
||||
scroll={{ x: 1820 }}
|
||||
rowSelection={{
|
||||
selectedRowKeys: selectedIds,
|
||||
preserveSelectedRowKeys: true,
|
||||
|
||||
Reference in New Issue
Block a user