发布(0.4.1): 优化分配性能与客服数据边界

修复分配页皮肤查询并发慢查询;客服导入账号严格限制为本人名下;分配概览改用真实归属数量;标题区展示版本并提示刷新。
This commit is contained in:
yml
2026-11-26 21:19:11 +08:00
parent 174ae23ac1
commit 7dfc9d725e
15 changed files with 409 additions and 106 deletions
+3
View File
@@ -15,6 +15,8 @@ export interface MessageDeletedResponse extends MessageResponse {
export interface AppInfo {
version: string;
/** 服务端当前前端构建标识;同版本重新构建时也会变化 */
release_id?: string;
}
export interface PageParams {
@@ -477,6 +479,7 @@ export interface AssignmentsSummary {
support_users: SupportUserItem[];
unassigned_count: number;
assigned_count?: number;
orphaned_count?: number;
total_count?: number;
}
@@ -0,0 +1,85 @@
import { useEffect, useState } from 'react';
import { appApi, type AppInfo } from '../api/modules';
const VERSION_POLL_INTERVAL_MS = 30_000;
function versionParts(version: string): number[] {
return (version.match(/\d+/g) || []).map((value) => Number(value));
}
function compareVersions(left: string, right: string): number {
const leftParts = versionParts(left);
const rightParts = versionParts(right);
const length = Math.max(leftParts.length, rightParts.length);
for (let index = 0; index < length; index += 1) {
const leftValue = leftParts[index] ?? 0;
const rightValue = rightParts[index] ?? 0;
if (leftValue !== rightValue) return leftValue - rightValue;
}
return 0;
}
function isNewerRelease(latest: AppInfo, loaded: AppInfo): boolean {
const versionDiff = compareVersions(latest.version, loaded.version);
if (versionDiff !== 0) return versionDiff > 0;
return Boolean(
latest.release_id
&& latest.release_id !== loaded.release_id,
);
}
export function useVersionMonitor() {
const [loaded, setLoaded] = useState<AppInfo | null>(null);
const [latest, setLatest] = useState<AppInfo | null>(null);
const [updateAvailable, setUpdateAvailable] = useState(false);
useEffect(() => {
let cancelled = false;
let inFlight = false;
let baseline: AppInfo | null = null;
const checkVersion = async () => {
if (inFlight) return;
inFlight = true;
try {
const next = await appApi.info();
if (cancelled) return;
if (baseline === null) {
baseline = next;
setLoaded(next);
setLatest(next);
return;
}
setLatest(next);
if (isNewerRelease(next, baseline)) {
setUpdateAvailable(true);
}
} catch {
// 网络抖动不提示版本更新;下一次轮询或窗口聚焦时会重试。
} finally {
inFlight = false;
}
};
void checkVersion();
const timer = window.setInterval(() => {
if (document.visibilityState === 'visible') {
void checkVersion();
}
}, VERSION_POLL_INTERVAL_MS);
const handleFocus = () => {
if (document.visibilityState === 'visible') void checkVersion();
};
document.addEventListener('visibilitychange', handleFocus);
window.addEventListener('focus', handleFocus);
return () => {
cancelled = true;
window.clearInterval(timer);
document.removeEventListener('visibilitychange', handleFocus);
window.removeEventListener('focus', handleFocus);
};
}, []);
return { loaded, latest, updateAvailable };
}
+96 -38
View File
@@ -1,5 +1,16 @@
import { useEffect, useState } from 'react';
import { Layout, Menu, Avatar, Space, Typography, Button, App, Dropdown } from 'antd';
import {
App,
Avatar,
Badge,
Button,
Dropdown,
Layout,
Menu,
Space,
Tag,
Typography,
} from 'antd';
import type { MenuProps } from 'antd';
import {
DashboardOutlined, UserOutlined, LogoutOutlined,
@@ -8,6 +19,7 @@ import {
SunOutlined, MoonOutlined, DesktopOutlined, GiftOutlined, ApartmentOutlined, MobileOutlined, ShoppingCartOutlined,
BookOutlined, GlobalOutlined,
SafetyCertificateOutlined, FileSearchOutlined, RobotOutlined, FileExcelOutlined, ThunderboltOutlined,
ReloadOutlined,
} from '@ant-design/icons';
import { useNavigate, useLocation, Outlet } from 'react-router-dom';
import { getUser, clearAuth, type AuthUser } from '../store/auth';
@@ -15,7 +27,7 @@ import { authApi } from '../api/modules';
import { type ThemeMode } from '../store/theme';
import { useTheme } from '../store/useTheme';
import { usePermissions } from '../hooks/usePermissions';
import { useAppInfo } from '../hooks/useAppInfo';
import { useVersionMonitor } from '../hooks/useVersionMonitor';
const { Sider, Content } = Layout;
const { Text } = Typography;
@@ -39,7 +51,11 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
const [collapsed, setCollapsed] = useState(false);
const { mode, isDark, setMode } = useTheme();
const { can, canAny } = usePermissions(user);
const appInfo = useAppInfo();
const {
loaded: appInfo,
latest: latestAppInfo,
updateAvailable,
} = useVersionMonitor();
// App.useApp() 的 modal 实例会继承 ConfigProvider 主题(静态 Modal.confirm 不会,暗色模式下是白底)
const { modal } = App.useApp();
@@ -182,10 +198,23 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
});
};
const refreshForUpdate = () => {
modal.confirm({
title: '服务器已有新版本',
content: `当前页面 ${versionText},服务器 ${latestVersionText}。请先刷新页面,避免继续使用旧界面提交数据。`,
okText: '立即刷新',
cancelText: '稍后',
onOk: () => window.location.reload(),
});
};
const siderTheme = isDark ? 'dark' : 'light';
const siderTextColor = isDark ? '#fff' : undefined;
const secondaryTextColor = isDark ? 'rgba(255,255,255,0.65)' : 'rgba(0,0,0,0.45)';
const versionText = appInfo?.version ? `v${appInfo.version}` : 'v--';
const latestVersionText = latestAppInfo?.version
? `v${latestAppInfo.version}`
: versionText;
return (
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
@@ -194,22 +223,72 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
display: 'flex', flexDirection: 'column', height: '100%',
}}>
<div style={{
height: 48, margin: '12px 12px 0', fontSize: 16,
textAlign: 'center', lineHeight: '48px', fontWeight: 'bold',
whiteSpace: 'nowrap', overflow: 'hidden', flexShrink: 0,
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
margin: '12px 12px 0',
display: 'flex',
flexDirection: 'column',
gap: 6,
flexShrink: 0,
color: siderTextColor,
}}>
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>
{collapsed ? <ApartmentOutlined /> : '直播运营后台'}
</span>
<Button
type="text"
size="small"
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
onClick={() => setCollapsed(!collapsed)}
style={{ color: siderTextColor, flexShrink: 0 }}
/>
<div style={{
minHeight: 40,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: 6,
}}>
{collapsed ? (
<Badge dot={updateAvailable}>
<ApartmentOutlined style={{ fontSize: 18 }} />
</Badge>
) : (
<div style={{ minWidth: 0, flex: 1 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 }}>
<span style={{
fontSize: 16,
fontWeight: 'bold',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}>
直播运营后台
</span>
</div>
</div>
)}
<Button
type="text"
size="small"
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
onClick={() => setCollapsed(!collapsed)}
style={{ color: siderTextColor, flexShrink: 0 }}
/>
</div>
{!collapsed ? (
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<Text style={{ color: secondaryTextColor, fontSize: 12 }}>
当前版本
</Text>
<Tag
color={updateAvailable ? 'red' : 'blue'}
style={{ marginInlineEnd: 0, fontSize: 11, lineHeight: '18px' }}
>
{versionText}
</Tag>
</div>
) : null}
{updateAvailable && !collapsed ? (
<Button
block
danger
type="primary"
size="small"
icon={<ReloadOutlined />}
onClick={refreshForUpdate}
>
服务器已更新,请刷新
</Button>
) : null}
</div>
<Menu
theme={siderTheme}
@@ -235,17 +314,6 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
</>
)}
</Space>
{!collapsed && (
<Text style={{
display: 'block',
color: secondaryTextColor,
fontSize: 12,
lineHeight: '20px',
marginBottom: 8,
}}>
当前版本 {versionText}
</Text>
)}
{collapsed ? (
<>
<Space orientation="vertical" style={{ width: '100%' }}>
@@ -270,16 +338,6 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
style={{ color: secondaryTextColor }}
/>
</Space>
<Text style={{
display: 'block',
color: secondaryTextColor,
fontSize: 11,
lineHeight: '18px',
textAlign: 'center',
marginTop: 8,
}}>
{versionText}
</Text>
</>
) : (
<Space style={{ width: '100%', justifyContent: 'space-between' }}>
+9 -5
View File
@@ -211,7 +211,6 @@ export default function AssignmentsPage() {
Object.assign(params, candidateFilters);
} else if (selectedUser) {
params.assigned_user_id = selectedUser.id;
params.assignable_only = true;
}
const data = await accountApi.listPaged(params);
if (requestId !== pagedRequestRef.current) return;
@@ -409,7 +408,9 @@ export default function AssignmentsPage() {
?? 0;
const assignedCount = summary?.assigned_count ?? 0;
const unassignedCount = summary?.unassigned_count ?? 0;
const totalAccountCount = summary?.total_count ?? assignedCount + unassignedCount;
const orphanedCount = summary?.orphaned_count ?? 0;
const totalAccountCount =
summary?.total_count ?? assignedCount + unassignedCount + orphanedCount;
const columns = [
{ title: 'ID', dataIndex: 'id', width: 72 },
@@ -504,7 +505,10 @@ export default function AssignmentsPage() {
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<h2 style={{ margin: 0 }}>账号分配中心</h2>
<Text type="secondary">按生命周期、占用、资产与皮肤能力筛选后定向发放</Text>
<Text type="secondary">
按生命周期、占用、资产与皮肤能力筛选后定向发放
{orphanedCount > 0 ? `;另有 ${orphanedCount} 个账号仍归属已停用客服` : ''}
</Text>
</div>
<Button icon={<ReloadOutlined />} loading={refreshing} onClick={() => void handleRefresh()}>
刷新
@@ -514,7 +518,7 @@ export default function AssignmentsPage() {
<Row gutter={12} style={{ flexShrink: 0 }}>
<Col flex="1 1 180px">
<Card size="small">
<Statistic title="可分配账号" value={totalAccountCount} prefix={<TeamOutlined />} />
<Statistic title="账号总数" value={totalAccountCount} prefix={<TeamOutlined />} />
</Card>
</Col>
<Col flex="1 1 180px">
@@ -746,7 +750,7 @@ export default function AssignmentsPage() {
}
options={(options?.skins || []).map((skin) => ({
value: skin.commodity_id,
label: `${skin.commodity_name} · ${skin.account_count}`,
label: `${skin.commodity_name} · 能力 ${skin.account_count}`,
}))}
/>
<Select