客户表过滤聚合
灵感:能力工具箱 arquero-table(Arquero 在浏览器内做客户表过滤聚合)。
> 小四原创:客户行数组 → aq.from → filter / groupby → 普通对象数组。
> 仅 Demo/小表;大数据走后端。
何时使用
- 看板按阶段汇总数量/金额
- 本地筛选客户行业后再聚合
- Demo 无后端透视小表
硬约束
- 依赖:
arquero。 - 输入为行对象数组;输出回
objects()便于 Vue 渲染。 - 明确边界:小数据(建议千行内);不做全量数仓。
- 实现要点注释标 小四原创。
- 不做图表引擎、不做 SQL 方言全集。
推荐实现
import aq from 'arquero'
export type ClientRow = {
name: string
stage: string
amount?: number
industry?: string
}
// 小四原创:按阶段汇总数量与金额
export function aggregateByStage(rows: ClientRow[]) {
return aq
.from(rows)
.groupby('stage')
.rollup({
count: aq.op.count(),
amountSum: aq.op.sum('amount'),
})
.orderby('stage')
.objects() as Array<{ stage: string; count: number; amountSum: number }>
}
export function filterClients(
rows: ClientRow[],
opts: { industry?: string; stage?: string },
) {
let t = aq.from(rows)
if (opts.industry) {
const ind = opts.industry
t = t.filter(aq.escape((d: ClientRow) => d.industry === ind))
}
if (opts.stage) {
const st = opts.stage
t = t.filter(aq.escape((d: ClientRow) => d.stage === st))
}
return t.objects() as ClientRow[]
}
Agent 步骤
npm i arquero。- 看板/统计卡调用
aggregateByStage。 - 自测:3 行两阶段 → 两组 count;空表不崩。
不要做
- 把百万行塞进浏览器 Arquero。
- 做成完整 Tabulator/Excel 替代品(过重项已跳过)。
附加
- README.md · reference.md · templates/usage.md