feat(platform): export realtime vehicle page

This commit is contained in:
lingniu
2026-07-04 13:07:56 +08:00
parent c6875e12a5
commit 2cff1637ae
2 changed files with 117 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import { SourceStatusTags } from '../components/SourceStatusTags';
import { StatusTag } from '../components/StatusTag';
import { VehicleMap, type VehicleMapPoint } from '../components/VehicleMap';
import { isAMapConfigured } from '../config/appConfig';
import { buildCsv, downloadCsv, type CsvColumn } from '../domain/csvExport';
function canOpenVehicle(vin?: string) {
const value = vin?.trim();
@@ -78,6 +79,32 @@ const serviceStatusLabel: Record<string, string> = {
identity_required: '身份未绑定'
};
const realtimeExportColumns: CsvColumn<VehicleRealtimeRow>[] = [
{ title: 'VIN', value: (row) => row.vin },
{ title: '车牌', value: (row) => row.plate },
{ title: '手机号', value: (row) => row.phone },
{ title: 'OEM', value: (row) => row.oem },
{ title: '主来源', value: (row) => row.primaryProtocol },
{ title: '来源列表', value: (row) => row.protocols?.join('|') },
{ title: '在线', value: (row) => row.online ? '在线' : '离线' },
{ title: '车辆服务状态', value: (row) => vehicleServiceStatus(row).label },
{ title: '来源在线', value: (row) => sourceEvidenceText(row) },
{ title: '经度', value: (row) => row.longitude },
{ title: '纬度', value: (row) => row.latitude },
{ title: '速度km/h', value: (row) => row.speedKmh },
{ title: 'SOC%', value: (row) => row.socPercent },
{ title: '总里程km', value: (row) => row.totalMileageKm },
{ title: '最后时间', value: (row) => row.lastSeen },
{ title: '绑定状态', value: (row) => row.bindingStatus }
];
function realtimeExportFileName(filters: Record<string, string>) {
const keyword = filters.keyword?.trim() || 'all';
const protocol = filters.protocol?.trim() || 'all-source';
const online = filters.online?.trim() || 'all-online';
return `realtime-vehicles-${keyword}-${protocol}-${online}.csv`;
}
export function Realtime({
onOpenVehicle,
onOpenHistory,
@@ -130,6 +157,14 @@ export function Realtime({
protocol: filters.protocol || row.primaryProtocol || ''
});
};
const exportRealtime = () => {
if (rows.length === 0) {
Toast.warning('当前没有可导出的实时车辆');
return;
}
downloadCsv(realtimeExportFileName(filters), buildCsv(realtimeExportColumns, rows));
Toast.success(`已导出 ${rows.length} 条实时车辆`);
};
const filterSummary = [
filters.keyword ? `关键词:${filters.keyword}` : '',
filters.protocol ? `数据来源:${filters.protocol}` : '',
@@ -313,6 +348,12 @@ export function Realtime({
</div>
<Tabs type="line">
<Tabs.TabPane tab="表格视图" itemKey="table">
<div className="vp-table-toolbar">
<Space wrap>
<Tag color="blue"> {rows.length.toLocaleString()} </Tag>
<Button size="small" onClick={exportRealtime}> CSV</Button>
</Space>
</div>
{rows.length === 0 && !loading ? (
<DataEmpty />
) : (