feat(platform): link history locations to mileage evidence
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
]}
|
||||
|
||||
Reference in New Issue
Block a user