From b4e2926f088419b0ef1d7c7026359e1cb0d4d497 Mon Sep 17 00:00:00 2001 From: yangsy Date: Mon, 1 Dec 2025 15:20:11 +0800 Subject: [PATCH] fix: sync camera & channels --- src/pages/station-page.vue | 54 +++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/pages/station-page.vue b/src/pages/station-page.vue index 7126a53..3b69d7d 100644 --- a/src/pages/station-page.vue +++ b/src/pages/station-page.vue @@ -70,15 +70,30 @@ const { mutate: syncCamera, isPending: cameraSyncing } = useMutation({ const stationCodes = Object.entries(stationSelection.value) .filter(([, selected]) => selected) .map(([code]) => code); - for (const stationCode of stationCodes) { - await syncCameraApi({ stationCode }); - await sleep(5000); - } + const results = await Promise.allSettled(stationCodes.map((stationCode) => syncCameraApi({ stationCode }))); + return results.map((result, index) => ({ ...result, stationCode: stationCodes[index] })); }, - onSuccess: () => { - window.$message.success('摄像机同步成功'); - pollingStore.disablePolling(); - pollingStore.enablePolling(); + onSuccess: (results) => { + console.log(results); + const successCount = results.filter((result) => result.status === 'fulfilled').length; + const failures = results.filter((result) => result.status === 'rejected'); + const failureCount = failures.length; + if (failureCount > 0) { + const failedStations = failures.map((f) => stationList.value.find((s) => s.code === f.stationCode)?.name).join('、'); + if (successCount === 0) { + window.$message.error('摄像机同步全部失败'); + window.$message.error(`${failedStations}`); + } else { + window.$message.warning(`摄像机同步完成:成功${successCount}个车站,失败${failureCount}个车站`); + window.$message.warning(`${failedStations}`); + } + } else { + window.$message.success('摄像机同步成功'); + } + if (successCount > 0) { + pollingStore.disablePolling(); + pollingStore.enablePolling(); + } onFinish(); }, onError: (error) => { @@ -92,12 +107,25 @@ const { mutate: syncNvrChannels, isPending: nvrChannelsSyncing } = useMutation({ const stationCodes = Object.entries(stationSelection.value) .filter(([, selected]) => selected) .map(([code]) => code); - for (const stationCode of stationCodes) { - await syncNvrChannelsApi({ stationCode }); - } + const results = await Promise.allSettled(stationCodes.map((stationCode) => syncNvrChannelsApi({ stationCode }))); + return results.map((result, index) => ({ ...result, stationCode: stationCodes[index] })); }, - onSuccess: () => { - window.$message.info('正在同步录像机通道,可能需要一些时间'); + onSuccess: (results) => { + const successCount = results.filter((result) => result.status === 'fulfilled').length; + const failures = results.filter((result) => result.status === 'rejected'); + const failureCount = failures.length; + if (failureCount > 0) { + const failedStations = failures.map((f) => stationList.value.find((s) => s.code === f.stationCode)?.name).join('、'); + if (successCount === 0) { + window.$message.error('录像机通道同步全部失败'); + window.$message.error(`${failedStations}`); + } else { + window.$message.warning(`录像机通道同步完成:成功${successCount}个车站,失败${failureCount}个车站`); + window.$message.warning(`${failedStations}`); + } + } else { + window.$message.success('录像机通道同步成功'); + } onFinish(); }, onError: (error) => {