feat(douyu): 支持账号批量撤回并刷新未分配状态
新增按勾选或标签批量撤回账号归属,撤回只处理确实已分配的账号。账号管理和分配管理增加可见时自动刷新、窗口聚焦刷新及手动刷新,解决批量登录完成后未分配账号延迟出现。
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
import { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import {
|
||||
Card, Table, Button, Select, Input, Tag, Row, Col, Statistic,
|
||||
Space, Tabs, Typography, Badge, theme, Tooltip,
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
import { message } from '../utils/antdMessage';
|
||||
import {
|
||||
UserOutlined, CheckCircleOutlined, TeamOutlined,
|
||||
SwapOutlined, ClearOutlined, UsergroupAddOutlined,
|
||||
SwapOutlined, ClearOutlined, UsergroupAddOutlined, ReloadOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import {
|
||||
accountApi,
|
||||
@@ -36,6 +36,9 @@ export default function AssignmentsPage() {
|
||||
const [filterTag, setFilterTag] = useState<string | undefined>(undefined);
|
||||
const [activeTab, setActiveTab] = useState<'unassigned' | 'assigned'>('unassigned');
|
||||
const [assigning, setAssigning] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const summaryRequestRef = useRef(0);
|
||||
const pagedRequestRef = useRef(0);
|
||||
const [pageSize, setPageSize] = useState(() => {
|
||||
const v = localStorage.getItem('assignment_page_size');
|
||||
return v ? Number(v) || 15 : 15;
|
||||
@@ -43,14 +46,18 @@ export default function AssignmentsPage() {
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
|
||||
// 加载分配概览统计
|
||||
const loadSummary = useCallback(async () => {
|
||||
const loadSummary = useCallback(async (silent = false) => {
|
||||
const requestId = ++summaryRequestRef.current;
|
||||
try {
|
||||
const data = await accountApi.assignmentsSummary();
|
||||
if (requestId !== summaryRequestRef.current) return [];
|
||||
setSummary(data);
|
||||
setSupportUsers(data.support_users);
|
||||
return data.support_users;
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
if (requestId === summaryRequestRef.current && !silent) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}, []);
|
||||
@@ -66,8 +73,9 @@ export default function AssignmentsPage() {
|
||||
}, []);
|
||||
|
||||
// 分页按需加载账号(服务端过滤与分页)
|
||||
const loadPagedAccounts = useCallback(async () => {
|
||||
setTableLoading(true);
|
||||
const loadPagedAccounts = useCallback(async (silent = false) => {
|
||||
const requestId = ++pagedRequestRef.current;
|
||||
if (!silent) setTableLoading(true);
|
||||
try {
|
||||
const params: Parameters<typeof accountApi.listPaged>[0] = {
|
||||
page: currentPage,
|
||||
@@ -87,12 +95,17 @@ export default function AssignmentsPage() {
|
||||
}
|
||||
|
||||
const data = await accountApi.listPaged(params);
|
||||
if (requestId !== pagedRequestRef.current) return;
|
||||
setPagedAccounts(data.items);
|
||||
setTotalCount(data.total);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
if (requestId === pagedRequestRef.current && !silent) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
} finally {
|
||||
setTableLoading(false);
|
||||
if (requestId === pagedRequestRef.current) {
|
||||
setTableLoading(false);
|
||||
}
|
||||
}
|
||||
}, [activeTab, selectedUser, currentPage, pageSize, searchText, filterTag]);
|
||||
|
||||
@@ -115,6 +128,34 @@ export default function AssignmentsPage() {
|
||||
loadPagedAccounts();
|
||||
}, [loadPagedAccounts]);
|
||||
|
||||
useEffect(() => {
|
||||
const refreshVisibleData = () => {
|
||||
if (document.visibilityState !== 'visible') return;
|
||||
void loadSummary(true);
|
||||
void loadPagedAccounts(true);
|
||||
};
|
||||
const timer = window.setInterval(refreshVisibleData, 15000);
|
||||
const handleVisibility = () => {
|
||||
if (document.visibilityState === 'visible') refreshVisibleData();
|
||||
};
|
||||
document.addEventListener('visibilitychange', handleVisibility);
|
||||
window.addEventListener('focus', refreshVisibleData);
|
||||
return () => {
|
||||
window.clearInterval(timer);
|
||||
document.removeEventListener('visibilitychange', handleVisibility);
|
||||
window.removeEventListener('focus', refreshVisibleData);
|
||||
};
|
||||
}, [loadPagedAccounts, loadSummary]);
|
||||
|
||||
const handleRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await Promise.all([loadSummary(), loadPagedAccounts()]);
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 切换客服
|
||||
const handleSelectUser = (user: SupportUserItem) => {
|
||||
setSelectedUser(user);
|
||||
@@ -249,7 +290,12 @@ export default function AssignmentsPage() {
|
||||
|
||||
return (
|
||||
<div style={{ height: '100%', display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
<h2 style={{ margin: 0, flexShrink: 0 }}>分配管理</h2>
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||
<h2 style={{ margin: 0 }}>分配管理</h2>
|
||||
<Button icon={<ReloadOutlined />} loading={refreshing} onClick={handleRefresh}>
|
||||
刷新
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={12} style={{ flexShrink: 0 }}>
|
||||
@@ -270,12 +316,14 @@ export default function AssignmentsPage() {
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Card size="small">
|
||||
<Statistic
|
||||
title="未分配"
|
||||
value={unassignedCount}
|
||||
styles={{ content: { color: token.colorError } }}
|
||||
prefix={<SwapOutlined />}
|
||||
/>
|
||||
<Tooltip title="仅统计持 CK 且 CK 未判失效、未停用/归档的账号。批量登录成功写入 CK 后会自动进入;本页每 15 秒刷新一次。">
|
||||
<Statistic
|
||||
title="未分配"
|
||||
value={unassignedCount}
|
||||
styles={{ content: { color: token.colorError } }}
|
||||
prefix={<SwapOutlined />}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
|
||||
Reference in New Issue
Block a user