feat(platform): link realtime table map selection

This commit is contained in:
lingniu
2026-07-04 18:07:48 +08:00
parent 483d92719b
commit f840d8be4a
2 changed files with 27 additions and 5 deletions

View File

@@ -353,6 +353,7 @@ export function Realtime({
.slice(0, 5); .slice(0, 5);
const defaultMapRow = mapServiceRows[0] ?? rows.find((row) => isValidCoordinate(row) && canOpenVehicle(row.vin)); const defaultMapRow = mapServiceRows[0] ?? rows.find((row) => isValidCoordinate(row) && canOpenVehicle(row.vin));
const selectedMapRow = rows.find((row, index) => realtimeMapPointId(row, index) === selectedMapPointId) ?? defaultMapRow; const selectedMapRow = rows.find((row, index) => realtimeMapPointId(row, index) === selectedMapPointId) ?? defaultMapRow;
const selectedMapPointKey = selectedMapRow ? realtimeMapPointId(selectedMapRow, rows.indexOf(selectedMapRow)) : selectedMapPointId;
const mapPoints: VehicleMapPoint[] = rows.map((row, index) => ({ const mapPoints: VehicleMapPoint[] = rows.map((row, index) => ({
id: realtimeMapPointId(row, index), id: realtimeMapPointId(row, index),
label: row.plate || row.vin || 'unknown', label: row.plate || row.vin || 'unknown',
@@ -416,6 +417,14 @@ export function Realtime({
amapConfigured, amapConfigured,
sourceIssueRows sourceIssueRows
}), '实时摘要'); }), '实时摘要');
const selectRealtimeRow = (row: VehicleRealtimeRow) => {
const index = rows.indexOf(row);
if (index < 0) return;
setSelectedMapPointId(realtimeMapPointId(row, index));
};
const selectRealtimeMapPoint = (point: VehicleMapPoint) => {
setSelectedMapPointId(point.id);
};
return ( return (
<div className="vp-page"> <div className="vp-page">
@@ -485,8 +494,8 @@ export function Realtime({
<VehicleMap <VehicleMap
points={mapPoints} points={mapPoints}
maxFallbackPoints={80} maxFallbackPoints={80}
selectedId={selectedMapRow ? realtimeMapPointId(selectedMapRow, rows.indexOf(selectedMapRow)) : selectedMapPointId} selectedId={selectedMapPointKey}
onPointSelect={(point) => setSelectedMapPointId(point.id)} onPointSelect={selectRealtimeMapPoint}
fallbackLabel="高德地图未配置,显示实时坐标预览" fallbackLabel="高德地图未配置,显示实时坐标预览"
/> />
</div> </div>
@@ -597,11 +606,11 @@ export function Realtime({
role="button" role="button"
tabIndex={0} tabIndex={0}
className={`vp-map-service-item vp-map-service-item-button ${selectedMapRow?.vin === row.vin ? 'vp-map-service-item-selected' : ''}`} className={`vp-map-service-item vp-map-service-item-button ${selectedMapRow?.vin === row.vin ? 'vp-map-service-item-selected' : ''}`}
onClick={() => setSelectedMapPointId(realtimeMapPointId(row, rows.indexOf(row)))} onClick={() => selectRealtimeRow(row)}
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Enter' || event.key === ' ') { if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault(); event.preventDefault();
setSelectedMapPointId(realtimeMapPointId(row, rows.indexOf(row))); selectRealtimeRow(row);
} }
}} }}
> >
@@ -722,6 +731,7 @@ export function Realtime({
width: 190, width: 190,
render: (_: unknown, row: VehicleRealtimeRow) => ( render: (_: unknown, row: VehicleRealtimeRow) => (
<Space spacing={4} wrap> <Space spacing={4} wrap>
<Button disabled={!isValidCoordinate(row)} onClick={() => selectRealtimeRow(row)}></Button>
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, filters.protocol || row.primaryProtocol)}></Button> <Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, filters.protocol || row.primaryProtocol)}></Button>
<Button disabled={!canOpenVehicle(row.vin) || !onOpenQuality} onClick={() => openQualityEvidence(row)}></Button> <Button disabled={!canOpenVehicle(row.vin) || !onOpenQuality} onClick={() => openQualityEvidence(row)}></Button>
</Space> </Space>
@@ -732,7 +742,13 @@ export function Realtime({
)} )}
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane tab="地图视图" itemKey="map"> <Tabs.TabPane tab="地图视图" itemKey="map">
<VehicleMap points={mapPoints} heightClassName="" fallbackLabel="高德地图未配置,显示实时坐标预览" /> <VehicleMap
points={mapPoints}
heightClassName=""
selectedId={selectedMapPointKey}
onPointSelect={selectRealtimeMapPoint}
fallbackLabel="高德地图未配置,显示实时坐标预览"
/>
</Tabs.TabPane> </Tabs.TabPane>
</Tabs> </Tabs>
</Card> </Card>

View File

@@ -8329,6 +8329,12 @@ test('selects realtime map vehicle from fallback map point', async () => {
expect(within(selectedPanel as HTMLElement).getByText('粤A选中2')).toBeInTheDocument(); expect(within(selectedPanel as HTMLElement).getByText('粤A选中2')).toBeInTheDocument();
}); });
expect(within(selectedPanel as HTMLElement).getByText('42 km/h')).toBeInTheDocument(); expect(within(selectedPanel as HTMLElement).getByText('42 km/h')).toBeInTheDocument();
const locateButtons = screen.getAllByRole('button', { name: '地图定位' });
fireEvent.click(locateButtons[0]);
expect(within(selectedPanel as HTMLElement).getByText('粤A选中1')).toBeInTheDocument();
fireEvent.click(locateButtons[1]);
expect(within(selectedPanel as HTMLElement).getByText('粤A选中2')).toBeInTheDocument();
}); });
test('opens vehicle service from realtime map service queue', async () => { test('opens vehicle service from realtime map service queue', async () => {