feat(platform): link mileage rows to trajectory evidence
This commit is contained in:
@@ -36,6 +36,13 @@ function canOpenVehicle(vin?: string) {
|
||||
return Boolean(value && value !== 'unknown');
|
||||
}
|
||||
|
||||
function nextDate(value: string) {
|
||||
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim());
|
||||
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 mileageActionRecommendation(row: DailyMileageRow) {
|
||||
if (row.anomalySeverity) {
|
||||
return {
|
||||
@@ -91,13 +98,15 @@ export function Mileage({
|
||||
initialProtocol,
|
||||
initialFilters = {},
|
||||
onFiltersChange,
|
||||
onOpenVehicle
|
||||
onOpenVehicle,
|
||||
onOpenHistory
|
||||
}: {
|
||||
initialVin: string;
|
||||
initialProtocol?: string;
|
||||
initialFilters?: Record<string, string>;
|
||||
onFiltersChange?: (filters: Record<string, string>) => void;
|
||||
onOpenVehicle: (vin: string, protocol?: string) => void;
|
||||
onOpenHistory?: (filters: Record<string, string>) => void;
|
||||
}) {
|
||||
const [rows, setRows] = useState<DailyMileageRow[]>([]);
|
||||
const [summary, setSummary] = useState<MileageSummary>(emptySummary);
|
||||
@@ -151,6 +160,17 @@ export function Mileage({
|
||||
applyFilters(currentVehicleKeyword ? { keyword: currentVehicleKeyword } : {});
|
||||
};
|
||||
|
||||
const openMileageEvidence = (row: DailyMileageRow) => {
|
||||
const dateFrom = row.date?.trim() ?? '';
|
||||
const dateTo = nextDate(dateFrom);
|
||||
onOpenHistory?.({
|
||||
keyword: row.vin,
|
||||
protocol: row.source,
|
||||
...(dateFrom ? { dateFrom } : {}),
|
||||
...(dateTo ? { dateTo } : {})
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const nextFilters = mergeInitialFilters(initialVin, initialProtocol, initialFilters);
|
||||
setFilters(nextFilters);
|
||||
@@ -318,9 +338,12 @@ export function Mileage({
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 110,
|
||||
width: 190,
|
||||
render: (_: unknown, row: DailyMileageRow) => (
|
||||
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, row.source)}>车辆服务</Button>
|
||||
<Space spacing={4} wrap>
|
||||
<Button disabled={!canOpenVehicle(row.vin) || !onOpenHistory} onClick={() => openMileageEvidence(row)}>核对轨迹</Button>
|
||||
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, row.source)}>车辆服务</Button>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
]}
|
||||
|
||||
Reference in New Issue
Block a user