import React from 'react'; import './SummaryRowTable.css'; function compute(data, key, type) { const arr = data.map((d) => Number(d[key]) || 0); if (!arr.length) return ''; if (type === 'sum') return arr.reduce((a, b) => a + b, 0); if (type === 'avg') return +(arr.reduce((a, b) => a + b, 0) / arr.length).toFixed(1); if (type === 'max') return Math.max(...arr); if (type === 'min') return Math.min(...arr); if (type === 'count') return arr.length; return ''; } export default function SummaryRowTable({ data = [], columns = [], summary = {}, labelKey = 'name', labelText = '合计 / 平均' }) { return ( {columns.map((c) => ( ))} {data.map((row, i) => ( {columns.map((c) => ( ))} ))} {columns.map((c) => ( ))}
{c.title}
= c.pos ? 'is-pos' : ''}> {row[c.key]}
{c.key === labelKey ? labelText : summary[c.key] ? compute(data, c.key, summary[c.key]) : ''}
); }