refactor(platform): centralize vehicle lookup rules
This commit is contained in:
@@ -4,6 +4,7 @@ import { api } from '../api/client';
|
||||
import type { DashboardSummary, LinkHealth, ProtocolStat, QualityIssueRow, VehicleCoverageRow, VehicleRealtimeRow } from '../api/types';
|
||||
import { PageHeader } from '../components/PageHeader';
|
||||
import { StatusTag } from '../components/StatusTag';
|
||||
import { qualityIssueVehicleLookup } from '../domain/vehicleLookup';
|
||||
|
||||
const statusColor: Record<string, 'green' | 'orange' | 'red' | 'grey'> = {
|
||||
ok: 'green',
|
||||
@@ -15,22 +16,6 @@ function formatLag(value?: number | null) {
|
||||
return value == null ? '未接入' : value.toLocaleString();
|
||||
}
|
||||
|
||||
function qualityVehicleLookup(row: QualityIssueRow) {
|
||||
const vin = row.vin?.trim();
|
||||
if (vin && vin !== 'unknown') {
|
||||
return { key: vin, label: '车辆服务' };
|
||||
}
|
||||
const plate = row.plate?.trim();
|
||||
if (plate) {
|
||||
return { key: plate, label: '按车牌查车' };
|
||||
}
|
||||
const phone = row.phone?.trim();
|
||||
if (phone) {
|
||||
return { key: phone, label: '按手机号查车' };
|
||||
}
|
||||
return { key: '', label: '车辆服务' };
|
||||
}
|
||||
|
||||
export function Dashboard({ onOpenVehicle, onOpenQuality }: { onOpenVehicle: (vin: string) => void; onOpenQuality: () => void }) {
|
||||
const [summary, setSummary] = useState<DashboardSummary | null>(null);
|
||||
const [coverage, setCoverage] = useState<VehicleCoverageRow[]>([]);
|
||||
@@ -148,7 +133,7 @@ export function Dashboard({ onOpenVehicle, onOpenQuality }: { onOpenVehicle: (vi
|
||||
title: '操作',
|
||||
width: 130,
|
||||
render: (_: unknown, row: QualityIssueRow) => {
|
||||
const lookup = qualityVehicleLookup(row);
|
||||
const lookup = qualityIssueVehicleLookup(row);
|
||||
return <Button disabled={!lookup.key} onClick={() => onOpenVehicle(lookup.key)}>{lookup.label}</Button>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user