feat(platform): copy mileage statistics summary
This commit is contained in:
@@ -111,6 +111,56 @@ function exportFileName(filters: Record<string, string>) {
|
||||
return `daily-mileage-${keyword}-${protocol}.csv`;
|
||||
}
|
||||
|
||||
function mileageSummaryText({
|
||||
filters,
|
||||
summary,
|
||||
pageMileageTotal,
|
||||
anomalyCount,
|
||||
peakMileage
|
||||
}: {
|
||||
filters: Record<string, string>;
|
||||
summary: MileageSummary;
|
||||
pageMileageTotal: number;
|
||||
anomalyCount: number;
|
||||
peakMileage?: DailyMileageRow;
|
||||
}) {
|
||||
const keyword = filters.keyword?.trim() || '全部车辆';
|
||||
const protocol = filters.protocol?.trim() || '全部来源';
|
||||
const dateFrom = filters.dateFrom?.trim();
|
||||
const dateTo = filters.dateTo?.trim();
|
||||
const dateRange = dateFrom || dateTo ? `${dateFrom || '-'} 至 ${dateTo || '-'}` : '全部日期';
|
||||
const peak = peakMileage
|
||||
? `${peakMileage.plate || peakMileage.vin} / ${peakMileage.date} / ${formatKm(peakMileage.dailyMileageKm)} km`
|
||||
: '-';
|
||||
return [
|
||||
'【里程统计摘要】',
|
||||
`车辆范围:${keyword}`,
|
||||
`数据来源:${protocol}`,
|
||||
`日期范围:${dateRange}`,
|
||||
`统计车辆:${summary.vehicleCount.toLocaleString()},记录:${summary.recordCount.toLocaleString()},来源:${summary.sourceCount.toLocaleString()}`,
|
||||
`累计里程:${formatKm(summary.totalMileageKm)} km`,
|
||||
`单车平均:${formatKm(summary.averageMileagePerVin)} km`,
|
||||
`当前页里程:${formatKm(pageMileageTotal)} km`,
|
||||
`异常记录:${anomalyCount.toLocaleString()}`,
|
||||
`最大单日:${peak}`,
|
||||
'统计口径:区间总值等于各日里程之和'
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
async function copyText(value: string, label: string) {
|
||||
const text = value.trim();
|
||||
if (!text) {
|
||||
Toast.warning(`${label}为空`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
Toast.success(`已复制${label}`);
|
||||
} catch {
|
||||
Toast.error(`复制${label}失败`);
|
||||
}
|
||||
}
|
||||
|
||||
export function Mileage({
|
||||
initialVin,
|
||||
initialProtocol,
|
||||
@@ -208,6 +258,18 @@ export function Mileage({
|
||||
downloadCsv(exportFileName(filters), buildCsv(mileageExportColumns, rows));
|
||||
Toast.success(`已导出 ${rows.length} 条里程明细`);
|
||||
};
|
||||
const copyStatisticsSummary = () => {
|
||||
copyText(
|
||||
mileageSummaryText({
|
||||
filters,
|
||||
summary,
|
||||
pageMileageTotal,
|
||||
anomalyCount: anomalyRows.length,
|
||||
peakMileage
|
||||
}),
|
||||
'统计摘要'
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const nextFilters = mergeInitialFilters(initialVin, initialProtocol, initialFilters);
|
||||
@@ -324,6 +386,12 @@ export function Mileage({
|
||||
))}
|
||||
</div>
|
||||
<Card bordered title="统计口径" style={{ marginTop: 16 }}>
|
||||
<div className="vp-table-toolbar">
|
||||
<Space wrap>
|
||||
<Tag color="blue">可复制日报口径</Tag>
|
||||
<Button size="small" onClick={copyStatisticsSummary}>复制统计摘要</Button>
|
||||
</Space>
|
||||
</div>
|
||||
<div className="vp-stat-definition-grid">
|
||||
<div>
|
||||
<Tag color="blue">日里程</Tag>
|
||||
|
||||
Reference in New Issue
Block a user