feat(platform): link vehicle center workflows

This commit is contained in:
lingniu
2026-07-04 18:13:14 +08:00
parent f840d8be4a
commit b8c8ff35fc
3 changed files with 93 additions and 8 deletions

View File

@@ -454,7 +454,7 @@ export default function App() {
const pages: Record<PageKey, JSX.Element> = {
dashboard: <Dashboard onOpenVehicle={openVehicle} onOpenQuality={openQuality} onOpenMap={openMap} onOpenRealtime={openRealtime} onOpenVehicles={openVehicles} onOpenHistory={openHistoryWithFilters} onOpenMileage={openMileageWithFilters} />,
vehicles: <Vehicles onOpenVehicle={openVehicle} onOpenQuality={openQuality} onFiltersChange={updateVehicleFilters} initialFilters={vehicleFilters} />,
vehicles: <Vehicles onOpenVehicle={openVehicle} onOpenQuality={openQuality} onOpenRealtime={openRealtime} onOpenHistory={openHistoryWithFilters} onFiltersChange={updateVehicleFilters} initialFilters={vehicleFilters} />,
map: <Realtime title="地图态势" description="以车辆服务为中心查看实时位置、在线状态、来源一致性和高德地图接入状态" onOpenVehicle={openVehicle} onOpenHistory={openHistoryForVehicle} onOpenQuality={openQuality} onFiltersChange={updateMapFilters} initialFilters={realtimeFilters} />,
realtime: <Realtime onOpenVehicle={openVehicle} onOpenHistory={openHistoryForVehicle} onOpenQuality={openQuality} onFiltersChange={updateRealtimeFilters} initialFilters={realtimeFilters} />,
detail: <VehicleDetail vin={activeVin} protocol={activeProtocol} platformRelease={platformRelease} onOpenRealtime={openRealtimeForVehicle} onOpenHistory={openHistoryForVehicle} onOpenRaw={openRawForVehicle} onOpenMileage={openMileageForVehicle} onOpenVehicles={openVehicles} onOpenQuality={openQuality} onOpenHistoryEvidence={openHistoryWithFilters} onOpenRawEvidence={openRawWithFilters} onQueryChange={updateVehicleDetailQuery} />,

View File

@@ -31,6 +31,17 @@ function sourceEvidenceText(row: VehicleCoverageRow) {
return `${row.onlineSourceCount}/${row.sourceCount} 来源在线`;
}
function primaryRowProtocol(row: VehicleCoverageRow, fallbackProtocol?: string) {
return (fallbackProtocol || row.sourceStatus?.find((source) => source.online)?.protocol || row.protocols?.[0] || '').trim();
}
function rowWorkflowFilters(row: VehicleCoverageRow, fallbackProtocol?: string) {
return {
keyword: row.vin,
...(primaryRowProtocol(row, fallbackProtocol) ? { protocol: primaryRowProtocol(row, fallbackProtocol) } : {})
};
}
function vehicleArchiveCompleteness(row: VehicleCoverageRow) {
const fields = [row.vin, row.plate, row.phone, row.oem];
const completed = fields.filter((item) => Boolean(String(item ?? '').trim())).length;
@@ -238,11 +249,15 @@ async function copyVehicleShareURL() {
export function Vehicles({
onOpenVehicle,
onOpenQuality,
onOpenRealtime,
onOpenHistory,
onFiltersChange,
initialFilters = {}
}: {
onOpenVehicle: (vin: string, protocol?: string) => void;
onOpenQuality?: (filters: Record<string, string>) => void;
onOpenRealtime?: (filters: Record<string, string>) => void;
onOpenHistory?: (filters: Record<string, string>) => void;
onFiltersChange?: (filters: Record<string, string>) => void;
initialFilters?: Record<string, string>;
}) {
@@ -472,16 +487,18 @@ export function Vehicles({
{ title: '绑定', width: 90, render: (_: unknown, row: VehicleCoverageRow) => <Tag color={row.bindingStatus === 'bound' ? 'green' : 'orange'}>{row.bindingStatus === 'bound' ? '已绑定' : '未绑定'}</Tag> },
{
title: '操作',
width: 190,
width: 300,
render: (_: unknown, row: VehicleCoverageRow) => (
<Space>
<Button onClick={() => onOpenVehicle(row.vin, filters.protocol)}></Button>
<Button disabled={!row.vin || !onOpenQuality} onClick={() => onOpenQuality?.({ keyword: row.vin, ...(filters.protocol ? { protocol: filters.protocol } : {}) })}></Button>
<Space wrap>
<Button disabled={!row.vin || !onOpenRealtime} onClick={() => onOpenRealtime?.(rowWorkflowFilters(row, filters.protocol))}></Button>
<Button disabled={!row.vin || !onOpenHistory} onClick={() => onOpenHistory?.(rowWorkflowFilters(row, filters.protocol))}></Button>
<Button onClick={() => onOpenVehicle(row.vin, primaryRowProtocol(row, filters.protocol))}></Button>
<Button disabled={!row.vin || !onOpenQuality} onClick={() => onOpenQuality?.(rowWorkflowFilters(row, filters.protocol))}></Button>
</Space>
)
}
],
[filters, onOpenQuality, onOpenVehicle]
[filters, onOpenHistory, onOpenQuality, onOpenRealtime, onOpenVehicle]
);
return (

View File

@@ -9327,13 +9327,81 @@ test('opens vehicle service from source-filtered vehicle list with source eviden
render(<App />);
expect(await screen.findByText('VIN-LIST-JT808')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
fireEvent.click(screen.getByRole('button', { name: '服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-LIST-JT808&protocol=JT808');
});
});
test('opens realtime and trajectory from vehicle center row', async () => {
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-LIST-WORKFLOW',
plate: '粤A列表流',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
missingProtocols: [],
sourceStatus: [
{ protocol: 'GB32960', online: false, lastSeen: '2026-07-03 18:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
window.history.replaceState(null, '', '/#/vehicles');
render(<App />);
expect(await screen.findByText('VIN-LIST-WORKFLOW')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '实时' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/realtime?keyword=VIN-LIST-WORKFLOW&protocol=JT808');
});
cleanup();
window.history.replaceState(null, '', '/#/vehicles');
render(<App />);
expect(await screen.findByText('VIN-LIST-WORKFLOW')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '轨迹' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=VIN-LIST-WORKFLOW&protocol=JT808');
});
});
test('opens quality issues from source-filtered vehicle list with source evidence', async () => {
window.history.replaceState(null, '', '/#/vehicles?protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
@@ -9429,7 +9497,7 @@ test('opens quality issues from source-filtered vehicle list with source evidenc
render(<App />);
expect(await screen.findByText('VIN-LIST-QUALITY')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '质量问题' }));
fireEvent.click(screen.getByRole('button', { name: '告警' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/alert-events?keyword=VIN-LIST-QUALITY&protocol=JT808');