fix: sync camera & channels

This commit is contained in:
yangsy
2025-12-01 15:20:11 +08:00
parent 168d11c71b
commit b4e2926f08

View File

@@ -70,15 +70,30 @@ const { mutate: syncCamera, isPending: cameraSyncing } = useMutation({
const stationCodes = Object.entries(stationSelection.value) const stationCodes = Object.entries(stationSelection.value)
.filter(([, selected]) => selected) .filter(([, selected]) => selected)
.map(([code]) => code); .map(([code]) => code);
for (const stationCode of stationCodes) { const results = await Promise.allSettled(stationCodes.map((stationCode) => syncCameraApi({ stationCode })));
await syncCameraApi({ stationCode }); return results.map((result, index) => ({ ...result, stationCode: stationCodes[index] }));
await sleep(5000);
}
}, },
onSuccess: () => { onSuccess: (results) => {
window.$message.success('摄像机同步成功'); console.log(results);
pollingStore.disablePolling(); const successCount = results.filter((result) => result.status === 'fulfilled').length;
pollingStore.enablePolling(); 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(); onFinish();
}, },
onError: (error) => { onError: (error) => {
@@ -92,12 +107,25 @@ const { mutate: syncNvrChannels, isPending: nvrChannelsSyncing } = useMutation({
const stationCodes = Object.entries(stationSelection.value) const stationCodes = Object.entries(stationSelection.value)
.filter(([, selected]) => selected) .filter(([, selected]) => selected)
.map(([code]) => code); .map(([code]) => code);
for (const stationCode of stationCodes) { const results = await Promise.allSettled(stationCodes.map((stationCode) => syncNvrChannelsApi({ stationCode })));
await syncNvrChannelsApi({ stationCode }); return results.map((result, index) => ({ ...result, stationCode: stationCodes[index] }));
}
}, },
onSuccess: () => { onSuccess: (results) => {
window.$message.info('正在同步录像机通道,可能需要一些时间'); 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(); onFinish();
}, },
onError: (error) => { onError: (error) => {