feat(fulfillment): 增加工作台状态事件同步

This commit is contained in:
yml
2026-11-18 10:59:20 +08:00
parent 3a8f12ae43
commit 00c4a268c2
10 changed files with 262 additions and 10 deletions
@@ -242,8 +242,8 @@ export default function PlatformFulfillmentPage() {
const [leaseDurationValue, setLeaseDurationValue] = useState<number | null>(60);
const [savingSettings, setSavingSettings] = useState(false);
const loadTasks = useCallback(async () => {
setLoading(true);
const loadTasks = useCallback(async (silent = false) => {
if (!silent) setLoading(true);
try {
const result = await platformFulfillmentApi.listTasks({
status: status || undefined,
@@ -254,21 +254,21 @@ export default function PlatformFulfillmentPage() {
setRows(result.items);
setTotal(result.pagination.total);
} catch (error) {
message.error(getErrorMessage(error));
if (!silent) message.error(getErrorMessage(error));
} finally {
setLoading(false);
if (!silent) setLoading(false);
}
}, [keyword, page, pageSize, status]);
const loadDetail = useCallback(async (taskId: number) => {
setDetailLoading(true);
const loadDetail = useCallback(async (taskId: number, silent = false) => {
if (!silent) setDetailLoading(true);
try {
const result = await platformFulfillmentApi.getTask(taskId);
setDetail(result);
} catch (error) {
message.error(getErrorMessage(error));
if (!silent) message.error(getErrorMessage(error));
} finally {
setDetailLoading(false);
if (!silent) setDetailLoading(false);
}
}, []);
@@ -276,6 +276,13 @@ export default function PlatformFulfillmentPage() {
void loadTasks();
}, [loadTasks]);
useEffect(() => {
const timer = window.setInterval(() => {
if (document.visibilityState === 'visible') void loadTasks(true);
}, 5000);
return () => window.clearInterval(timer);
}, [loadTasks]);
useEffect(() => {
void platformFulfillmentApi
.getSettings()
@@ -287,6 +294,14 @@ export default function PlatformFulfillmentPage() {
if (selectedId) void loadDetail(selectedId);
}, [loadDetail, selectedId]);
useEffect(() => {
if (!selectedId) return;
const timer = window.setInterval(() => {
if (document.visibilityState === 'visible') void loadDetail(selectedId, true);
}, 3000);
return () => window.clearInterval(timer);
}, [loadDetail, selectedId]);
const selected = detail?.task || null;
const qrValue = selected?.bindTask?.qrUrl || '';