diff --git a/vehicle-data-platform/apps/web/src/App.tsx b/vehicle-data-platform/apps/web/src/App.tsx index 21b3b853..645229e0 100644 --- a/vehicle-data-platform/apps/web/src/App.tsx +++ b/vehicle-data-platform/apps/web/src/App.tsx @@ -292,6 +292,19 @@ export default function App() { replaceHash('history', nextVin, nextProtocol); }; + const openHistoryWithFilters = (filters: Record = {}) => { + const nextFilters = normalizeHistoryFilterValues(filters); + const nextVin = nextFilters.keyword?.trim() || analysisVin; + const nextProtocol = nextFilters.protocol?.trim() ?? activeProtocol; + setAnalysisVin(nextVin); + setActiveProtocol(nextProtocol); + setHistoryTab('location'); + setHistoryFilters({ ...nextFilters, keyword: nextVin, protocol: nextProtocol }); + setActivePage('history'); + const { keyword, protocol, ...restFilters } = nextFilters; + replaceHash('history', keyword ?? nextVin, protocol ?? nextProtocol, restFilters); + }; + const openRawForVehicle = (vin: string, protocol?: string) => { const nextVin = vin.trim(); const nextProtocol = protocol?.trim() ?? activeProtocol; @@ -350,7 +363,7 @@ export default function App() { realtime: , detail: , history: , - mileage: , + mileage: , quality: setLinkIssueCount(health.linkHealth.filter((item) => item.status !== 'ok').length)} onFiltersChange={updateQualityFilters} initialFilters={qualityFilters} /> }; diff --git a/vehicle-data-platform/apps/web/src/pages/Mileage.tsx b/vehicle-data-platform/apps/web/src/pages/Mileage.tsx index 3846e3c7..d0d72f8b 100644 --- a/vehicle-data-platform/apps/web/src/pages/Mileage.tsx +++ b/vehicle-data-platform/apps/web/src/pages/Mileage.tsx @@ -36,6 +36,13 @@ function canOpenVehicle(vin?: string) { return Boolean(value && value !== 'unknown'); } +function nextDate(value: string) { + const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim()); + if (!match) return ''; + const date = new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]) + 1)); + return date.toISOString().slice(0, 10); +} + function mileageActionRecommendation(row: DailyMileageRow) { if (row.anomalySeverity) { return { @@ -91,13 +98,15 @@ export function Mileage({ initialProtocol, initialFilters = {}, onFiltersChange, - onOpenVehicle + onOpenVehicle, + onOpenHistory }: { initialVin: string; initialProtocol?: string; initialFilters?: Record; onFiltersChange?: (filters: Record) => void; onOpenVehicle: (vin: string, protocol?: string) => void; + onOpenHistory?: (filters: Record) => void; }) { const [rows, setRows] = useState([]); const [summary, setSummary] = useState(emptySummary); @@ -151,6 +160,17 @@ export function Mileage({ applyFilters(currentVehicleKeyword ? { keyword: currentVehicleKeyword } : {}); }; + const openMileageEvidence = (row: DailyMileageRow) => { + const dateFrom = row.date?.trim() ?? ''; + const dateTo = nextDate(dateFrom); + onOpenHistory?.({ + keyword: row.vin, + protocol: row.source, + ...(dateFrom ? { dateFrom } : {}), + ...(dateTo ? { dateTo } : {}) + }); + }; + useEffect(() => { const nextFilters = mergeInitialFilters(initialVin, initialProtocol, initialFilters); setFilters(nextFilters); @@ -318,9 +338,12 @@ export function Mileage({ }, { title: '操作', - width: 110, + width: 190, render: (_: unknown, row: DailyMileageRow) => ( - + + + + ) } ]} diff --git a/vehicle-data-platform/apps/web/src/test/App.test.tsx b/vehicle-data-platform/apps/web/src/test/App.test.tsx index 7a9e708c..3ba34ca3 100644 --- a/vehicle-data-platform/apps/web/src/test/App.test.tsx +++ b/vehicle-data-platform/apps/web/src/test/App.test.tsx @@ -3931,6 +3931,74 @@ test('opens vehicle service from mileage row with row source evidence', async () }); }); +test('opens same-day trajectory playback from mileage row for evidence review', async () => { + window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-TRACK&protocol=JT808'); + vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => { + const path = String(input); + if (path.includes('/api/ops/health')) { + return { + ok: true, + json: async () => ({ + data: { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + } + if (path.includes('/api/mileage/summary')) { + return { + ok: true, + json: async () => ({ + data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 18.8, averageMileagePerVin: 18.8 }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + } + if (path.includes('/api/mileage/daily')) { + return { + ok: true, + json: async () => ({ + data: { + items: [{ + vin: 'VIN-MILEAGE-TRACK', + plate: '粤A轨迹核', + source: 'JT808', + date: '2026-07-03', + startMileageKm: 200, + endMileageKm: 218.8, + dailyMileageKm: 18.8, + anomalySeverity: 'warning' + }], + total: 1, + limit: 20, + offset: 0 + }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + } + return { + ok: true, + json: async () => ({ + data: { items: [], total: 0, limit: 20, offset: 0 }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + }); + + render(); + + expect(await screen.findByText('VIN-MILEAGE-TRACK')).toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: '核对轨迹' })); + + await waitFor(() => { + expect(window.location.hash).toBe('#/history?keyword=VIN-MILEAGE-TRACK&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04'); + }); +}); + test('shows mileage anomaly action guidance', async () => { window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-ANOMALY&protocol=GB32960'); vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {