fix: sync camera & channels
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user