feat(platform): add reusable history report view

This commit is contained in:
lingniu
2026-07-05 18:42:45 +08:00
parent 3e3bc117f7
commit ac4b7fcd30
3 changed files with 221 additions and 1 deletions

View File

@@ -455,6 +455,44 @@ function scheduledHistoryReportPlanText({
].join('\n');
}
function savedHistoryReportViewText({
filters,
fieldCount,
fieldPaths,
locationCount,
rawCount,
validPointCount,
anomalySummary
}: {
filters: HistoryFilters;
fieldCount: number;
fieldPaths: string[];
locationCount: number;
rawCount: number;
validPointCount: number;
anomalySummary: TrajectoryAnomalySummary;
}) {
const vehicle = filters.keyword?.trim() || '';
const protocol = filters.protocol?.trim() || '';
const fieldTemplate = fieldPaths.length > 0 ? fieldPaths.join(', ') : filters.fields?.trim() || '未配置字段裁剪';
const evidenceFilters = {
tab: 'fields',
...(filters.dateFrom?.trim() ? { dateFrom: filters.dateFrom.trim() } : {}),
...(filters.dateTo?.trim() ? { dateTo: filters.dateTo.trim() } : {}),
includeFields: 'true',
...(fieldPaths.length > 0 ? { fields: fieldPaths.join(',') } : filters.fields?.trim() ? { fields: filters.fields.trim() } : {})
};
return [
'【保存报表视图】',
`视图范围:${vehicle || '全部车辆'} / ${protocol || '全部数据通道'} / ${filters.dateFrom?.trim() || '-'}${filters.dateTo?.trim() || '-'}`,
`字段模板:${fieldTemplate}`,
'交付节奏:日报用于运营复盘,周报用于客户对账,临时导出用于问题解释。',
`当前证据:位置 ${locationCount.toLocaleString()} 条,有效定位 ${validPointCount.toLocaleString()},明细 ${rawCount.toLocaleString()} 帧,字段 ${fieldCount.toLocaleString()} 个。`,
`质量提示:断点 ${anomalySummary.gapCount.toLocaleString()} / 里程回退 ${anomalySummary.mileageRollbackCount.toLocaleString()} / 超速 ${anomalySummary.overspeedCount.toLocaleString()}`,
`复用链接:${appURL(buildAppHash({ page: 'history-query', keyword: vehicle, protocol, filters: evidenceFilters }))}`
].join('\n');
}
function trajectoryReviewPackageText({
filters,
locationCount,
@@ -1075,7 +1113,7 @@ export function History({
},
{
title: '字段裁剪包',
value: selectedFieldCount > 0 ? `${selectedFieldCount.toLocaleString()} 字段` : `${rawFieldRows.length.toLocaleString()} 字段`,
value: rawFieldRows.length > 0 ? `${rawFieldRows.length.toLocaleString()} 字段` : `${selectedFieldCount.toLocaleString()} 字段`,
detail: selectedFieldCount > 0 ? '按客户指定字段裁剪,减少导出体积。' : '先填写字段裁剪或切换字段裁剪页,再生成字段级交付。',
color: rawFieldRows.length > 0 || selectedFieldCount > 0 ? 'green' as const : 'orange' as const,
action: '字段配置',
@@ -1169,6 +1207,44 @@ export function History({
onClick: () => openQueryTab('fields')
}
];
const savedReportViewItems = [
{
title: '当前筛选',
value: currentVehicleKeyword || '全部车辆',
detail: `${currentProtocol || '全部数据通道'} / ${filters.dateFrom || '-'}${filters.dateTo || '-'}`,
action: '保存视图',
color: currentVehicleKeyword ? 'green' as const : 'blue' as const,
disabled: false,
onClick: () => copySavedReportView()
},
{
title: '字段模板',
value: rawFieldRows.length > 0 ? `${rawFieldRows.length.toLocaleString()} 字段` : `${selectedFieldCount.toLocaleString()} 字段`,
detail: filters.fields?.trim() || '未配置字段裁剪,默认使用当前字段明细。',
action: '复用字段',
color: selectedFieldCount > 0 || rawFieldRows.length > 0 ? 'green' as const : 'orange' as const,
disabled: false,
onClick: () => openQueryTab('fields')
},
{
title: '交付节奏',
value: '日报/周报',
detail: '日报用于运营复盘,周报用于客户对账,临时导出用于问题解释。',
action: '复制计划',
color: 'blue' as const,
disabled: false,
onClick: () => copyScheduledHistoryReportPlan()
},
{
title: '快速分享',
value: '可复制',
detail: '复制当前视图链接和字段模板,交给客户或内部运营复用。',
action: '复制链接',
color: 'blue' as const,
disabled: false,
onClick: () => copySavedReportView()
}
];
const customerHistoryQuestions = [
{
question: '这辆车这段时间在哪里?',
@@ -1293,6 +1369,29 @@ export function History({
'历史数据周期交付计划'
);
};
const copySavedReportView = () => {
const fieldPaths = Array.from(new Set(rawFieldRows.map((row) => row.fieldPath).filter(Boolean)));
const fallbackDateFrom = dateOnly(rawFieldRows[0]?.deviceTime);
const fallbackDateTo = fallbackDateFrom ? nextDate(fallbackDateFrom) : '';
const viewFilters = {
...filters,
...(filters.dateFrom?.trim() ? {} : fallbackDateFrom ? { dateFrom: fallbackDateFrom } : {}),
...(filters.dateTo?.trim() ? {} : fallbackDateTo ? { dateTo: fallbackDateTo } : {}),
...(fieldPaths.length > 0 ? { fields: fieldPaths.join(',') } : {})
};
copyText(
savedHistoryReportViewText({
filters: viewFilters,
locationCount: locations.total ?? 0,
rawCount: rawFrames.total ?? 0,
fieldCount: rawFieldRows.length,
fieldPaths,
validPointCount: validLocations.length,
anomalySummary: trajectoryAnomalies
}),
'保存报表视图'
);
};
const copyTrajectoryReviewPackage = () => {
copyText(
trajectoryReviewPackageText({
@@ -1755,6 +1854,42 @@ export function History({
</div>
</Card>
) : null}
{mode === 'query' ? (
<Card bordered title="保存报表视图" style={{ marginTop: 16 }}>
<div className="vp-history-saved-report">
<div className="vp-history-saved-report-summary">
<Space wrap>
<Tag color="blue"></Tag>
<Tag color={currentVehicleKeyword ? 'green' : 'grey'}>{currentVehicleKeyword ? '单车范围' : '全部车辆'}</Tag>
<Tag color={selectedFieldCount > 0 || rawFieldRows.length > 0 ? 'green' : 'orange'}>
{selectedFieldCount > 0 ? `${selectedFieldCount.toLocaleString()} 个字段` : `${rawFieldRows.length.toLocaleString()} 个字段`}
</Tag>
</Space>
<Typography.Title heading={5} style={{ margin: 0 }}></Typography.Title>
<Typography.Text type="secondary">
</Typography.Text>
</div>
<div className="vp-history-saved-report-grid">
{savedReportViewItems.map((item) => (
<button
key={item.title}
type="button"
className="vp-history-saved-report-item"
disabled={item.disabled}
onClick={item.onClick}
aria-label={`保存报表视图 ${item.title} ${item.value} ${item.action}`}
>
<Tag color={item.color}>{item.title}</Tag>
<strong>{item.value}</strong>
<span>{item.detail}</span>
<em>{item.action}</em>
</button>
))}
</div>
</div>
</Card>
) : null}
{mode === 'query' ? (
<Card bordered title="客户历史问题" style={{ marginTop: 16 }}>
<div className="vp-history-question-board">