feat(platform): resolve vehicle identity before navigation
This commit is contained in:
@@ -37,13 +37,22 @@ export default function App() {
|
||||
return () => window.clearInterval(timer);
|
||||
}, [refreshOpsHealth]);
|
||||
|
||||
const openVehicle = (vin: string) => {
|
||||
const nextVin = vin.trim();
|
||||
if (!nextVin) {
|
||||
const openVehicle = async (keyword: string) => {
|
||||
const lookupKey = keyword.trim();
|
||||
if (!lookupKey) {
|
||||
return;
|
||||
}
|
||||
setActiveVin(nextVin);
|
||||
setActivePage('detail');
|
||||
try {
|
||||
const resolved = await api.vehicleResolve(new URLSearchParams({ keyword: lookupKey }));
|
||||
const nextKey = resolved.resolved && resolved.vin ? resolved.vin : lookupKey;
|
||||
setActiveVin(nextKey);
|
||||
setActivePage('detail');
|
||||
if (!resolved.resolved) {
|
||||
Toast.warning('未匹配到车辆身份,已打开问题排查视图');
|
||||
}
|
||||
} catch (error) {
|
||||
Toast.error(error instanceof Error ? error.message : '车辆查询失败');
|
||||
}
|
||||
};
|
||||
|
||||
const openHistoryForVehicle = (vin: string) => {
|
||||
|
||||
@@ -38,6 +38,32 @@ test('rawFramesQuery posts structured JSON instead of URL query strings', async
|
||||
});
|
||||
});
|
||||
|
||||
test('vehicleResolve sends keyword to the identity resolution endpoint', async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
lookupKey: '粤AG18312',
|
||||
resolved: true,
|
||||
vin: 'LB9A32A24R0LS1426',
|
||||
plate: '粤AG18312',
|
||||
phone: '13307795425',
|
||||
oem: 'G7s',
|
||||
protocols: ['GB32960', 'JT808'],
|
||||
online: true,
|
||||
lastSeen: '2026-07-03 20:12:10'
|
||||
},
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response);
|
||||
|
||||
const result = await api.vehicleResolve(new URLSearchParams({ keyword: '粤AG18312' }));
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/vehicles/resolve?keyword=%E7%B2%A4AG18312', undefined);
|
||||
expect(result.vin).toBe('LB9A32A24R0LS1426');
|
||||
});
|
||||
|
||||
test('api errors include backend message, detail, and trace id', async () => {
|
||||
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
|
||||
ok: false,
|
||||
|
||||
@@ -13,6 +13,7 @@ import type {
|
||||
VehicleRealtimeRow,
|
||||
VehicleCoverageRow,
|
||||
VehicleDetail,
|
||||
VehicleIdentityResolution,
|
||||
VehicleRow
|
||||
} from './types';
|
||||
|
||||
@@ -71,6 +72,7 @@ function withTraceID(message: string, traceID?: string) {
|
||||
export const api = {
|
||||
dashboardSummary: () => request<DashboardSummary>('/api/dashboard/summary'),
|
||||
vehicles: (params = new URLSearchParams()) => request<Page<VehicleRow>>(`/api/vehicles?${params.toString()}`),
|
||||
vehicleResolve: (params = new URLSearchParams()) => request<VehicleIdentityResolution>(`/api/vehicles/resolve?${params.toString()}`),
|
||||
vehicleCoverage: (params = new URLSearchParams()) => request<Page<VehicleCoverageRow>>(`/api/vehicles/coverage?${params.toString()}`),
|
||||
vehicleDetail: (params = new URLSearchParams()) => request<VehicleDetail>(`/api/vehicles/detail?${params.toString()}`),
|
||||
vehicleRealtime: (params = new URLSearchParams()) => request<Page<VehicleRealtimeRow>>(`/api/realtime/vehicles?${params.toString()}`),
|
||||
|
||||
@@ -51,6 +51,18 @@ export interface VehicleCoverageRow {
|
||||
bindingStatus: string;
|
||||
}
|
||||
|
||||
export interface VehicleIdentityResolution {
|
||||
lookupKey: string;
|
||||
resolved: boolean;
|
||||
vin: string;
|
||||
plate: string;
|
||||
phone: string;
|
||||
oem: string;
|
||||
protocols: string[];
|
||||
online: boolean;
|
||||
lastSeen: string;
|
||||
}
|
||||
|
||||
export interface VehicleDetail {
|
||||
vin: string;
|
||||
lookupKey: string;
|
||||
|
||||
@@ -41,10 +41,11 @@ export function AppShell({
|
||||
activePage: PageKey;
|
||||
linkIssueCount: number | null;
|
||||
onChange: (page: PageKey) => void;
|
||||
onVehicleSearch: (keyword: string) => void;
|
||||
onVehicleSearch: (keyword: string) => void | Promise<void>;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const [keyword, setKeyword] = useState('');
|
||||
const [searching, setSearching] = useState(false);
|
||||
|
||||
const search = () => {
|
||||
const value = keyword.trim();
|
||||
@@ -52,7 +53,8 @@ export function AppShell({
|
||||
Toast.warning('请输入 VIN / 车牌 / 手机号');
|
||||
return;
|
||||
}
|
||||
onVehicleSearch(value);
|
||||
setSearching(true);
|
||||
Promise.resolve(onVehicleSearch(value)).finally(() => setSearching(false));
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -81,7 +83,7 @@ export function AppShell({
|
||||
onEnterPress={search}
|
||||
style={{ width: 320 }}
|
||||
/>
|
||||
<Button theme="solid" type="primary" onClick={search}>查询车辆</Button>
|
||||
<Button theme="solid" type="primary" loading={searching} onClick={search}>查询车辆</Button>
|
||||
</Space>
|
||||
<Space spacing={12}>
|
||||
<Tag color="blue">生产环境</Tag>
|
||||
|
||||
Reference in New Issue
Block a user