@veltra/sheet 2.1.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/report/binding-badge.js +100 -0
- package/dist/components/report/designer/cell-coords.js +46 -0
- package/dist/components/report/designer/col-widths.js +29 -0
- package/dist/components/report/designer/conditional-rules/helpers.js +139 -0
- package/dist/components/report/designer/drop-highlight-overlay.js +76 -0
- package/dist/components/report/designer/float-panel.js +422 -0
- package/dist/components/report/designer/role.js +17 -0
- package/dist/components/report/designer/rule-preview.js +33 -0
- package/dist/components/report/designer/rule-row.js +253 -0
- package/dist/components/report/designer/rules-dialog.js +118 -0
- package/dist/components/report/designer/topology-overlay.js +122 -0
- package/dist/components/report/designer/topology.js +64 -0
- package/dist/components/report/designer/use-grid-overlay.js +75 -0
- package/dist/components/report/designer-hub.js +177 -0
- package/dist/components/report/field-panel-helpers.js +33 -0
- package/dist/components/report/field-panel.js +132 -0
- package/dist/components/report/filter-bar.js +74 -0
- package/dist/components/report/hub-connection-form.js +145 -0
- package/dist/components/report/hub-dataset-editor.js +394 -0
- package/dist/components/report/preview-grid-size.js +32 -0
- package/dist/components/report/report-designer.js +393 -0
- package/dist/components/report/report-viewer.js +124 -0
- package/dist/components/report/style.d.ts +17 -0
- package/dist/components/report/style.js +18 -0
- package/dist/components/report/style2.css +874 -0
- package/dist/components/report/use-report-designer.js +382 -0
- package/dist/components/report/use-report-viewer.js +55 -0
- package/dist/{vue → components/sheet}/formula-bar.js +1 -1
- package/dist/{vue → components/sheet}/formula-suggest-list.js +1 -1
- package/dist/{vue → components/sheet}/import-file.js +1 -1
- package/dist/{vue → components/sheet}/insert-count-menu-item.js +1 -1
- package/dist/{vue → components/sheet}/insert-image.js +1 -1
- package/dist/{vue → components/sheet}/popup-helpers.js +1 -1
- package/dist/{vue → components/sheet}/popups/border-popup.js +31 -3
- package/dist/{vue → components/sheet}/popups/border-preset-glyph.js +1 -1
- package/dist/{vue → components/sheet}/popups/export-popup.js +2 -2
- package/dist/{vue → components/sheet}/popups/fill-color-popup.js +3 -3
- package/dist/{vue → components/sheet}/popups/find-popup.js +1 -1
- package/dist/{vue → components/sheet}/popups/font-color-popup.js +3 -3
- package/dist/{vue → components/sheet}/popups/font-size-popup.js +3 -3
- package/dist/{vue → components/sheet}/popups/import.worker.d.ts +1 -1
- package/dist/{vue → components/sheet}/popups/import.worker.js +1 -1
- package/dist/{vue → components/sheet}/popups/insert-image-popup.js +1 -1
- package/dist/{vue → components/sheet}/sheet-context-menu.js +7 -4
- package/dist/{vue → components/sheet}/sheet-tabs.js +1 -1
- package/dist/{vue → components/sheet}/sheet-toolbar.js +1 -1
- package/dist/{vue → components/sheet}/sheet.js +16 -1
- package/dist/{vue → components/sheet}/use-find-replace.js +1 -1
- package/dist/{vue → components/sheet}/use-formula-ref-select.js +1 -1
- package/dist/{vue → components/sheet}/use-sheet-grid.js +22 -4
- package/dist/{vue → components/sheet}/use-sheet-state.js +6 -5
- package/dist/{vue → components/sheet}/use-sheet-tabs-bar.js +1 -1
- package/dist/{vue → components/sheet}/use-tool-groups.js +2 -2
- package/dist/{vue → components/sheet}/use-tool-popup.js +2 -2
- package/dist/{vue → components/sheet}/use-toolbar-scroll.js +1 -1
- package/dist/index.d.ts +17 -3
- package/dist/index.js +13 -3
- package/dist/report/binding.d.ts +83 -0
- package/dist/report/binding.js +332 -0
- package/dist/report/connector.d.ts +66 -0
- package/dist/report/connector.js +159 -0
- package/dist/report/export-xlsx.d.ts +17 -0
- package/dist/report/export-xlsx.js +92 -0
- package/dist/report/filter-bar.d.ts +10 -0
- package/dist/report/filter-bar.js +31 -0
- package/dist/report/index.d.ts +12 -0
- package/dist/report/params.d.ts +13 -0
- package/dist/report/params.js +61 -0
- package/dist/report/render/aggregate.js +169 -0
- package/dist/report/render/builder.d.ts +12 -0
- package/dist/report/render/builder.js +139 -0
- package/dist/report/render/coordinate.d.ts +25 -0
- package/dist/report/render/coordinate.js +733 -0
- package/dist/report/render/index.d.ts +14 -0
- package/dist/report/render/index.js +21 -0
- package/dist/report/render/style-resolver.js +50 -0
- package/dist/report/render/template-index.d.ts +24 -0
- package/dist/report/render/template-index.js +137 -0
- package/dist/report/rules/evaluate.d.ts +25 -0
- package/dist/report/rules/evaluate.js +82 -0
- package/dist/report/rules/index.d.ts +2 -0
- package/dist/report/template.d.ts +63 -0
- package/dist/report/template.js +83 -0
- package/dist/report/types.d.ts +85 -0
- package/dist/tools/apply-style.js +29 -0
- package/dist/tools/builtin.js +17 -17
- package/dist/tools/context.d.ts +39 -6
- package/dist/tools/context.js +38 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/report-designer.d.ts +38 -0
- package/dist/types/report-viewer.d.ts +38 -0
- package/dist/types/sheet.d.ts +21 -1
- package/package.json +6 -8
- package/src/components/report/__test__/conditional-rules-helpers.test.ts +88 -0
- package/src/components/report/__test__/field-panel-helpers.test.ts +65 -0
- package/src/components/report/__test__/float-panel-position.test.ts +45 -0
- package/src/components/report/__test__/preview-grid-size.test.ts +63 -0
- package/src/components/report/__test__/report-designer.test.ts +464 -0
- package/src/components/report/__test__/report-viewer.test.ts +357 -0
- package/src/components/report/__test__/topology.test.ts +143 -0
- package/src/components/report/__test__/use-report-designer.test.ts +697 -0
- package/src/components/report/binding-badge.ts +92 -0
- package/src/components/report/designer/cell-coords.ts +94 -0
- package/src/components/report/designer/col-widths.ts +56 -0
- package/src/components/report/designer/conditional-rules/helpers.ts +189 -0
- package/src/components/report/designer/drop-highlight-overlay.vue +74 -0
- package/src/components/report/designer/float-panel.vue +431 -0
- package/src/components/report/designer/role.ts +32 -0
- package/src/components/report/designer/rule-preview.vue +40 -0
- package/src/components/report/designer/rule-row.vue +252 -0
- package/src/components/report/designer/rules-dialog.vue +110 -0
- package/src/components/report/designer/topology-overlay.vue +127 -0
- package/src/components/report/designer/topology.ts +124 -0
- package/src/components/report/designer/use-grid-overlay.ts +113 -0
- package/src/components/report/designer-hub.vue +198 -0
- package/src/components/report/field-panel-helpers.ts +44 -0
- package/src/components/report/field-panel.vue +136 -0
- package/src/components/report/filter-bar.vue +77 -0
- package/src/components/report/hub-connection-form.vue +124 -0
- package/src/components/report/hub-dataset-editor.vue +369 -0
- package/src/components/report/index.ts +2 -0
- package/src/components/report/preview-grid-size.ts +33 -0
- package/src/components/report/report-designer.vue +420 -0
- package/src/components/report/report-viewer.vue +136 -0
- package/src/components/report/style-designer.scss +587 -0
- package/src/components/report/style-hub.scss +292 -0
- package/src/components/report/style-viewer.scss +104 -0
- package/src/components/report/style.scss +3 -0
- package/src/components/report/style.ts +20 -0
- package/src/components/report/use-report-designer.ts +596 -0
- package/src/components/report/use-report-viewer.ts +88 -0
- package/src/{vue → components/sheet}/__test__/formula-bar.test.ts +37 -18
- package/src/{vue → components/sheet}/__test__/insert-image-popup.test.ts +1 -1
- package/src/{vue → components/sheet}/__test__/insert-image.test.ts +1 -1
- package/src/{vue → components/sheet}/__test__/sheet-component.test.ts +77 -3
- package/src/{vue → components/sheet}/__test__/sheet-context-menu.test.ts +4 -3
- package/src/{vue → components/sheet}/formula-bar.vue +1 -1
- package/src/{vue → components/sheet}/insert-image.ts +1 -1
- package/src/{vue → components/sheet}/popup-helpers.ts +1 -1
- package/src/{vue → components/sheet}/popups/border-popup.vue +32 -4
- package/src/{vue → components/sheet}/popups/export-popup.vue +2 -2
- package/src/{vue → components/sheet}/popups/fill-color-popup.vue +3 -3
- package/src/{vue → components/sheet}/popups/find-popup.vue +1 -1
- package/src/{vue → components/sheet}/popups/font-color-popup.vue +3 -3
- package/src/{vue → components/sheet}/popups/font-size-popup.vue +3 -3
- package/src/{vue → components/sheet}/popups/insert-image-popup.vue +1 -1
- package/src/{vue → components/sheet}/sheet-context-menu.ts +10 -4
- package/src/{vue → components/sheet}/sheet-toolbar.vue +2 -2
- package/src/{vue → components/sheet}/sheet.vue +6 -3
- package/src/{vue → components/sheet}/use-find-replace.ts +1 -1
- package/src/{vue → components/sheet}/use-sheet-grid.ts +23 -5
- package/src/{vue → components/sheet}/use-sheet-state.ts +11 -6
- package/src/{vue → components/sheet}/use-tool-groups.ts +2 -2
- package/src/{vue → components/sheet}/use-tool-popup.ts +2 -2
- package/src/index.ts +24 -188
- package/src/report/__test__/binding.test.ts +320 -0
- package/src/report/__test__/connector.test.ts +239 -0
- package/src/report/__test__/export-xlsx.test.ts +118 -0
- package/src/report/__test__/filter-bar.test.ts +58 -0
- package/src/report/__test__/params.test.ts +156 -0
- package/src/report/__test__/render.test.ts +830 -0
- package/src/report/__test__/rules.test.ts +131 -0
- package/src/report/__test__/template.test.ts +366 -0
- package/src/report/binding.ts +474 -0
- package/src/report/connector.ts +206 -0
- package/src/report/export-xlsx.ts +113 -0
- package/src/report/filter-bar.ts +36 -0
- package/src/report/index.ts +13 -0
- package/src/report/params.ts +96 -0
- package/src/report/render/__test__/aggregate.test.ts +16 -0
- package/src/report/render/__test__/coordinate.test.ts +405 -0
- package/src/report/render/aggregate.ts +261 -0
- package/src/report/render/builder.ts +211 -0
- package/src/report/render/coordinate.ts +1239 -0
- package/src/report/render/index.ts +30 -0
- package/src/report/render/style-resolver.ts +68 -0
- package/src/report/render/template-index.ts +200 -0
- package/src/report/rules/evaluate.ts +113 -0
- package/src/report/rules/index.ts +7 -0
- package/src/report/template.ts +145 -0
- package/src/report/types.ts +96 -0
- package/src/tools/__test__/apply-style.test.ts +129 -0
- package/src/tools/apply-style.ts +41 -0
- package/src/tools/builtin.ts +20 -20
- package/src/tools/context.ts +67 -4
- package/src/tools/index.ts +1 -0
- package/src/types/index.ts +2 -6
- package/src/types/report-designer.ts +38 -0
- package/src/types/report-viewer.ts +37 -0
- package/src/types/sheet.ts +26 -1
- /package/dist/{vue → components/sheet}/style.d.ts +0 -0
- /package/dist/{vue → components/sheet}/style.js +0 -0
- /package/dist/{vue → components/sheet}/style2.css +0 -0
- /package/dist/{vue → components/sheet}/use-formula-suggest.js +0 -0
- /package/src/{vue → components/sheet}/__test__/import-file.test.ts +0 -0
- /package/src/{vue → components/sheet}/__test__/insert-count-menu-item.test.ts +0 -0
- /package/src/{vue → components/sheet}/__test__/use-formula-ref-select.test.ts +0 -0
- /package/src/{vue → components/sheet}/__test__/use-formula-suggest.test.ts +0 -0
- /package/src/{vue → components/sheet}/formula-suggest-list.vue +0 -0
- /package/src/{vue → components/sheet}/import-file.ts +0 -0
- /package/src/{vue → components/sheet}/index.ts +0 -0
- /package/src/{vue → components/sheet}/insert-count-menu-item.vue +0 -0
- /package/src/{vue → components/sheet}/parsing.ts +0 -0
- /package/src/{vue → components/sheet}/popups/border-preset-glyph.vue +0 -0
- /package/src/{vue → components/sheet}/popups/import.worker.ts +0 -0
- /package/src/{vue → components/sheet}/sheet-tabs.vue +0 -0
- /package/src/{vue → components/sheet}/style.scss +0 -0
- /package/src/{vue → components/sheet}/style.ts +0 -0
- /package/src/{vue → components/sheet}/use-formula-ref-select.ts +0 -0
- /package/src/{vue → components/sheet}/use-formula-suggest.ts +0 -0
- /package/src/{vue → components/sheet}/use-sheet-tabs-bar.ts +0 -0
- /package/src/{vue → components/sheet}/use-toolbar-scroll.ts +0 -0
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
import { Sheet } from '@veltra/sheet-core'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { REPORT_META_NAMESPACE, createReportBinding } from '../binding'
|
|
5
|
+
import { renderReport, resolveFilledColWidths } from '../render'
|
|
6
|
+
import type { DatasetCatalogItem, DatasetRecords } from '../types'
|
|
7
|
+
|
|
8
|
+
// ---- 内联 fixtures(单一事实源在测试自身,不依赖 playground mock hub)----
|
|
9
|
+
|
|
10
|
+
const ORDERS_DATASET: DatasetCatalogItem = {
|
|
11
|
+
id: 'orders',
|
|
12
|
+
label: '销售明细',
|
|
13
|
+
fields: [
|
|
14
|
+
{ name: 'customer', label: '客户', type: 'string' },
|
|
15
|
+
{ name: 'orderNo', label: '订单号', type: 'string' },
|
|
16
|
+
{ name: 'region', label: '地区', type: 'string' },
|
|
17
|
+
{ name: 'amount', label: '金额', type: 'number' },
|
|
18
|
+
{ name: 'orderDate', label: '下单日期', type: 'date' }
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const CUSTOMERS_DATASET: DatasetCatalogItem = {
|
|
23
|
+
id: 'customers',
|
|
24
|
+
label: '客户',
|
|
25
|
+
fields: [
|
|
26
|
+
{ name: 'id', label: '客户ID', type: 'string' },
|
|
27
|
+
{ name: 'region', label: '地区', type: 'string' }
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const SALES_MATRIX_DATASET: DatasetCatalogItem = {
|
|
32
|
+
id: 'sales-matrix',
|
|
33
|
+
label: '销售矩阵',
|
|
34
|
+
fields: [
|
|
35
|
+
{ name: 'region', label: '地区', type: 'string' },
|
|
36
|
+
{ name: 'category', label: '品类', type: 'string' },
|
|
37
|
+
{ name: 'amount', label: '销售额', type: 'number' }
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 4 客户 × 14 订单(与模板断言严格对应) */
|
|
42
|
+
const ORDER_ROWS: Record<string, unknown>[] = [
|
|
43
|
+
{ customer: '甲公司', region: '华东', orderNo: 'O-1001', amount: 100, orderDate: '2024-01-05' },
|
|
44
|
+
{ customer: '甲公司', region: '华东', orderNo: 'O-1002', amount: 200, orderDate: '2024-01-12' },
|
|
45
|
+
{ customer: '甲公司', region: '华东', orderNo: 'O-1003', amount: 150, orderDate: '2024-01-20' },
|
|
46
|
+
{ customer: '甲公司', region: '华东', orderNo: 'O-1004', amount: 180, orderDate: '2024-01-28' },
|
|
47
|
+
{ customer: '乙公司', region: '华南', orderNo: 'O-2001', amount: 300, orderDate: '2024-02-01' },
|
|
48
|
+
{ customer: '乙公司', region: '华南', orderNo: 'O-2002', amount: 250, orderDate: '2024-02-08' },
|
|
49
|
+
{ customer: '乙公司', region: '华南', orderNo: 'O-2003', amount: 220, orderDate: '2024-02-15' },
|
|
50
|
+
{ customer: '乙公司', region: '华南', orderNo: 'O-2004', amount: 280, orderDate: '2024-02-22' },
|
|
51
|
+
{ customer: '丙公司', region: '华北', orderNo: 'O-3001', amount: 400, orderDate: '2024-03-01' },
|
|
52
|
+
{ customer: '丙公司', region: '华北', orderNo: 'O-3002', amount: 350, orderDate: '2024-03-10' },
|
|
53
|
+
{ customer: '丙公司', region: '华北', orderNo: 'O-3003', amount: 320, orderDate: '2024-03-18' },
|
|
54
|
+
{ customer: '丁公司', region: '西部', orderNo: 'O-4001', amount: 500, orderDate: '2024-04-02' },
|
|
55
|
+
{ customer: '丁公司', region: '西部', orderNo: 'O-4002', amount: 450, orderDate: '2024-04-11' },
|
|
56
|
+
{ customer: '丁公司', region: '西部', orderNo: 'O-4003', amount: 480, orderDate: '2024-04-20' }
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
const CUSTOMER_ROWS: Record<string, unknown>[] = [
|
|
60
|
+
{ id: 'C-01', name: '甲公司', region: '华东' },
|
|
61
|
+
{ id: 'C-02', name: '乙公司', region: '华南' },
|
|
62
|
+
{ id: 'C-03', name: '丙公司', region: '华北' },
|
|
63
|
+
{ id: 'C-04', name: '丁公司', region: '西部' },
|
|
64
|
+
{ id: 'C-05', name: '戊公司', region: '华东' },
|
|
65
|
+
{ id: 'C-06', name: '己公司', region: '华南' },
|
|
66
|
+
{ id: 'C-07', name: '庚公司', region: '华北' },
|
|
67
|
+
{ id: 'C-08', name: '辛公司', region: '西部' }
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
/** 地区 × 品类矩阵交叉数据(4 地区 × 5 品类 = 20 行) */
|
|
71
|
+
const SALES_MATRIX_ROWS: Record<string, unknown>[] = [
|
|
72
|
+
{ region: '华东', category: '办公设备', qty: 42, amount: 50400, month: '2024-Q1' },
|
|
73
|
+
{ region: '华东', category: '耗材', qty: 128, amount: 8640, month: '2024-Q1' },
|
|
74
|
+
{ region: '华东', category: '家具', qty: 18, amount: 46440, month: '2024-Q1' },
|
|
75
|
+
{ region: '华东', category: '外设', qty: 35, amount: 73465, month: '2024-Q1' },
|
|
76
|
+
{ region: '华东', category: '网络', qty: 12, amount: 8640, month: '2024-Q1' },
|
|
77
|
+
{ region: '华南', category: '办公设备', qty: 28, amount: 33600, month: '2024-Q1' },
|
|
78
|
+
{ region: '华南', category: '耗材', qty: 96, amount: 6480, month: '2024-Q1' },
|
|
79
|
+
{ region: '华南', category: '家具', qty: 22, amount: 56760, month: '2024-Q1' },
|
|
80
|
+
{ region: '华南', category: '外设', qty: 30, amount: 62970, month: '2024-Q1' },
|
|
81
|
+
{ region: '华南', category: '网络', qty: 8, amount: 5760, month: '2024-Q1' },
|
|
82
|
+
{ region: '华北', category: '办公设备', qty: 20, amount: 24000, month: '2024-Q1' },
|
|
83
|
+
{ region: '华北', category: '耗材', qty: 72, amount: 4860, month: '2024-Q1' },
|
|
84
|
+
{ region: '华北', category: '家具', qty: 14, amount: 36120, month: '2024-Q1' },
|
|
85
|
+
{ region: '华北', category: '外设', qty: 18, amount: 37782, month: '2024-Q1' },
|
|
86
|
+
{ region: '华北', category: '网络', qty: 10, amount: 7200, month: '2024-Q1' },
|
|
87
|
+
{ region: '西部', category: '办公设备', qty: 16, amount: 19200, month: '2024-Q1' },
|
|
88
|
+
{ region: '西部', category: '耗材', qty: 54, amount: 3645, month: '2024-Q1' },
|
|
89
|
+
{ region: '西部', category: '家具', qty: 12, amount: 30960, month: '2024-Q1' },
|
|
90
|
+
{ region: '西部', category: '外设', qty: 14, amount: 29386, month: '2024-Q1' },
|
|
91
|
+
{ region: '西部', category: '网络', qty: 6, amount: 4320, month: '2024-Q1' }
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
const MOCK_DATA_RECORDS: DatasetRecords = { orders: ORDER_ROWS, customers: CUSTOMER_ROWS }
|
|
95
|
+
|
|
96
|
+
// ---- 内联模板种子 ----
|
|
97
|
+
|
|
98
|
+
/** 预置 Report Template:表头(5 列)+ 同一扩展带(分组 + 明细)+ 合计行 */
|
|
99
|
+
function seedGroupDetailTemplate(sheet: Sheet): void {
|
|
100
|
+
sheet.setCells([
|
|
101
|
+
{ addr: { row: 0, col: 0 }, data: { v: '客户' } },
|
|
102
|
+
{ addr: { row: 0, col: 1 }, data: { v: '订单号' } },
|
|
103
|
+
{ addr: { row: 0, col: 2 }, data: { v: '地区' } },
|
|
104
|
+
{ addr: { row: 0, col: 3 }, data: { v: '金额' } },
|
|
105
|
+
{ addr: { row: 0, col: 4 }, data: { v: '下单日期' } },
|
|
106
|
+
{ addr: { row: 2, col: 1 }, data: { v: '合计' } }
|
|
107
|
+
])
|
|
108
|
+
|
|
109
|
+
sheet.setCellStyle(
|
|
110
|
+
{ start: { row: 0, col: 0 }, end: { row: 0, col: 4 } },
|
|
111
|
+
{ font: { bold: true }, fill: { color: '#E8EEF7' } }
|
|
112
|
+
)
|
|
113
|
+
sheet.setCellStyle(
|
|
114
|
+
{ start: { row: 2, col: 0 }, end: { row: 2, col: 4 } },
|
|
115
|
+
{ font: { bold: true } }
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
const groupParent = { row: 1, col: 0 }
|
|
119
|
+
|
|
120
|
+
const customerGroup = createReportBinding(ORDERS_DATASET, 'customer')
|
|
121
|
+
customerGroup.preset = 'groupHeader'
|
|
122
|
+
customerGroup.aggregate = 'group'
|
|
123
|
+
customerGroup.expand = 'down'
|
|
124
|
+
sheet.setCellMeta(groupParent, REPORT_META_NAMESPACE, customerGroup)
|
|
125
|
+
|
|
126
|
+
const orderNo = createReportBinding(ORDERS_DATASET, 'orderNo')
|
|
127
|
+
orderNo.rowParent = groupParent
|
|
128
|
+
sheet.setCellMeta({ row: 1, col: 1 }, REPORT_META_NAMESPACE, orderNo)
|
|
129
|
+
|
|
130
|
+
const region = createReportBinding(ORDERS_DATASET, 'region')
|
|
131
|
+
region.rowParent = groupParent
|
|
132
|
+
sheet.setCellMeta({ row: 1, col: 2 }, REPORT_META_NAMESPACE, region)
|
|
133
|
+
|
|
134
|
+
const amount = createReportBinding(ORDERS_DATASET, 'amount')
|
|
135
|
+
amount.rowParent = groupParent
|
|
136
|
+
sheet.setCellMeta({ row: 1, col: 3 }, REPORT_META_NAMESPACE, amount)
|
|
137
|
+
|
|
138
|
+
const orderDate = createReportBinding(ORDERS_DATASET, 'orderDate')
|
|
139
|
+
orderDate.rowParent = groupParent
|
|
140
|
+
sheet.setCellMeta({ row: 1, col: 4 }, REPORT_META_NAMESPACE, orderDate)
|
|
141
|
+
|
|
142
|
+
const subtotal = createReportBinding(ORDERS_DATASET, 'amount')
|
|
143
|
+
subtotal.preset = 'subtotal'
|
|
144
|
+
subtotal.aggregate = 'sum'
|
|
145
|
+
subtotal.expand = 'none'
|
|
146
|
+
subtotal.rowParent = groupParent
|
|
147
|
+
sheet.setCellMeta({ row: 2, col: 3 }, REPORT_META_NAMESPACE, subtotal)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 预置二维矩阵模板:地区(行)× 品类(列)销售额交叉表 */
|
|
151
|
+
function seedMatrixTemplate(sheet: Sheet): void {
|
|
152
|
+
sheet.setCells([
|
|
153
|
+
{ addr: { row: 0, col: 0 }, data: { v: '地区 \\ 品类' } },
|
|
154
|
+
{ addr: { row: 2, col: 0 }, data: { v: '合计' } }
|
|
155
|
+
])
|
|
156
|
+
|
|
157
|
+
sheet.setCellStyle(
|
|
158
|
+
{ start: { row: 0, col: 0 }, end: { row: 0, col: 0 } },
|
|
159
|
+
{ font: { bold: true }, fill: { color: '#E8EEF7' } }
|
|
160
|
+
)
|
|
161
|
+
sheet.setCellStyle(
|
|
162
|
+
{ start: { row: 2, col: 0 }, end: { row: 2, col: 0 } },
|
|
163
|
+
{ font: { bold: true } }
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
const colGroupAddr = { row: 0, col: 1 }
|
|
167
|
+
const rowGroupAddr = { row: 1, col: 0 }
|
|
168
|
+
const crossAddr = { row: 1, col: 1 }
|
|
169
|
+
|
|
170
|
+
const categoryGroup = createReportBinding(SALES_MATRIX_DATASET, 'category')
|
|
171
|
+
categoryGroup.preset = 'groupHeader'
|
|
172
|
+
categoryGroup.aggregate = 'group'
|
|
173
|
+
categoryGroup.expand = 'right'
|
|
174
|
+
sheet.setCellMeta(colGroupAddr, REPORT_META_NAMESPACE, categoryGroup)
|
|
175
|
+
|
|
176
|
+
const regionGroup = createReportBinding(SALES_MATRIX_DATASET, 'region')
|
|
177
|
+
regionGroup.preset = 'groupHeader'
|
|
178
|
+
regionGroup.aggregate = 'group'
|
|
179
|
+
regionGroup.expand = 'down'
|
|
180
|
+
sheet.setCellMeta(rowGroupAddr, REPORT_META_NAMESPACE, regionGroup)
|
|
181
|
+
|
|
182
|
+
const cross = createReportBinding(SALES_MATRIX_DATASET, 'amount')
|
|
183
|
+
cross.preset = 'cross'
|
|
184
|
+
cross.aggregate = 'sum'
|
|
185
|
+
cross.expand = 'none'
|
|
186
|
+
cross.rowParent = rowGroupAddr
|
|
187
|
+
cross.colParent = colGroupAddr
|
|
188
|
+
sheet.setCellMeta(crossAddr, REPORT_META_NAMESPACE, cross)
|
|
189
|
+
|
|
190
|
+
const colSubtotal = createReportBinding(SALES_MATRIX_DATASET, 'amount')
|
|
191
|
+
colSubtotal.preset = 'subtotal'
|
|
192
|
+
colSubtotal.aggregate = 'sum'
|
|
193
|
+
colSubtotal.expand = 'none'
|
|
194
|
+
colSubtotal.colParent = colGroupAddr
|
|
195
|
+
sheet.setCellMeta({ row: 2, col: 1 }, REPORT_META_NAMESPACE, colSubtotal)
|
|
196
|
+
|
|
197
|
+
const grandTotal = createReportBinding(SALES_MATRIX_DATASET, 'amount')
|
|
198
|
+
grandTotal.preset = 'grandTotal'
|
|
199
|
+
grandTotal.aggregate = 'sum'
|
|
200
|
+
grandTotal.expand = 'none'
|
|
201
|
+
sheet.setCellMeta({ row: 2, col: 6 }, REPORT_META_NAMESPACE, grandTotal)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function buildGroupDetailTemplate() {
|
|
205
|
+
const sheet = new Sheet()
|
|
206
|
+
seedGroupDetailTemplate(sheet)
|
|
207
|
+
return sheet.snapshot()
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function cellValue(
|
|
211
|
+
snapshot: ReturnType<typeof buildGroupDetailTemplate>,
|
|
212
|
+
row: number,
|
|
213
|
+
col: number
|
|
214
|
+
): unknown {
|
|
215
|
+
return snapshot.cells.find((c) => c.row === row && c.col === col)?.v
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function hasMerge(
|
|
219
|
+
snapshot: ReturnType<typeof buildGroupDetailTemplate>,
|
|
220
|
+
start: { row: number; col: number },
|
|
221
|
+
end: { row: number; col: number }
|
|
222
|
+
): boolean {
|
|
223
|
+
return snapshot.merges.some(
|
|
224
|
+
(m) =>
|
|
225
|
+
m.start.row === start.row &&
|
|
226
|
+
m.start.col === start.col &&
|
|
227
|
+
m.end.row === end.row &&
|
|
228
|
+
m.end.col === end.col
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function buildMatrixTemplate() {
|
|
233
|
+
const sheet = new Sheet()
|
|
234
|
+
seedMatrixTemplate(sheet)
|
|
235
|
+
return sheet.snapshot()
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
describe('renderReport', () => {
|
|
239
|
+
it('4 客户 14 订单:行数、分组值、明细 zip、地区列与组小计', () => {
|
|
240
|
+
const template = buildGroupDetailTemplate()
|
|
241
|
+
const filled = renderReport(template, MOCK_DATA_RECORDS)
|
|
242
|
+
|
|
243
|
+
// 表头 1 + 甲(4+1) + 乙(4+1) + 丙(3+1) + 丁(3+1) = 19 行
|
|
244
|
+
expect(filled.rows).toBe(19)
|
|
245
|
+
expect(filled.meta).toBeUndefined()
|
|
246
|
+
|
|
247
|
+
// 表头保留(含地区列)
|
|
248
|
+
expect(cellValue(filled, 0, 0)).toBe('客户')
|
|
249
|
+
expect(cellValue(filled, 0, 1)).toBe('订单号')
|
|
250
|
+
expect(cellValue(filled, 0, 2)).toBe('地区')
|
|
251
|
+
expect(cellValue(filled, 0, 3)).toBe('金额')
|
|
252
|
+
expect(cellValue(filled, 0, 4)).toBe('下单日期')
|
|
253
|
+
|
|
254
|
+
// 甲公司:4 明细 + 小计 630(金额在 col 3)
|
|
255
|
+
expect(cellValue(filled, 1, 0)).toBe('甲公司')
|
|
256
|
+
expect(cellValue(filled, 1, 1)).toBe('O-1001')
|
|
257
|
+
expect(cellValue(filled, 1, 2)).toBe('华东')
|
|
258
|
+
expect(cellValue(filled, 1, 3)).toBe(100)
|
|
259
|
+
expect(cellValue(filled, 2, 1)).toBe('O-1002')
|
|
260
|
+
expect(cellValue(filled, 3, 1)).toBe('O-1003')
|
|
261
|
+
expect(cellValue(filled, 4, 1)).toBe('O-1004')
|
|
262
|
+
expect(cellValue(filled, 5, 1)).toBe('合计')
|
|
263
|
+
expect(cellValue(filled, 5, 3)).toBe(630)
|
|
264
|
+
|
|
265
|
+
// 乙公司:4 明细 + 小计 1050
|
|
266
|
+
expect(cellValue(filled, 6, 0)).toBe('乙公司')
|
|
267
|
+
expect(cellValue(filled, 6, 1)).toBe('O-2001')
|
|
268
|
+
expect(cellValue(filled, 6, 2)).toBe('华南')
|
|
269
|
+
expect(cellValue(filled, 9, 1)).toBe('O-2004')
|
|
270
|
+
expect(cellValue(filled, 10, 1)).toBe('合计')
|
|
271
|
+
expect(cellValue(filled, 10, 3)).toBe(1050)
|
|
272
|
+
|
|
273
|
+
// 丙公司:3 明细 + 小计 1070
|
|
274
|
+
expect(cellValue(filled, 11, 0)).toBe('丙公司')
|
|
275
|
+
expect(cellValue(filled, 11, 2)).toBe('华北')
|
|
276
|
+
expect(cellValue(filled, 14, 1)).toBe('合计')
|
|
277
|
+
expect(cellValue(filled, 14, 3)).toBe(1070)
|
|
278
|
+
|
|
279
|
+
// 丁公司:3 明细 + 小计 1430
|
|
280
|
+
expect(cellValue(filled, 15, 0)).toBe('丁公司')
|
|
281
|
+
expect(cellValue(filled, 15, 2)).toBe('西部')
|
|
282
|
+
expect(cellValue(filled, 18, 1)).toBe('合计')
|
|
283
|
+
expect(cellValue(filled, 18, 3)).toBe(1430)
|
|
284
|
+
|
|
285
|
+
// 分组格纵向 merge 覆盖明细行(不含小计行)
|
|
286
|
+
expect(hasMerge(filled, { row: 1, col: 0 }, { row: 4, col: 0 })).toBe(true)
|
|
287
|
+
expect(hasMerge(filled, { row: 6, col: 0 }, { row: 9, col: 0 })).toBe(true)
|
|
288
|
+
expect(hasMerge(filled, { row: 11, col: 0 }, { row: 13, col: 0 })).toBe(true)
|
|
289
|
+
expect(hasMerge(filled, { row: 15, col: 0 }, { row: 17, col: 0 })).toBe(true)
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
it('分组格被误设为 list 时按明细全量展开(无分组锚点)', () => {
|
|
293
|
+
const template = buildGroupDetailTemplate()
|
|
294
|
+
const broken = JSON.parse(JSON.stringify(template)) as ReturnType<
|
|
295
|
+
typeof buildGroupDetailTemplate
|
|
296
|
+
>
|
|
297
|
+
const groupMeta = broken.meta!.find((m) => m.row === 1 && m.col === 0)!
|
|
298
|
+
;(groupMeta.payload as { aggregate: string }).aggregate = 'list'
|
|
299
|
+
|
|
300
|
+
const filled = renderReport(broken, MOCK_DATA_RECORDS)
|
|
301
|
+
// 分组格误设为 list 时按全量明细展开 + 小计
|
|
302
|
+
expect(filled.rows).toBe(1 + ORDER_ROWS.length + 1)
|
|
303
|
+
expect(cellValue(filled, 1, 1)).toBe('O-1001')
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
it('Filled Report 不携带 Binding meta', () => {
|
|
307
|
+
const template = buildGroupDetailTemplate()
|
|
308
|
+
const filled = renderReport(template, MOCK_DATA_RECORDS)
|
|
309
|
+
expect(filled.meta?.length ?? 0).toBe(0)
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
it('模板样式 id 随扩展实例复制', () => {
|
|
313
|
+
const sheet = new Sheet()
|
|
314
|
+
seedGroupDetailTemplate(sheet)
|
|
315
|
+
// 金额列在 col 3
|
|
316
|
+
sheet.setCellStyle(
|
|
317
|
+
{ start: { row: 1, col: 3 }, end: { row: 1, col: 3 } },
|
|
318
|
+
{ font: { bold: true } }
|
|
319
|
+
)
|
|
320
|
+
const styleId = sheet.getCellData({ row: 1, col: 3 })?.s
|
|
321
|
+
expect(styleId).toBeDefined()
|
|
322
|
+
|
|
323
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
324
|
+
const firstAmount = filled.cells.find((c) => c.row === 1 && c.col === 3)
|
|
325
|
+
expect(firstAmount?.s).toBe(styleId)
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
it('subtotal 支持 avg / count 聚合', () => {
|
|
329
|
+
const sheet = new Sheet()
|
|
330
|
+
seedGroupDetailTemplate(sheet)
|
|
331
|
+
sheet.setCellMeta({ row: 2, col: 3 }, REPORT_META_NAMESPACE, {
|
|
332
|
+
dataset: 'orders',
|
|
333
|
+
field: 'amount',
|
|
334
|
+
preset: 'subtotal',
|
|
335
|
+
aggregate: 'avg',
|
|
336
|
+
expand: 'none',
|
|
337
|
+
rowParent: { row: 1, col: 0 }
|
|
338
|
+
})
|
|
339
|
+
const avgFilled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
340
|
+
// 甲公司 4 单金额均值 (100+200+150+180)/4 = 157.5
|
|
341
|
+
expect(avgFilled.cells.find((c) => c.row === 5 && c.col === 3)?.v).toBe(157.5)
|
|
342
|
+
|
|
343
|
+
const sheet2 = new Sheet()
|
|
344
|
+
seedGroupDetailTemplate(sheet2)
|
|
345
|
+
sheet2.setCellMeta({ row: 2, col: 3 }, REPORT_META_NAMESPACE, {
|
|
346
|
+
dataset: 'orders',
|
|
347
|
+
field: 'orderNo',
|
|
348
|
+
preset: 'subtotal',
|
|
349
|
+
aggregate: 'count',
|
|
350
|
+
expand: 'none',
|
|
351
|
+
rowParent: { row: 1, col: 0 }
|
|
352
|
+
})
|
|
353
|
+
const countFilled = renderReport(sheet2.snapshot(), MOCK_DATA_RECORDS)
|
|
354
|
+
expect(countFilled.cells.find((c) => c.row === 5 && c.col === 3)?.v).toBe(4)
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
it('grandTotal 行对全量数据汇总', () => {
|
|
358
|
+
const sheet = new Sheet()
|
|
359
|
+
seedGroupDetailTemplate(sheet)
|
|
360
|
+
sheet.setCells([{ addr: { row: 3, col: 1 }, data: { v: '总计' } }])
|
|
361
|
+
sheet.setCellMeta({ row: 3, col: 3 }, REPORT_META_NAMESPACE, {
|
|
362
|
+
dataset: 'orders',
|
|
363
|
+
field: 'amount',
|
|
364
|
+
preset: 'grandTotal',
|
|
365
|
+
aggregate: 'sum',
|
|
366
|
+
expand: 'none'
|
|
367
|
+
})
|
|
368
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
369
|
+
// 全量金额 4180
|
|
370
|
+
expect(filled.cells.find((c) => c.v === 4180 && c.col === 3)?.v).toBe(4180)
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
it('条件样式规则固化到 Filled Report 样式表', () => {
|
|
374
|
+
const sheet = new Sheet()
|
|
375
|
+
seedGroupDetailTemplate(sheet)
|
|
376
|
+
sheet.setCellMeta({ row: 1, col: 3 }, REPORT_META_NAMESPACE, {
|
|
377
|
+
dataset: 'orders',
|
|
378
|
+
field: 'amount',
|
|
379
|
+
preset: 'detail',
|
|
380
|
+
aggregate: 'list',
|
|
381
|
+
expand: 'down',
|
|
382
|
+
rowParent: { row: 1, col: 0 },
|
|
383
|
+
conditionalRules: [{ operator: 'gt', value: 100, style: { fill: { color: '#FFCCCC' } } }]
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
387
|
+
const hotCell = filled.cells.find((c) => c.col === 3 && c.v === 150)
|
|
388
|
+
expect(hotCell?.s).toBeDefined()
|
|
389
|
+
expect(filled.styles[(hotCell!.s ?? 1) - 1]?.fill?.color).toBe('#FFCCCC')
|
|
390
|
+
|
|
391
|
+
const coldCell = filled.cells.find((c) => c.col === 3 && c.v === 100)
|
|
392
|
+
expect(filled.styles[(coldCell!.s ?? 1) - 1]?.fill?.color).not.toBe('#FFCCCC')
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
it('条件样式按另一字段求值', () => {
|
|
396
|
+
const sheet = new Sheet()
|
|
397
|
+
seedGroupDetailTemplate(sheet)
|
|
398
|
+
sheet.setCellMeta({ row: 1, col: 3 }, REPORT_META_NAMESPACE, {
|
|
399
|
+
dataset: 'orders',
|
|
400
|
+
field: 'amount',
|
|
401
|
+
preset: 'detail',
|
|
402
|
+
aggregate: 'list',
|
|
403
|
+
expand: 'down',
|
|
404
|
+
rowParent: { row: 1, col: 0 },
|
|
405
|
+
conditionalRules: [
|
|
406
|
+
{ operator: 'eq', value: '华东', field: 'region', style: { fill: { color: '#FFCCCC' } } }
|
|
407
|
+
]
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
411
|
+
const eastCell = filled.cells.find((c) => c.col === 3 && c.v === 150)
|
|
412
|
+
expect(filled.styles[(eastCell!.s ?? 1) - 1]?.fill?.color).toBe('#FFCCCC')
|
|
413
|
+
|
|
414
|
+
const southCell = filled.cells.find((c) => c.col === 3 && c.v === 300)
|
|
415
|
+
expect(filled.styles[(southCell!.s ?? 1) - 1]?.fill?.color).not.toBe('#FFCCCC')
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
it('scope: row 染满整行含静态格与横向展开列', () => {
|
|
419
|
+
const sheet = new Sheet()
|
|
420
|
+
seedGroupDetailTemplate(sheet)
|
|
421
|
+
sheet.setCellMeta({ row: 1, col: 3 }, REPORT_META_NAMESPACE, {
|
|
422
|
+
dataset: 'orders',
|
|
423
|
+
field: 'amount',
|
|
424
|
+
preset: 'detail',
|
|
425
|
+
aggregate: 'list',
|
|
426
|
+
expand: 'down',
|
|
427
|
+
rowParent: { row: 1, col: 0 },
|
|
428
|
+
conditionalRules: [
|
|
429
|
+
{ operator: 'gt', value: 100, scope: 'row', style: { fill: { color: '#FFCCCC' } } }
|
|
430
|
+
]
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
434
|
+
const hotRow = filled.cells.find((c) => c.col === 3 && c.v === 150)!.row
|
|
435
|
+
const hotStyle =
|
|
436
|
+
filled.styles[(filled.cells.find((c) => c.col === 3 && c.v === 150)!.s ?? 1) - 1]
|
|
437
|
+
expect(hotStyle?.fill?.color).toBe('#FFCCCC')
|
|
438
|
+
|
|
439
|
+
const staticOrderNo = filled.cells.find(
|
|
440
|
+
(c) => c.row === hotRow && c.col === 1 && c.v === 'O-1003'
|
|
441
|
+
)
|
|
442
|
+
expect(filled.styles[(staticOrderNo!.s ?? 1) - 1]?.fill?.color).toBe('#FFCCCC')
|
|
443
|
+
|
|
444
|
+
const coldRow = filled.cells.find((c) => c.col === 3 && c.v === 100)!.row
|
|
445
|
+
const coldAmount = filled.cells.find((c) => c.row === coldRow && c.col === 3)
|
|
446
|
+
expect(filled.styles[(coldAmount!.s ?? 1) - 1]?.fill?.color).not.toBe('#FFCCCC')
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
it('横向展开明细列同行继承 scope: row 行级样式', () => {
|
|
450
|
+
const sheet = new Sheet()
|
|
451
|
+
sheet.setCells([{ addr: { row: 0, col: 0 }, data: { v: '备注' } }])
|
|
452
|
+
const amount = createReportBinding(ORDERS_DATASET, 'amount')
|
|
453
|
+
amount.aggregate = 'list'
|
|
454
|
+
amount.expand = 'right'
|
|
455
|
+
amount.conditionalRules = [
|
|
456
|
+
{ operator: 'gt', value: 100, scope: 'row', style: { fill: { color: '#FFCCCC' } } }
|
|
457
|
+
]
|
|
458
|
+
sheet.setCellMeta({ row: 0, col: 1 }, REPORT_META_NAMESPACE, amount)
|
|
459
|
+
|
|
460
|
+
const filled = renderReport(sheet.snapshot(), { orders: [ORDER_ROWS[2]!] })
|
|
461
|
+
const amountCell = filled.cells.find((c) => c.row === 0 && c.v === 150)
|
|
462
|
+
const staticNote = filled.cells.find((c) => c.row === 0 && c.col === 0)
|
|
463
|
+
expect(filled.styles[(amountCell!.s ?? 1) - 1]?.fill?.color).toBe('#FFCCCC')
|
|
464
|
+
expect(filled.styles[(staticNote!.s ?? 1) - 1]?.fill?.color).toBe('#FFCCCC')
|
|
465
|
+
|
|
466
|
+
const coldFilled = renderReport(sheet.snapshot(), { orders: [ORDER_ROWS[0]!] })
|
|
467
|
+
const coldAmount = coldFilled.cells.find((c) => c.row === 0 && c.v === 100)
|
|
468
|
+
expect(coldFilled.styles[(coldAmount!.s ?? 1) - 1]?.fill?.color).not.toBe('#FFCCCC')
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
it('二维矩阵:地区 × 品类销售额交叉扩展', () => {
|
|
472
|
+
const filled = renderReport(buildMatrixTemplate(), { 'sales-matrix': SALES_MATRIX_ROWS })
|
|
473
|
+
|
|
474
|
+
// 表头 1 + 4 地区 + 1 合计 = 6 行
|
|
475
|
+
expect(filled.rows).toBe(6)
|
|
476
|
+
expect(cellValue(filled, 0, 0)).toBe('地区 \\ 品类')
|
|
477
|
+
expect(cellValue(filled, 0, 1)).toBe('办公设备')
|
|
478
|
+
expect(cellValue(filled, 0, 5)).toBe('网络')
|
|
479
|
+
|
|
480
|
+
// 华东 × 办公设备 = 50400
|
|
481
|
+
expect(cellValue(filled, 1, 0)).toBe('华东')
|
|
482
|
+
expect(cellValue(filled, 1, 1)).toBe(50400)
|
|
483
|
+
|
|
484
|
+
// 列合计:办公设备四地区之和
|
|
485
|
+
const officeTotal = SALES_MATRIX_ROWS.filter((r) => r.category === '办公设备').reduce(
|
|
486
|
+
(sum, row) => sum + (row.amount as number),
|
|
487
|
+
0
|
|
488
|
+
)
|
|
489
|
+
expect(cellValue(filled, 5, 1)).toBe(officeTotal)
|
|
490
|
+
|
|
491
|
+
// 总计
|
|
492
|
+
const grandTotal = SALES_MATRIX_ROWS.reduce((sum, row) => sum + (row.amount as number), 0)
|
|
493
|
+
expect(cellValue(filled, 5, 6)).toBe(grandTotal)
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
it('同扩展带追加明细列:预览行数与值正确', () => {
|
|
497
|
+
const sheet = new Sheet()
|
|
498
|
+
seedGroupDetailTemplate(sheet)
|
|
499
|
+
sheet.setCells([{ addr: { row: 0, col: 5 }, data: { v: '备注' } }])
|
|
500
|
+
const remark = createReportBinding(ORDERS_DATASET, 'orderNo')
|
|
501
|
+
remark.rowParent = { row: 1, col: 0 }
|
|
502
|
+
sheet.setCellMeta({ row: 1, col: 5 }, REPORT_META_NAMESPACE, remark)
|
|
503
|
+
|
|
504
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
505
|
+
expect(filled.rows).toBe(19)
|
|
506
|
+
expect(cellValue(filled, 1, 0)).toBe('甲公司')
|
|
507
|
+
expect(cellValue(filled, 1, 1)).toBe('O-1001')
|
|
508
|
+
expect(cellValue(filled, 1, 5)).toBe('O-1001')
|
|
509
|
+
})
|
|
510
|
+
|
|
511
|
+
it('独立扩展带:第二数据源 customers 明细正确渲染', () => {
|
|
512
|
+
const sheet = new Sheet()
|
|
513
|
+
seedGroupDetailTemplate(sheet)
|
|
514
|
+
sheet.setCells([{ addr: { row: 0, col: 5 }, data: { v: '客户ID' } }])
|
|
515
|
+
const customerId = createReportBinding(CUSTOMERS_DATASET, 'id')
|
|
516
|
+
customerId.expand = 'down'
|
|
517
|
+
customerId.aggregate = 'list'
|
|
518
|
+
sheet.setCellMeta({ row: 4, col: 5 }, REPORT_META_NAMESPACE, customerId)
|
|
519
|
+
|
|
520
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
521
|
+
const customers = CUSTOMER_ROWS
|
|
522
|
+
|
|
523
|
+
// 订单扩展 19 行(含表头)+ 客户列表
|
|
524
|
+
expect(filled.rows).toBe(19 + customers.length)
|
|
525
|
+
expect(cellValue(filled, 0, 5)).toBe('客户ID')
|
|
526
|
+
expect(cellValue(filled, 19, 5)).toBe(customers[0]!.id)
|
|
527
|
+
expect(cellValue(filled, 19 + customers.length - 1, 5)).toBe(
|
|
528
|
+
customers[customers.length - 1]!.id
|
|
529
|
+
)
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
it('多行扩展带合并明细输出:分组列与首行明细不丢失', () => {
|
|
533
|
+
const sheet = new Sheet()
|
|
534
|
+
seedGroupDetailTemplate(sheet)
|
|
535
|
+
sheet.clearCellMeta({ row: 1, col: 3 }, REPORT_META_NAMESPACE)
|
|
536
|
+
sheet.clearCellMeta({ row: 1, col: 4 }, REPORT_META_NAMESPACE)
|
|
537
|
+
sheet.clearCellMeta({ row: 2, col: 3 }, REPORT_META_NAMESPACE)
|
|
538
|
+
const snap = sheet.snapshot()
|
|
539
|
+
snap.cells = snap.cells.filter((cell) => !(cell.row === 2 && cell.col === 1))
|
|
540
|
+
sheet.restore(snap)
|
|
541
|
+
sheet.restoreContent(snap)
|
|
542
|
+
|
|
543
|
+
const amount = createReportBinding(ORDERS_DATASET, 'amount')
|
|
544
|
+
amount.rowParent = { row: 1, col: 0 }
|
|
545
|
+
sheet.setCellMeta({ row: 2, col: 3 }, REPORT_META_NAMESPACE, amount)
|
|
546
|
+
|
|
547
|
+
const orderDate = createReportBinding(ORDERS_DATASET, 'orderDate')
|
|
548
|
+
orderDate.rowParent = { row: 1, col: 0 }
|
|
549
|
+
sheet.setCellMeta({ row: 2, col: 4 }, REPORT_META_NAMESPACE, orderDate)
|
|
550
|
+
|
|
551
|
+
const subtotal = createReportBinding(ORDERS_DATASET, 'amount')
|
|
552
|
+
subtotal.preset = 'subtotal'
|
|
553
|
+
subtotal.aggregate = 'sum'
|
|
554
|
+
subtotal.expand = 'none'
|
|
555
|
+
subtotal.rowParent = { row: 1, col: 0 }
|
|
556
|
+
sheet.setCellMeta({ row: 3, col: 3 }, REPORT_META_NAMESPACE, subtotal)
|
|
557
|
+
sheet.setCells([{ addr: { row: 3, col: 1 }, data: { v: '合计' } }])
|
|
558
|
+
|
|
559
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
560
|
+
expect(filled.rows).toBe(19)
|
|
561
|
+
expect(cellValue(filled, 1, 0)).toBe('甲公司')
|
|
562
|
+
expect(cellValue(filled, 1, 1)).toBe('O-1001')
|
|
563
|
+
expect(cellValue(filled, 1, 3)).toBe(100)
|
|
564
|
+
expect(cellValue(filled, 1, 4)).toBe('2024-01-05')
|
|
565
|
+
expect(cellValue(filled, 5, 3)).toBe(630)
|
|
566
|
+
})
|
|
567
|
+
|
|
568
|
+
it('横向展开 right + group:列头向右延展', () => {
|
|
569
|
+
const sheet = new Sheet()
|
|
570
|
+
sheet.setCells([{ addr: { row: 0, col: 0 }, data: { v: '品类' } }])
|
|
571
|
+
const category = createReportBinding(SALES_MATRIX_DATASET, 'category')
|
|
572
|
+
category.aggregate = 'group'
|
|
573
|
+
category.expand = 'right'
|
|
574
|
+
sheet.setCellMeta({ row: 0, col: 1 }, REPORT_META_NAMESPACE, category)
|
|
575
|
+
|
|
576
|
+
const filled = renderReport(sheet.snapshot(), { 'sales-matrix': SALES_MATRIX_ROWS })
|
|
577
|
+
expect(cellValue(filled, 0, 1)).toBe('办公设备')
|
|
578
|
+
expect(cellValue(filled, 0, 5)).toBe('网络')
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
it('转置明细 right + list:一条记录一列', () => {
|
|
582
|
+
const sheet = new Sheet()
|
|
583
|
+
sheet.setCells([{ addr: { row: 0, col: 0 }, data: { v: '订单号' } }])
|
|
584
|
+
const orderNo = createReportBinding(ORDERS_DATASET, 'orderNo')
|
|
585
|
+
orderNo.aggregate = 'list'
|
|
586
|
+
orderNo.expand = 'right'
|
|
587
|
+
sheet.setCellMeta({ row: 0, col: 1 }, REPORT_META_NAMESPACE, orderNo)
|
|
588
|
+
|
|
589
|
+
const filled = renderReport(sheet.snapshot(), { orders: ORDER_ROWS.slice(0, 3) })
|
|
590
|
+
expect(cellValue(filled, 0, 1)).toBe('O-1001')
|
|
591
|
+
expect(cellValue(filled, 0, 2)).toBe('O-1002')
|
|
592
|
+
expect(cellValue(filled, 0, 3)).toBe('O-1003')
|
|
593
|
+
})
|
|
594
|
+
|
|
595
|
+
it('多级列头:年 → 季度列头值正确', () => {
|
|
596
|
+
const sheet = new Sheet()
|
|
597
|
+
const data = [
|
|
598
|
+
{ year: '2024', quarter: 'Q1', amount: 10 },
|
|
599
|
+
{ year: '2024', quarter: 'Q2', amount: 20 },
|
|
600
|
+
{ year: '2025', quarter: 'Q1', amount: 30 }
|
|
601
|
+
]
|
|
602
|
+
const year = createReportBinding({ id: 'sales', label: 's', fields: [] }, 'year')
|
|
603
|
+
year.aggregate = 'group'
|
|
604
|
+
year.expand = 'right'
|
|
605
|
+
sheet.setCellMeta({ row: 0, col: 0 }, REPORT_META_NAMESPACE, year)
|
|
606
|
+
|
|
607
|
+
const quarter = createReportBinding({ id: 'sales', label: 's', fields: [] }, 'quarter')
|
|
608
|
+
quarter.aggregate = 'group'
|
|
609
|
+
quarter.expand = 'right'
|
|
610
|
+
quarter.colParent = { row: 0, col: 0 }
|
|
611
|
+
sheet.setCellMeta({ row: 1, col: 0 }, REPORT_META_NAMESPACE, quarter)
|
|
612
|
+
|
|
613
|
+
const filled = renderReport(sheet.snapshot(), { sales: data })
|
|
614
|
+
expect(cellValue(filled, 0, 0)).toBe('2024')
|
|
615
|
+
expect(cellValue(filled, 0, 2)).toBe('2025')
|
|
616
|
+
expect(cellValue(filled, 1, 0)).toBe('Q1')
|
|
617
|
+
expect(cellValue(filled, 1, 1)).toBe('Q2')
|
|
618
|
+
expect(cellValue(filled, 1, 2)).toBe('Q1')
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
it('顶部标题行的交叉表照常展开', () => {
|
|
622
|
+
const sheet = new Sheet()
|
|
623
|
+
sheet.setCells([
|
|
624
|
+
{ addr: { row: 0, col: 0 }, data: { v: '销售交叉表' } },
|
|
625
|
+
{ addr: { row: 2, col: 0 }, data: { v: '合计' } }
|
|
626
|
+
])
|
|
627
|
+
|
|
628
|
+
const category = createReportBinding(SALES_MATRIX_DATASET, 'category')
|
|
629
|
+
category.aggregate = 'group'
|
|
630
|
+
category.expand = 'right'
|
|
631
|
+
sheet.setCellMeta({ row: 1, col: 1 }, REPORT_META_NAMESPACE, category)
|
|
632
|
+
|
|
633
|
+
const region = createReportBinding(SALES_MATRIX_DATASET, 'region')
|
|
634
|
+
region.aggregate = 'group'
|
|
635
|
+
region.expand = 'down'
|
|
636
|
+
sheet.setCellMeta({ row: 2, col: 0 }, REPORT_META_NAMESPACE, region)
|
|
637
|
+
|
|
638
|
+
const cross = createReportBinding(SALES_MATRIX_DATASET, 'amount')
|
|
639
|
+
cross.aggregate = 'sum'
|
|
640
|
+
cross.expand = 'none'
|
|
641
|
+
cross.rowParent = { row: 2, col: 0 }
|
|
642
|
+
cross.colParent = { row: 1, col: 1 }
|
|
643
|
+
sheet.setCellMeta({ row: 2, col: 1 }, REPORT_META_NAMESPACE, cross)
|
|
644
|
+
|
|
645
|
+
const filled = renderReport(sheet.snapshot(), { 'sales-matrix': SALES_MATRIX_ROWS })
|
|
646
|
+
expect(cellValue(filled, 0, 0)).toBe('销售交叉表')
|
|
647
|
+
expect(cellValue(filled, 1, 1)).toBe('办公设备')
|
|
648
|
+
expect(cellValue(filled, 2, 0)).toBe('华东')
|
|
649
|
+
expect(cellValue(filled, 2, 1)).toBe(50400)
|
|
650
|
+
})
|
|
651
|
+
|
|
652
|
+
it('空数据集:展开块为 0,表头仍输出', () => {
|
|
653
|
+
const filled = renderReport(buildGroupDetailTemplate(), { orders: [], customers: [] })
|
|
654
|
+
expect(filled.rows).toBe(1)
|
|
655
|
+
expect(cellValue(filled, 0, 0)).toBe('客户')
|
|
656
|
+
})
|
|
657
|
+
|
|
658
|
+
it('max / min 聚合', () => {
|
|
659
|
+
const sheet = new Sheet()
|
|
660
|
+
seedGroupDetailTemplate(sheet)
|
|
661
|
+
sheet.setCellMeta({ row: 2, col: 3 }, REPORT_META_NAMESPACE, {
|
|
662
|
+
dataset: 'orders',
|
|
663
|
+
field: 'amount',
|
|
664
|
+
preset: 'subtotal',
|
|
665
|
+
aggregate: 'max',
|
|
666
|
+
expand: 'none',
|
|
667
|
+
rowParent: { row: 1, col: 0 }
|
|
668
|
+
})
|
|
669
|
+
const maxFilled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
670
|
+
expect(maxFilled.cells.find((c) => c.row === 5 && c.col === 3)?.v).toBe(200)
|
|
671
|
+
|
|
672
|
+
const sheet2 = new Sheet()
|
|
673
|
+
seedGroupDetailTemplate(sheet2)
|
|
674
|
+
sheet2.setCellMeta({ row: 2, col: 3 }, REPORT_META_NAMESPACE, {
|
|
675
|
+
dataset: 'orders',
|
|
676
|
+
field: 'amount',
|
|
677
|
+
preset: 'subtotal',
|
|
678
|
+
aggregate: 'min',
|
|
679
|
+
expand: 'none',
|
|
680
|
+
rowParent: { row: 1, col: 0 }
|
|
681
|
+
})
|
|
682
|
+
const minFilled = renderReport(sheet2.snapshot(), MOCK_DATA_RECORDS)
|
|
683
|
+
expect(minFilled.cells.find((c) => c.row === 5 && c.col === 3)?.v).toBe(100)
|
|
684
|
+
})
|
|
685
|
+
|
|
686
|
+
it('mergeSpan: false 时扩展格不合并', () => {
|
|
687
|
+
const sheet = new Sheet()
|
|
688
|
+
const group = createReportBinding(ORDERS_DATASET, 'customer')
|
|
689
|
+
group.aggregate = 'group'
|
|
690
|
+
group.expand = 'down'
|
|
691
|
+
group.mergeSpan = false
|
|
692
|
+
sheet.setCellMeta({ row: 1, col: 0 }, REPORT_META_NAMESPACE, group)
|
|
693
|
+
|
|
694
|
+
const detail = createReportBinding(ORDERS_DATASET, 'orderNo')
|
|
695
|
+
detail.aggregate = 'list'
|
|
696
|
+
detail.expand = 'down'
|
|
697
|
+
detail.rowParent = { row: 1, col: 0 }
|
|
698
|
+
sheet.setCellMeta({ row: 1, col: 1 }, REPORT_META_NAMESPACE, detail)
|
|
699
|
+
|
|
700
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
701
|
+
expect(hasMerge(filled, { row: 1, col: 0 }, { row: 4, col: 0 })).toBe(false)
|
|
702
|
+
expect(cellValue(filled, 1, 0)).toBe('甲公司')
|
|
703
|
+
expect(cellValue(filled, 2, 0)).toBe('甲公司')
|
|
704
|
+
})
|
|
705
|
+
|
|
706
|
+
it('横向展开列继承列方向父格的模板列宽', () => {
|
|
707
|
+
const template = buildMatrixTemplate()
|
|
708
|
+
const templateWidths: Array<[number, number]> = [
|
|
709
|
+
[0, 80],
|
|
710
|
+
[1, 120]
|
|
711
|
+
]
|
|
712
|
+
const filledWidths = resolveFilledColWidths(
|
|
713
|
+
template,
|
|
714
|
+
{ 'sales-matrix': SALES_MATRIX_ROWS },
|
|
715
|
+
templateWidths
|
|
716
|
+
)
|
|
717
|
+
expect(filledWidths).toEqual(
|
|
718
|
+
expect.arrayContaining([
|
|
719
|
+
[0, 80],
|
|
720
|
+
[1, 120],
|
|
721
|
+
[2, 120],
|
|
722
|
+
[3, 120],
|
|
723
|
+
[4, 120],
|
|
724
|
+
[5, 120]
|
|
725
|
+
])
|
|
726
|
+
)
|
|
727
|
+
})
|
|
728
|
+
|
|
729
|
+
it('跨列行小计按组求和,不是全表合计', () => {
|
|
730
|
+
const sheet = new Sheet()
|
|
731
|
+
sheet.setCells([{ addr: { row: 0, col: 0 }, data: { v: '客户' } }])
|
|
732
|
+
const groupParent = { row: 1, col: 0 }
|
|
733
|
+
|
|
734
|
+
const customerGroup = createReportBinding(ORDERS_DATASET, 'customer')
|
|
735
|
+
customerGroup.preset = 'groupHeader'
|
|
736
|
+
customerGroup.aggregate = 'group'
|
|
737
|
+
customerGroup.expand = 'down'
|
|
738
|
+
sheet.setCellMeta(groupParent, REPORT_META_NAMESPACE, customerGroup)
|
|
739
|
+
|
|
740
|
+
const orderNo = createReportBinding(ORDERS_DATASET, 'orderNo')
|
|
741
|
+
orderNo.rowParent = groupParent
|
|
742
|
+
sheet.setCellMeta({ row: 1, col: 1 }, REPORT_META_NAMESPACE, orderNo)
|
|
743
|
+
|
|
744
|
+
const amount = createReportBinding(ORDERS_DATASET, 'amount')
|
|
745
|
+
amount.rowParent = groupParent
|
|
746
|
+
sheet.setCellMeta({ row: 1, col: 2 }, REPORT_META_NAMESPACE, amount)
|
|
747
|
+
|
|
748
|
+
const subtotal = createReportBinding(ORDERS_DATASET, 'amount')
|
|
749
|
+
subtotal.preset = 'subtotal'
|
|
750
|
+
subtotal.aggregate = 'sum'
|
|
751
|
+
subtotal.expand = 'none'
|
|
752
|
+
subtotal.rowParent = groupParent
|
|
753
|
+
sheet.setCellMeta({ row: 2, col: 2 }, REPORT_META_NAMESPACE, subtotal)
|
|
754
|
+
|
|
755
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
756
|
+
expect(cellValue(filled, 5, 2)).toBe(630)
|
|
757
|
+
expect(cellValue(filled, 10, 2)).toBe(1050)
|
|
758
|
+
expect(cellValue(filled, 5, 2)).not.toBe(4180)
|
|
759
|
+
})
|
|
760
|
+
|
|
761
|
+
it('跨列行小计误挂明细时仍按分组祖先过滤', () => {
|
|
762
|
+
const sheet = new Sheet()
|
|
763
|
+
sheet.setCells([{ addr: { row: 0, col: 0 }, data: { v: '客户' } }])
|
|
764
|
+
const groupParent = { row: 1, col: 0 }
|
|
765
|
+
const listAddr = { row: 1, col: 2 }
|
|
766
|
+
|
|
767
|
+
const customerGroup = createReportBinding(ORDERS_DATASET, 'customer')
|
|
768
|
+
customerGroup.preset = 'groupHeader'
|
|
769
|
+
customerGroup.aggregate = 'group'
|
|
770
|
+
customerGroup.expand = 'down'
|
|
771
|
+
sheet.setCellMeta(groupParent, REPORT_META_NAMESPACE, customerGroup)
|
|
772
|
+
|
|
773
|
+
const amount = createReportBinding(ORDERS_DATASET, 'amount')
|
|
774
|
+
amount.rowParent = groupParent
|
|
775
|
+
sheet.setCellMeta(listAddr, REPORT_META_NAMESPACE, amount)
|
|
776
|
+
|
|
777
|
+
const subtotal = createReportBinding(ORDERS_DATASET, 'amount')
|
|
778
|
+
subtotal.preset = 'subtotal'
|
|
779
|
+
subtotal.aggregate = 'sum'
|
|
780
|
+
subtotal.expand = 'none'
|
|
781
|
+
subtotal.rowParent = listAddr
|
|
782
|
+
sheet.setCellMeta({ row: 2, col: 2 }, REPORT_META_NAMESPACE, subtotal)
|
|
783
|
+
|
|
784
|
+
const filled = renderReport(sheet.snapshot(), MOCK_DATA_RECORDS)
|
|
785
|
+
expect(cellValue(filled, 5, 2)).toBe(630)
|
|
786
|
+
expect(cellValue(filled, 10, 2)).toBe(1050)
|
|
787
|
+
})
|
|
788
|
+
|
|
789
|
+
it('交叉列小计仅 colParent 时按列分组求和,不是全表合计', () => {
|
|
790
|
+
const sheet = new Sheet()
|
|
791
|
+
const colGroupAddr = { row: 0, col: 1 }
|
|
792
|
+
const rowGroupAddr = { row: 1, col: 0 }
|
|
793
|
+
|
|
794
|
+
const categoryGroup = createReportBinding(SALES_MATRIX_DATASET, 'category')
|
|
795
|
+
categoryGroup.preset = 'groupHeader'
|
|
796
|
+
categoryGroup.aggregate = 'group'
|
|
797
|
+
categoryGroup.expand = 'right'
|
|
798
|
+
sheet.setCellMeta(colGroupAddr, REPORT_META_NAMESPACE, categoryGroup)
|
|
799
|
+
|
|
800
|
+
const regionGroup = createReportBinding(SALES_MATRIX_DATASET, 'region')
|
|
801
|
+
regionGroup.preset = 'groupHeader'
|
|
802
|
+
regionGroup.aggregate = 'group'
|
|
803
|
+
regionGroup.expand = 'down'
|
|
804
|
+
sheet.setCellMeta(rowGroupAddr, REPORT_META_NAMESPACE, regionGroup)
|
|
805
|
+
|
|
806
|
+
const cross = createReportBinding(SALES_MATRIX_DATASET, 'amount')
|
|
807
|
+
cross.preset = 'cross'
|
|
808
|
+
cross.aggregate = 'sum'
|
|
809
|
+
cross.expand = 'none'
|
|
810
|
+
cross.rowParent = rowGroupAddr
|
|
811
|
+
cross.colParent = colGroupAddr
|
|
812
|
+
sheet.setCellMeta({ row: 1, col: 1 }, REPORT_META_NAMESPACE, cross)
|
|
813
|
+
|
|
814
|
+
const colSubtotal = createReportBinding(SALES_MATRIX_DATASET, 'amount')
|
|
815
|
+
colSubtotal.preset = 'subtotal'
|
|
816
|
+
colSubtotal.aggregate = 'sum'
|
|
817
|
+
colSubtotal.expand = 'none'
|
|
818
|
+
colSubtotal.colParent = colGroupAddr
|
|
819
|
+
sheet.setCellMeta({ row: 2, col: 1 }, REPORT_META_NAMESPACE, colSubtotal)
|
|
820
|
+
|
|
821
|
+
const filled = renderReport(sheet.snapshot(), { 'sales-matrix': SALES_MATRIX_ROWS })
|
|
822
|
+
const officeTotal = SALES_MATRIX_ROWS.filter((row) => row.category === '办公设备').reduce(
|
|
823
|
+
(sum, row) => sum + (row.amount as number),
|
|
824
|
+
0
|
|
825
|
+
)
|
|
826
|
+
const grandTotal = SALES_MATRIX_ROWS.reduce((sum, row) => sum + (row.amount as number), 0)
|
|
827
|
+
expect(cellValue(filled, 5, 1)).toBe(officeTotal)
|
|
828
|
+
expect(cellValue(filled, 5, 1)).not.toBe(grandTotal)
|
|
829
|
+
})
|
|
830
|
+
})
|