fix(platform): keep dashboard metrics on preview failures
This commit is contained in:
@@ -127,21 +127,21 @@ export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { on
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([
|
||||
api.dashboardSummary(),
|
||||
api.vehicleServiceSummary(),
|
||||
api.vehicleCoverage(new URLSearchParams({ limit: '8' })),
|
||||
api.vehicleRealtime(new URLSearchParams({ limit: '8' })),
|
||||
api.qualityIssues(new URLSearchParams({ limit: '5' }))
|
||||
])
|
||||
.then(([nextSummary, nextServiceSummary, coveragePage, locationPage, qualityPage]) => {
|
||||
setSummary(nextSummary);
|
||||
setServiceSummary(nextServiceSummary);
|
||||
setCoverage(coveragePage.items);
|
||||
setLocations(locationPage.items);
|
||||
setQualityIssues(qualityPage.items);
|
||||
const tasks = [
|
||||
api.dashboardSummary().then(setSummary),
|
||||
api.vehicleServiceSummary().then(setServiceSummary),
|
||||
api.vehicleCoverage(new URLSearchParams({ limit: '8' })).then((page) => setCoverage(page.items)),
|
||||
api.vehicleRealtime(new URLSearchParams({ limit: '8' })).then((page) => setLocations(page.items)),
|
||||
api.qualityIssues(new URLSearchParams({ limit: '5' })).then((page) => setQualityIssues(page.items))
|
||||
];
|
||||
Promise.allSettled(tasks)
|
||||
.then((results) => {
|
||||
const failed = results.find((result) => result.status === 'rejected');
|
||||
if (failed?.status === 'rejected') {
|
||||
const reason = failed.reason;
|
||||
Toast.error(reason instanceof Error ? reason.message : '总览数据加载失败');
|
||||
}
|
||||
})
|
||||
.catch((error: Error) => Toast.error(error.message))
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user