feat(platform-web): keep realtime source in vehicle links
This commit is contained in:
@@ -11,7 +11,7 @@ function canOpenVehicle(vin?: string) {
|
|||||||
return Boolean(value && value !== 'unknown');
|
return Boolean(value && value !== 'unknown');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string) => void }) {
|
export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string, protocol?: string) => void }) {
|
||||||
const [rows, setRows] = useState<VehicleRealtimeRow[]>([]);
|
const [rows, setRows] = useState<VehicleRealtimeRow[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
@@ -105,7 +105,7 @@ export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string) => vo
|
|||||||
title: '操作',
|
title: '操作',
|
||||||
width: 110,
|
width: 110,
|
||||||
render: (_: unknown, row: VehicleRealtimeRow) => (
|
render: (_: unknown, row: VehicleRealtimeRow) => (
|
||||||
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin)}>车辆服务</Button>
|
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, row.primaryProtocol)}>车辆服务</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
|
|||||||
@@ -168,3 +168,78 @@ test('keeps row protocol when opening vehicle service from history results', asy
|
|||||||
expect(window.location.hash).toBe('#/detail?keyword=VIN-JT808-001&protocol=JT808');
|
expect(window.location.hash).toBe('#/detail?keyword=VIN-JT808-001&protocol=JT808');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('keeps primary protocol when opening vehicle service from realtime vehicles', async () => {
|
||||||
|
window.history.replaceState(null, '', '/#/realtime');
|
||||||
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||||
|
const path = String(input);
|
||||||
|
if (path.includes('/api/realtime/vehicles')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
items: [{
|
||||||
|
vin: 'VIN-MQTT-001',
|
||||||
|
plate: '川AHTWO1',
|
||||||
|
phone: '',
|
||||||
|
oem: '宇通',
|
||||||
|
protocols: ['GB32960', 'YUTONG_MQTT'],
|
||||||
|
sourceCount: 2,
|
||||||
|
onlineSourceCount: 1,
|
||||||
|
online: true,
|
||||||
|
primaryProtocol: 'YUTONG_MQTT',
|
||||||
|
longitude: 113.2,
|
||||||
|
latitude: 23.1,
|
||||||
|
speedKmh: 30,
|
||||||
|
socPercent: 78,
|
||||||
|
totalMileageKm: 119925,
|
||||||
|
lastSeen: '2026-07-03 20:12:10'
|
||||||
|
}],
|
||||||
|
total: 1,
|
||||||
|
limit: 50,
|
||||||
|
offset: 0
|
||||||
|
},
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
if (path.includes('/api/vehicles/resolve')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
lookupKey: 'VIN-MQTT-001',
|
||||||
|
resolved: true,
|
||||||
|
vin: 'VIN-MQTT-001',
|
||||||
|
plate: '川AHTWO1',
|
||||||
|
phone: '',
|
||||||
|
oem: '宇通',
|
||||||
|
protocols: ['GB32960', 'YUTONG_MQTT'],
|
||||||
|
online: true,
|
||||||
|
lastSeen: '2026-07-03 20:12:10'
|
||||||
|
},
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: { items: [], total: 0, limit: 10, offset: 0 },
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<App />);
|
||||||
|
|
||||||
|
expect(await screen.findByText('VIN-MQTT-001')).toBeInTheDocument();
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(window.location.hash).toBe('#/detail?keyword=VIN-MQTT-001&protocol=YUTONG_MQTT');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user