发布(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
@@ -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 };
}