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>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
|
||||
import { api } from '../api/client';
|
||||
import type { OpsHealth, QualitySummary, QualityIssueRow } from '../api/types';
|
||||
import { PageHeader } from '../components/PageHeader';
|
||||
import { qualityIssueVehicleLookup } from '../domain/vehicleLookup';
|
||||
|
||||
const statusColor: Record<string, 'green' | 'orange' | 'red' | 'grey'> = {
|
||||
ok: 'green',
|
||||
@@ -49,22 +50,6 @@ async function copyText(value: string, label: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function vehicleLookup(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 Quality({
|
||||
onOpenVehicle,
|
||||
onHealthLoaded
|
||||
@@ -194,7 +179,7 @@ export function Quality({
|
||||
title: '操作',
|
||||
width: 250,
|
||||
render: (_: unknown, row: QualityIssueRow) => {
|
||||
const lookup = vehicleLookup(row);
|
||||
const lookup = qualityIssueVehicleLookup(row);
|
||||
return (
|
||||
<Space spacing={4}>
|
||||
<Button size="small" icon={<IconCopy />} onClick={() => copyText(row.phone, '手机号')}>手机号</Button>
|
||||
|
||||
Reference in New Issue
Block a user