feat(platform): link history locations to mileage evidence

This commit is contained in:
lingniu
2026-07-04 11:54:48 +08:00
parent 2ba30b21cd
commit f305066eff
3 changed files with 140 additions and 4 deletions

View File

@@ -29,6 +29,18 @@ function canOpenVehicle(vin?: string) {
return Boolean(value && value !== 'unknown');
}
function dateOnly(value?: string) {
const match = String(value ?? '').match(/^(\d{4})-(\d{2})-(\d{2})/);
return match ? `${match[1]}-${match[2]}-${match[3]}` : '';
}
function nextDate(value: string) {
const match = value.match(/^(\d{4})-(\d{2})-(\d{2})$/);
if (!match) return '';
const date = new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]) + 1));
return date.toISOString().slice(0, 10);
}
function splitFields(value?: string) {
return (value ?? '')
.split(/[\n,]/)
@@ -105,7 +117,8 @@ export function History({
initialTab,
initialFilters = {},
onFiltersChange,
onOpenVehicle
onOpenVehicle,
onOpenMileage
}: {
initialVin: string;
initialProtocol?: string;
@@ -113,6 +126,7 @@ export function History({
initialFilters?: Record<string, string>;
onFiltersChange?: (filters: HistoryFilters, tab?: HistoryTabKey) => void;
onOpenVehicle: (vin: string, protocol?: string) => void;
onOpenMileage?: (filters: Record<string, string>) => void;
}) {
const initialHistoryFilters = mergeInitialFilters(initialVin, initialProtocol, initialFilters);
const [filters, setFilters] = useState<HistoryFilters>(initialHistoryFilters);
@@ -271,6 +285,15 @@ export function History({
if (!currentPlayback || !canOpenVehicle(currentPlayback.vin)) return;
onOpenVehicle(currentPlayback.vin, currentPlayback.protocol);
};
const openLocationMileage = (row: HistoryLocationRow) => {
if (!canOpenVehicle(row.vin)) return;
const day = dateOnly(row.deviceTime || row.serverTime || row.lastSeen);
onOpenMileage?.({
keyword: row.vin,
protocol: row.protocol,
...(day ? { dateFrom: day, dateTo: nextDate(day) } : {})
});
};
return (
<div className="vp-page">
@@ -433,9 +456,12 @@ export function History({
{ title: '入库时间', dataIndex: 'serverTime', width: 190 },
{
title: '操作',
width: 110,
width: 190,
render: (_: unknown, row: HistoryLocationRow) => (
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, row.protocol)}></Button>
<Space>
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, row.protocol)}></Button>
<Button disabled={!canOpenVehicle(row.vin) || !onOpenMileage} onClick={() => openLocationMileage(row)}></Button>
</Space>
)
}
]}