Files
ln-bi/src/modules/assets/history/presentation.ts
T
shishengliang a81ace14e4
ci/woodpecker/push/woodpecker Pipeline was canceled
ci/woodpecker/manual/woodpecker Pipeline was successful
feat(assets): 展示近七天资产趋势并支持业务回溯归档
2026-11-02 18:17:41 +08:00

30 lines
2.1 KiB
TypeScript

import type { HistoryPoint } from '../../../shared/assets/history';
/** Accessible period buttons and chart clicks share one selection model. */
export function defaultHistoryPeriod(points: HistoryPoint[]): string | null {
return points.find(p => p.state === 'LIVE')?.period || [...points].reverse().find(p => p.state === 'ARCHIVED' || p.state === 'RECONSTRUCTED')?.period || points.at(-1)?.period || null;
}
export function updateLivePoint(points: HistoryPoint[], live: HistoryPoint): HistoryPoint[] {
return points.map((point, index) => {
if (point.state !== 'LIVE' || point.period !== live.period) return point;
if (points[index - 1]?.state === 'RECONSTRUCTED') return { ...live, difference: null, comparisonLabel: '推算与实时或正式快照口径不同,暂无可比数据' };
const baseline = points[index - 1]?.counts || (point.counts && point.difference ? {
total: point.counts.total - point.difference.total,
operating: point.counts.operating - point.difference.operating,
inventory: point.counts.inventory - point.difference.inventory,
} : null);
return { ...live, difference: baseline && live.counts ? {
total: live.counts.total - baseline.total,
operating: live.counts.operating - baseline.operating,
inventory: live.counts.inventory - baseline.inventory,
} : null, comparisonLabel: baseline ? `截至当前较${live.period.length === 4 ? '上年末' : live.period.length === 10 ? '昨日' : '上月末'}` : '暂无可比数据' };
});
}
export const signedCount = (value: number) => value > 0 ? `+${value.toLocaleString()}` : value.toLocaleString();
export function displayHistoryCounts(point: HistoryPoint) {
return point.reconstruction ? { total: null, operating: point.reconstruction.operating, inventory: point.reconstruction.inventory } : point.counts;
}
export function displayHistoryDifference(point: HistoryPoint, key: 'total' | 'operating' | 'inventory'): number | null {
return point.reconstruction ? key === 'total' ? null : point.reconstruction.difference?.[key] ?? null : point.difference?.[key] ?? null;
}