fix(platform): load vehicle context by source

This commit is contained in:
lingniu
2026-07-04 06:41:55 +08:00
parent c70af50cec
commit 2feaf246be
2 changed files with 21 additions and 13 deletions

View File

@@ -31,12 +31,17 @@ export default function App() {
const [currentVehicleLabel, setCurrentVehicleLabel] = useState('');
const [currentVehicleConsistency, setCurrentVehicleConsistency] = useState<VehicleSourceConsistency | undefined>();
const loadVehicleContext = useCallback(async (keyword: string) => {
const loadVehicleContext = useCallback(async (keyword: string, protocol?: string) => {
const lookupKey = keyword.trim();
if (!lookupKey) {
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 resolved = Boolean(overview.vin);
setCurrentVehicleStatus(overview.serviceStatus ?? serviceStatusFromOverview(overview));
@@ -62,7 +67,7 @@ export default function App() {
if (initialRoute.page !== 'detail' || !initialRoute.keyword) {
return;
}
loadVehicleContext(initialRoute.keyword).catch((error) => {
loadVehicleContext(initialRoute.keyword, initialRoute.protocol).catch((error) => {
Toast.error(error instanceof Error ? error.message : '车辆查询失败');
});
}, [initialRoute.keyword, initialRoute.page, loadVehicleContext]);
@@ -169,7 +174,7 @@ export default function App() {
return;
}
try {
const context = await loadVehicleContext(lookupKey);
const context = await loadVehicleContext(lookupKey, nextProtocol);
const resolved = context?.resolved;
const nextKey = context?.nextKey ?? lookupKey;
setActiveVin(nextKey);