perf: reuse mileage monitoring snapshots
This commit is contained in:
@@ -565,7 +565,7 @@ export default function MonitoringView() {
|
||||
}, [filterTargetNames]);
|
||||
|
||||
// 加载首页数据
|
||||
const loadFirstPage = useCallback((showPageLoading = true) => {
|
||||
const loadFirstPage = useCallback((showPageLoading = true, force = false) => {
|
||||
if (showPageLoading) setPageLoading(true);
|
||||
setPageError(null);
|
||||
return fetchMonitoring({
|
||||
@@ -589,6 +589,7 @@ export default function MonitoringView() {
|
||||
endDate: rangeEnd || undefined,
|
||||
brands: filterBrands.length > 0 ? filterBrands : undefined,
|
||||
sourcePriority,
|
||||
force,
|
||||
}).then(d => {
|
||||
setVehicles(d.vehicles);
|
||||
setStats(d.stats);
|
||||
@@ -613,7 +614,7 @@ export default function MonitoringView() {
|
||||
if (manualRefreshing) return;
|
||||
setManualRefreshing(true);
|
||||
try {
|
||||
await loadFirstPage(false);
|
||||
await loadFirstPage(false, true);
|
||||
} finally {
|
||||
setManualRefreshing(false);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ export async function fetchMonitoring(params?: {
|
||||
endDate?: string;
|
||||
brands?: string[];
|
||||
sourcePriority?: MileageSourceGroup[];
|
||||
force?: boolean;
|
||||
}): Promise<MonitoringData> {
|
||||
const query = new URLSearchParams();
|
||||
if (params?.sortBy) query.set('sortBy', params.sortBy);
|
||||
@@ -76,6 +77,7 @@ export async function fetchMonitoring(params?: {
|
||||
if (params?.startDate) query.set('startDate', params.startDate);
|
||||
if (params?.endDate) query.set('endDate', params.endDate);
|
||||
if (params?.sourcePriority?.length) query.set('sourcePriority', params.sourcePriority.join(','));
|
||||
if (params?.force) query.set('force', '1');
|
||||
const qs = query.toString();
|
||||
return fetchJson<MonitoringData>(`${BASE}/monitoring${qs ? `?${qs}` : ''}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user