diff --git a/src/App.tsx b/src/App.tsx index 5fbfe86..f965061 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -372,6 +372,30 @@ export default function App() { return mp; }), [modalWeeklyDetail, modalFilters.plateNumber]); + const customerPieData = useMemo(() => { + let data: { name: string; value: number }[] = []; + if (customerChartView === 'region') { + const map: Record = {}; + customerData.forEach(item => { map[item.region] = (map[item.region] || 0) + item.total; }); + data = Object.entries(map).map(([name, value]) => ({ name, value })).sort((a, b) => b.value - a.value); + } else { + const map: Record = {}; + customerData.forEach(item => { map[item.city] = (map[item.city] || 0) + item.total; }); + const tot = Object.values(map).reduce((a, b) => a + b, 0); + const threshold = tot * 0.05; + let other = 0; + Object.entries(map).forEach(([name, value]) => { + if (value >= threshold) data.push({ name, value }); + else other += value; + }); + if (other > 0) data.push({ name: '其他', value: other }); + data.sort((a, b) => b.value - a.value); + } + return data; + }, [customerData, customerChartView]); + + const watermarkText = useMemo(() => `羚牛氢能-${new Date().toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }).replace(/\//g, '-')}`, [lastUpdate]); + if (loading && !summary) { return (
@@ -399,30 +423,6 @@ export default function App() { const SUMMARY = summary!; - const customerPieData = useMemo(() => { - let data: { name: string; value: number }[] = []; - if (customerChartView === 'region') { - const map: Record = {}; - customerData.forEach(item => { map[item.region] = (map[item.region] || 0) + item.total; }); - data = Object.entries(map).map(([name, value]) => ({ name, value })).sort((a, b) => b.value - a.value); - } else { - const map: Record = {}; - customerData.forEach(item => { map[item.city] = (map[item.city] || 0) + item.total; }); - const tot = Object.values(map).reduce((a, b) => a + b, 0); - const threshold = tot * 0.05; - let other = 0; - Object.entries(map).forEach(([name, value]) => { - if (value >= threshold) data.push({ name, value }); - else other += value; - }); - if (other > 0) data.push({ name: '其他', value: other }); - data.sort((a, b) => b.value - a.value); - } - return data; - }, [customerData, customerChartView]); - - const watermarkText = useMemo(() => `羚牛氢能-${new Date().toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }).replace(/\//g, '-')}`, [lastUpdate]); - return (
{/* Watermark */}