fix(platform): load vehicle context by source
This commit is contained in:
@@ -31,12 +31,17 @@ export default function App() {
|
|||||||
const [currentVehicleLabel, setCurrentVehicleLabel] = useState('');
|
const [currentVehicleLabel, setCurrentVehicleLabel] = useState('');
|
||||||
const [currentVehicleConsistency, setCurrentVehicleConsistency] = useState<VehicleSourceConsistency | undefined>();
|
const [currentVehicleConsistency, setCurrentVehicleConsistency] = useState<VehicleSourceConsistency | undefined>();
|
||||||
|
|
||||||
const loadVehicleContext = useCallback(async (keyword: string) => {
|
const loadVehicleContext = useCallback(async (keyword: string, protocol?: string) => {
|
||||||
const lookupKey = keyword.trim();
|
const lookupKey = keyword.trim();
|
||||||
if (!lookupKey) {
|
if (!lookupKey) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const overview = await api.vehicleServiceOverview(new URLSearchParams({ keyword: lookupKey }));
|
const params = new URLSearchParams({ keyword: lookupKey });
|
||||||
|
const source = protocol?.trim();
|
||||||
|
if (source) {
|
||||||
|
params.set('protocol', source);
|
||||||
|
}
|
||||||
|
const overview = await api.vehicleServiceOverview(params);
|
||||||
const nextKey = overview.vin || lookupKey;
|
const nextKey = overview.vin || lookupKey;
|
||||||
const resolved = Boolean(overview.vin);
|
const resolved = Boolean(overview.vin);
|
||||||
setCurrentVehicleStatus(overview.serviceStatus ?? serviceStatusFromOverview(overview));
|
setCurrentVehicleStatus(overview.serviceStatus ?? serviceStatusFromOverview(overview));
|
||||||
@@ -62,7 +67,7 @@ export default function App() {
|
|||||||
if (initialRoute.page !== 'detail' || !initialRoute.keyword) {
|
if (initialRoute.page !== 'detail' || !initialRoute.keyword) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loadVehicleContext(initialRoute.keyword).catch((error) => {
|
loadVehicleContext(initialRoute.keyword, initialRoute.protocol).catch((error) => {
|
||||||
Toast.error(error instanceof Error ? error.message : '车辆查询失败');
|
Toast.error(error instanceof Error ? error.message : '车辆查询失败');
|
||||||
});
|
});
|
||||||
}, [initialRoute.keyword, initialRoute.page, loadVehicleContext]);
|
}, [initialRoute.keyword, initialRoute.page, loadVehicleContext]);
|
||||||
@@ -169,7 +174,7 @@ export default function App() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const context = await loadVehicleContext(lookupKey);
|
const context = await loadVehicleContext(lookupKey, nextProtocol);
|
||||||
const resolved = context?.resolved;
|
const resolved = context?.resolved;
|
||||||
const nextKey = context?.nextKey ?? lookupKey;
|
const nextKey = context?.nextKey ?? lookupKey;
|
||||||
setActiveVin(nextKey);
|
setActiveVin(nextKey);
|
||||||
|
|||||||
@@ -2195,7 +2195,7 @@ test('opens current vehicle service from history header with current source evid
|
|||||||
|
|
||||||
test('opens vehicle service from realtime vehicles with primary source evidence', async () => {
|
test('opens vehicle service from realtime vehicles with primary source evidence', async () => {
|
||||||
window.history.replaceState(null, '', '/#/realtime');
|
window.history.replaceState(null, '', '/#/realtime');
|
||||||
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||||
const path = String(input);
|
const path = String(input);
|
||||||
if (path.includes('/api/realtime/vehicles')) {
|
if (path.includes('/api/realtime/vehicles')) {
|
||||||
return {
|
return {
|
||||||
@@ -2228,20 +2228,22 @@ test('opens vehicle service from realtime vehicles with primary source evidence'
|
|||||||
})
|
})
|
||||||
} as Response;
|
} as Response;
|
||||||
}
|
}
|
||||||
if (path.includes('/api/vehicles/resolve')) {
|
if (path.includes('/api/vehicle-service/overview')) {
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
json: async () => ({
|
json: async () => ({
|
||||||
data: {
|
data: {
|
||||||
lookupKey: 'VIN-MQTT-001',
|
|
||||||
resolved: true,
|
|
||||||
vin: 'VIN-MQTT-001',
|
vin: 'VIN-MQTT-001',
|
||||||
plate: '川AHTWO1',
|
plate: '川AHTWO1',
|
||||||
phone: '',
|
sourceCount: 2,
|
||||||
oem: '宇通',
|
onlineSourceCount: 1,
|
||||||
protocols: ['GB32960', 'YUTONG_MQTT'],
|
coverageStatus: 'online',
|
||||||
online: true,
|
primaryProtocol: 'YUTONG_MQTT',
|
||||||
lastSeen: '2026-07-03 20:12:10'
|
lastSeen: '2026-07-03 20:12:10',
|
||||||
|
historyCount: 0,
|
||||||
|
rawCount: 0,
|
||||||
|
mileageCount: 0,
|
||||||
|
qualityIssueCount: 0
|
||||||
},
|
},
|
||||||
traceId: 'trace-test',
|
traceId: 'trace-test',
|
||||||
timestamp: 1783094400000
|
timestamp: 1783094400000
|
||||||
@@ -2266,6 +2268,7 @@ test('opens vehicle service from realtime vehicles with primary source evidence'
|
|||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(window.location.hash).toBe('#/detail?keyword=VIN-MQTT-001&protocol=YUTONG_MQTT');
|
expect(window.location.hash).toBe('#/detail?keyword=VIN-MQTT-001&protocol=YUTONG_MQTT');
|
||||||
});
|
});
|
||||||
|
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=VIN-MQTT-001&protocol=YUTONG_MQTT'), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows canonical service status in realtime vehicles', async () => {
|
test('shows canonical service status in realtime vehicles', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user