@veltra/sheet 2.3.4 → 2.5.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/index.d.ts +2 -17
- package/dist/index.js +2 -13
- package/dist/types/index.d.ts +1 -3
- package/package.json +5 -6
- package/src/index.ts +1 -27
- package/src/types/index.ts +0 -2
- package/dist/components/report/binding-badge.js +0 -112
- package/dist/components/report/designer/cell-coords.js +0 -46
- package/dist/components/report/designer/col-widths.js +0 -29
- package/dist/components/report/designer/conditional-rules/helpers.js +0 -139
- package/dist/components/report/designer/drop-highlight-overlay.js +0 -76
- package/dist/components/report/designer/float-panel.js +0 -422
- package/dist/components/report/designer/role.js +0 -17
- package/dist/components/report/designer/rule-preview.js +0 -33
- package/dist/components/report/designer/rule-row.js +0 -253
- package/dist/components/report/designer/rules-dialog.js +0 -118
- package/dist/components/report/designer/topology-overlay.js +0 -122
- package/dist/components/report/designer/topology.js +0 -64
- package/dist/components/report/designer/use-grid-overlay.js +0 -75
- package/dist/components/report/designer-hub.js +0 -177
- package/dist/components/report/field-panel-helpers.js +0 -33
- package/dist/components/report/field-panel.js +0 -132
- package/dist/components/report/filter-bar.js +0 -74
- package/dist/components/report/hub-connection-form.js +0 -145
- package/dist/components/report/hub-dataset-editor.js +0 -409
- package/dist/components/report/preview-grid-size.js +0 -32
- package/dist/components/report/report-designer.js +0 -393
- package/dist/components/report/report-viewer.js +0 -124
- package/dist/components/report/style.d.ts +0 -17
- package/dist/components/report/style.js +0 -18
- package/dist/components/report/style2.css +0 -874
- package/dist/components/report/use-report-designer.js +0 -386
- package/dist/components/report/use-report-viewer.js +0 -55
- package/dist/report/binding.d.ts +0 -83
- package/dist/report/binding.js +0 -334
- package/dist/report/connector.d.ts +0 -66
- package/dist/report/connector.js +0 -159
- package/dist/report/export-xlsx.d.ts +0 -13
- package/dist/report/export-xlsx.js +0 -13
- package/dist/report/filter-bar.d.ts +0 -10
- package/dist/report/filter-bar.js +0 -31
- package/dist/report/index.d.ts +0 -12
- package/dist/report/params.d.ts +0 -13
- package/dist/report/params.js +0 -61
- package/dist/report/render/aggregate.js +0 -169
- package/dist/report/render/builder.d.ts +0 -12
- package/dist/report/render/builder.js +0 -139
- package/dist/report/render/coordinate.d.ts +0 -25
- package/dist/report/render/coordinate.js +0 -733
- package/dist/report/render/index.d.ts +0 -14
- package/dist/report/render/index.js +0 -21
- package/dist/report/render/style-resolver.js +0 -50
- package/dist/report/render/template-index.d.ts +0 -24
- package/dist/report/render/template-index.js +0 -137
- package/dist/report/rules/evaluate.d.ts +0 -25
- package/dist/report/rules/evaluate.js +0 -82
- package/dist/report/rules/index.d.ts +0 -2
- package/dist/report/template.d.ts +0 -63
- package/dist/report/template.js +0 -83
- package/dist/report/types.d.ts +0 -85
- package/dist/types/report-designer.d.ts +0 -38
- package/dist/types/report-viewer.d.ts +0 -38
- package/src/components/report/__test__/binding-badge.test.ts +0 -92
- package/src/components/report/__test__/conditional-rules-helpers.test.ts +0 -88
- package/src/components/report/__test__/field-panel-helpers.test.ts +0 -65
- package/src/components/report/__test__/float-panel-position.test.ts +0 -45
- package/src/components/report/__test__/preview-grid-size.test.ts +0 -63
- package/src/components/report/__test__/report-designer.test.ts +0 -464
- package/src/components/report/__test__/report-viewer.test.ts +0 -357
- package/src/components/report/__test__/topology.test.ts +0 -143
- package/src/components/report/__test__/use-report-designer.test.ts +0 -697
- package/src/components/report/binding-badge.ts +0 -117
- package/src/components/report/designer/cell-coords.ts +0 -95
- package/src/components/report/designer/col-widths.ts +0 -56
- package/src/components/report/designer/conditional-rules/helpers.ts +0 -189
- package/src/components/report/designer/drop-highlight-overlay.vue +0 -75
- package/src/components/report/designer/float-panel.vue +0 -432
- package/src/components/report/designer/role.ts +0 -32
- package/src/components/report/designer/rule-preview.vue +0 -40
- package/src/components/report/designer/rule-row.vue +0 -252
- package/src/components/report/designer/rules-dialog.vue +0 -110
- package/src/components/report/designer/topology-overlay.vue +0 -128
- package/src/components/report/designer/topology.ts +0 -124
- package/src/components/report/designer/use-grid-overlay.ts +0 -114
- package/src/components/report/designer-hub.vue +0 -198
- package/src/components/report/field-panel-helpers.ts +0 -44
- package/src/components/report/field-panel.vue +0 -136
- package/src/components/report/filter-bar.vue +0 -77
- package/src/components/report/hub-connection-form.vue +0 -124
- package/src/components/report/hub-dataset-editor.vue +0 -387
- package/src/components/report/index.ts +0 -2
- package/src/components/report/preview-grid-size.ts +0 -33
- package/src/components/report/report-designer.vue +0 -421
- package/src/components/report/report-viewer.vue +0 -136
- package/src/components/report/style-designer.scss +0 -587
- package/src/components/report/style-hub.scss +0 -292
- package/src/components/report/style-viewer.scss +0 -104
- package/src/components/report/style.scss +0 -3
- package/src/components/report/style.ts +0 -20
- package/src/components/report/use-report-designer.ts +0 -602
- package/src/components/report/use-report-viewer.ts +0 -88
- package/src/report/__test__/binding.test.ts +0 -320
- package/src/report/__test__/connector.test.ts +0 -239
- package/src/report/__test__/export-xlsx.test.ts +0 -96
- package/src/report/__test__/filter-bar.test.ts +0 -58
- package/src/report/__test__/params.test.ts +0 -156
- package/src/report/__test__/render.test.ts +0 -856
- package/src/report/__test__/rules.test.ts +0 -131
- package/src/report/__test__/template.test.ts +0 -366
- package/src/report/binding.ts +0 -474
- package/src/report/connector.ts +0 -206
- package/src/report/export-xlsx.ts +0 -15
- package/src/report/filter-bar.ts +0 -36
- package/src/report/index.ts +0 -13
- package/src/report/params.ts +0 -96
- package/src/report/render/__test__/aggregate.test.ts +0 -16
- package/src/report/render/__test__/coordinate.test.ts +0 -405
- package/src/report/render/aggregate.ts +0 -261
- package/src/report/render/builder.ts +0 -211
- package/src/report/render/coordinate.ts +0 -1239
- package/src/report/render/index.ts +0 -30
- package/src/report/render/style-resolver.ts +0 -68
- package/src/report/render/template-index.ts +0 -200
- package/src/report/rules/evaluate.ts +0 -113
- package/src/report/rules/index.ts +0 -7
- package/src/report/template.ts +0 -145
- package/src/report/types.ts +0 -96
- package/src/types/report-designer.ts +0 -38
- package/src/types/report-viewer.ts +0 -37
package/src/report/binding.ts
DELETED
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
import type { CellAddress } from '@veltra/sheet-core'
|
|
2
|
-
import { formatAddress, parseAddress } from '@veltra/sheet-core'
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
DatasetCatalogItem,
|
|
6
|
-
ReportAggregate,
|
|
7
|
-
ReportBinding,
|
|
8
|
-
ReportExpand,
|
|
9
|
-
ReportPreset
|
|
10
|
-
} from './types'
|
|
11
|
-
|
|
12
|
-
/** 字段 label 解析用的 catalog(由宿主注入) */
|
|
13
|
-
let bindingCatalog: DatasetCatalogItem[] = []
|
|
14
|
-
|
|
15
|
-
export function setBindingCatalog(catalog: DatasetCatalogItem[]): void {
|
|
16
|
-
bindingCatalog = catalog
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const REPORT_META_NAMESPACE = 'report'
|
|
20
|
-
|
|
21
|
-
const AGGREGATE_PLACEHOLDER_TAG: Record<ReportAggregate, string> = {
|
|
22
|
-
list: '明细',
|
|
23
|
-
group: '分组',
|
|
24
|
-
sum: '求和',
|
|
25
|
-
avg: '平均',
|
|
26
|
-
count: '计数',
|
|
27
|
-
max: '最大',
|
|
28
|
-
min: '最小'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** 预设 → 绑定字段补丁(父格除 grandTotal 外均保留推断值) */
|
|
32
|
-
export function presetBindingPatch(
|
|
33
|
-
preset: ReportPreset,
|
|
34
|
-
options?: { transpose?: boolean }
|
|
35
|
-
): Partial<ReportBinding> {
|
|
36
|
-
const expand: ReportExpand = options?.transpose ? 'right' : 'down'
|
|
37
|
-
switch (preset) {
|
|
38
|
-
case 'groupHeader':
|
|
39
|
-
return { preset, expand, aggregate: 'group' }
|
|
40
|
-
case 'detail':
|
|
41
|
-
return { preset, expand, aggregate: 'list' }
|
|
42
|
-
case 'subtotal':
|
|
43
|
-
return { preset, expand: 'none', aggregate: 'sum' }
|
|
44
|
-
case 'grandTotal':
|
|
45
|
-
return {
|
|
46
|
-
preset,
|
|
47
|
-
expand: 'none',
|
|
48
|
-
aggregate: 'sum',
|
|
49
|
-
rowParent: undefined,
|
|
50
|
-
colParent: undefined
|
|
51
|
-
}
|
|
52
|
-
case 'cross':
|
|
53
|
-
return { preset, expand: 'none', aggregate: 'sum' }
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** 将预设写入绑定(grandTotal 清空双父格;其余保留既有父格) */
|
|
58
|
-
export function applyReportPreset(
|
|
59
|
-
binding: ReportBinding,
|
|
60
|
-
preset: ReportPreset,
|
|
61
|
-
options?: { transpose?: boolean }
|
|
62
|
-
): ReportBinding {
|
|
63
|
-
const patch = presetBindingPatch(preset, options)
|
|
64
|
-
const next: ReportBinding = { ...binding, ...patch }
|
|
65
|
-
if (preset === 'grandTotal') {
|
|
66
|
-
delete next.rowParent
|
|
67
|
-
delete next.colParent
|
|
68
|
-
}
|
|
69
|
-
return next
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function isVerticalExpandBinding(binding: ReportBinding): boolean {
|
|
73
|
-
return (
|
|
74
|
-
binding.expand === 'down' && (binding.aggregate === 'group' || binding.aggregate === 'list')
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function isHorizontalExpandBinding(binding: ReportBinding): boolean {
|
|
79
|
-
return (
|
|
80
|
-
binding.expand === 'right' && (binding.aggregate === 'group' || binding.aggregate === 'list')
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function isRowGroupBinding(binding: ReportBinding): boolean {
|
|
85
|
-
return binding.expand === 'down' && binding.aggregate === 'group'
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function isColGroupBinding(binding: ReportBinding): boolean {
|
|
89
|
-
return binding.expand === 'right' && binding.aggregate === 'group'
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function isReductionAggregate(aggregate: ReportAggregate): boolean {
|
|
93
|
-
return (
|
|
94
|
-
aggregate === 'sum' ||
|
|
95
|
-
aggregate === 'avg' ||
|
|
96
|
-
aggregate === 'count' ||
|
|
97
|
-
aggregate === 'max' ||
|
|
98
|
-
aggregate === 'min'
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** 小计 / 汇总 / 交叉格的父格候选只列分组头 */
|
|
103
|
-
export function prefersGroupParent(binding: ReportBinding): boolean {
|
|
104
|
-
if (
|
|
105
|
-
binding.preset === 'subtotal' ||
|
|
106
|
-
binding.preset === 'grandTotal' ||
|
|
107
|
-
binding.preset === 'cross'
|
|
108
|
-
) {
|
|
109
|
-
return true
|
|
110
|
-
}
|
|
111
|
-
return binding.expand === 'none' && isReductionAggregate(binding.aggregate)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** 当前 expand / aggregate 是否仍属于已写入的预设族(同族内改聚合不掉到「自定义」) */
|
|
115
|
-
export function presetStillApplies(binding: ReportBinding): boolean {
|
|
116
|
-
const preset = binding.preset
|
|
117
|
-
if (!preset) return false
|
|
118
|
-
if (preset === 'groupHeader') {
|
|
119
|
-
return (
|
|
120
|
-
binding.aggregate === 'group' && (binding.expand === 'down' || binding.expand === 'right')
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
if (preset === 'detail') {
|
|
124
|
-
return binding.aggregate === 'list' && (binding.expand === 'down' || binding.expand === 'right')
|
|
125
|
-
}
|
|
126
|
-
return binding.expand === 'none' && isReductionAggregate(binding.aggregate)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const DEFAULT_SCAN_COLS = 64
|
|
130
|
-
const DEFAULT_SCAN_ROWS = 64
|
|
131
|
-
|
|
132
|
-
type GetBindingAt = (addr: CellAddress) => ReportBinding | undefined
|
|
133
|
-
|
|
134
|
-
export interface InferParentOptions {
|
|
135
|
-
/** 小计落格:必须优先分组头,禁止把同列/同行明细当成父格 */
|
|
136
|
-
preferGroup?: boolean
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** 指定模板行是否含纵向扩展绑定(展开带行) */
|
|
140
|
-
export function isExpansionBandRow(
|
|
141
|
-
row: number,
|
|
142
|
-
getBindingAt: GetBindingAt,
|
|
143
|
-
scanCols = DEFAULT_SCAN_COLS
|
|
144
|
-
): boolean {
|
|
145
|
-
for (let col = 0; col < scanCols; col++) {
|
|
146
|
-
const binding = getBindingAt({ row, col })
|
|
147
|
-
if (binding && isVerticalExpandBinding(binding)) return true
|
|
148
|
-
}
|
|
149
|
-
return false
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** 指定模板列是否含横向扩展绑定(展开带列) */
|
|
153
|
-
export function isExpansionBandCol(
|
|
154
|
-
col: number,
|
|
155
|
-
getBindingAt: GetBindingAt,
|
|
156
|
-
scanRows = DEFAULT_SCAN_ROWS
|
|
157
|
-
): boolean {
|
|
158
|
-
for (let row = 0; row < scanRows; row++) {
|
|
159
|
-
const binding = getBindingAt({ row, col })
|
|
160
|
-
if (binding && isHorizontalExpandBinding(binding)) return true
|
|
161
|
-
}
|
|
162
|
-
return false
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** 落格时推断预设:默认明细;数值字段且位于展开带正下方或正右相邻 → 小计 */
|
|
166
|
-
export function inferDropPreset(
|
|
167
|
-
addr: CellAddress,
|
|
168
|
-
fieldType: DatasetCatalogItem['fields'][number]['type'],
|
|
169
|
-
getBindingAt: GetBindingAt
|
|
170
|
-
): ReportPreset {
|
|
171
|
-
if (fieldType !== 'number') return 'detail'
|
|
172
|
-
if (addr.row > 0 && isExpansionBandRow(addr.row - 1, getBindingAt)) return 'subtotal'
|
|
173
|
-
if (addr.col > 0 && isExpansionBandCol(addr.col - 1, getBindingAt)) return 'subtotal'
|
|
174
|
-
return 'detail'
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export interface ListParentCandidateOptions {
|
|
178
|
-
preferGroup?: boolean
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** 同数据集纵向扩展绑定格(行方向父格下拉候选) */
|
|
182
|
-
export function listRowParentCandidates(
|
|
183
|
-
binding: ReportBinding,
|
|
184
|
-
entries: ReadonlyArray<{ addr: CellAddress; binding: ReportBinding }>,
|
|
185
|
-
options?: ListParentCandidateOptions
|
|
186
|
-
): CellAddress[] {
|
|
187
|
-
const preferGroup = options?.preferGroup === true
|
|
188
|
-
const candidates: CellAddress[] = []
|
|
189
|
-
for (const entry of entries) {
|
|
190
|
-
if (entry.binding.dataset !== binding.dataset) continue
|
|
191
|
-
if (preferGroup) {
|
|
192
|
-
if (!isRowGroupBinding(entry.binding)) continue
|
|
193
|
-
} else if (!isVerticalExpandBinding(entry.binding)) {
|
|
194
|
-
continue
|
|
195
|
-
}
|
|
196
|
-
candidates.push(entry.addr)
|
|
197
|
-
}
|
|
198
|
-
return candidates
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/** 同数据集横向扩展绑定格(列方向父格下拉候选) */
|
|
202
|
-
export function listColParentCandidates(
|
|
203
|
-
binding: ReportBinding,
|
|
204
|
-
entries: ReadonlyArray<{ addr: CellAddress; binding: ReportBinding }>,
|
|
205
|
-
options?: ListParentCandidateOptions
|
|
206
|
-
): CellAddress[] {
|
|
207
|
-
const preferGroup = options?.preferGroup === true
|
|
208
|
-
const candidates: CellAddress[] = []
|
|
209
|
-
for (const entry of entries) {
|
|
210
|
-
if (entry.binding.dataset !== binding.dataset) continue
|
|
211
|
-
if (preferGroup) {
|
|
212
|
-
if (!isColGroupBinding(entry.binding)) continue
|
|
213
|
-
} else if (!isHorizontalExpandBinding(entry.binding)) {
|
|
214
|
-
continue
|
|
215
|
-
}
|
|
216
|
-
candidates.push(entry.addr)
|
|
217
|
-
}
|
|
218
|
-
return candidates
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
interface ScanHit {
|
|
222
|
-
addr: CellAddress
|
|
223
|
-
group: boolean
|
|
224
|
-
distance: number
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function betterHit(current: ScanHit | null, next: ScanHit): boolean {
|
|
228
|
-
if (!current) return true
|
|
229
|
-
if (next.distance !== current.distance) return next.distance < current.distance
|
|
230
|
-
return next.addr.col + next.addr.row < current.addr.col + current.addr.row
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function pickExpandHit(hits: ScanHit[], preferGroup: boolean): CellAddress | null {
|
|
234
|
-
let group: ScanHit | null = null
|
|
235
|
-
let expand: ScanHit | null = null
|
|
236
|
-
for (const hit of hits) {
|
|
237
|
-
if (hit.group && betterHit(group, hit)) group = hit
|
|
238
|
-
if (betterHit(expand, hit)) expand = hit
|
|
239
|
-
}
|
|
240
|
-
if (preferGroup) return group?.addr ?? null
|
|
241
|
-
return group?.addr ?? expand?.addr ?? null
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function scanVerticalOnRow(
|
|
245
|
-
row: number,
|
|
246
|
-
originCol: number,
|
|
247
|
-
colStart: number,
|
|
248
|
-
colEnd: number,
|
|
249
|
-
getBindingAt: GetBindingAt
|
|
250
|
-
): ScanHit[] {
|
|
251
|
-
const hits: ScanHit[] = []
|
|
252
|
-
for (let col = colStart; col < colEnd; col++) {
|
|
253
|
-
const binding = getBindingAt({ row, col })
|
|
254
|
-
if (!binding || !isVerticalExpandBinding(binding)) continue
|
|
255
|
-
hits.push({
|
|
256
|
-
addr: { row, col },
|
|
257
|
-
group: isRowGroupBinding(binding),
|
|
258
|
-
distance: Math.abs(col - originCol)
|
|
259
|
-
})
|
|
260
|
-
}
|
|
261
|
-
return hits
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function scanHorizontalOnCol(
|
|
265
|
-
col: number,
|
|
266
|
-
originRow: number,
|
|
267
|
-
rowStart: number,
|
|
268
|
-
rowEnd: number,
|
|
269
|
-
getBindingAt: GetBindingAt
|
|
270
|
-
): ScanHit[] {
|
|
271
|
-
const hits: ScanHit[] = []
|
|
272
|
-
for (let row = rowStart; row < rowEnd; row++) {
|
|
273
|
-
const binding = getBindingAt({ row, col })
|
|
274
|
-
if (!binding || !isHorizontalExpandBinding(binding)) continue
|
|
275
|
-
hits.push({
|
|
276
|
-
addr: { row, col },
|
|
277
|
-
group: isColGroupBinding(binding),
|
|
278
|
-
distance: Math.abs(row - originRow)
|
|
279
|
-
})
|
|
280
|
-
}
|
|
281
|
-
return hits
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* 行方向父格推断:
|
|
286
|
-
* 1. 同行向左:先找分组头,否则最近纵向扩展格
|
|
287
|
-
* 2. 上方各行整行扫描:每行先找分组头,再退回任意纵向扩展格
|
|
288
|
-
* 小计(preferGroup)禁止把明细当成父格
|
|
289
|
-
*/
|
|
290
|
-
export function inferRowParentCandidate(
|
|
291
|
-
addr: CellAddress,
|
|
292
|
-
getBindingAt: GetBindingAt,
|
|
293
|
-
options?: InferParentOptions
|
|
294
|
-
): CellAddress | null {
|
|
295
|
-
const preferGroup = options?.preferGroup === true
|
|
296
|
-
|
|
297
|
-
const sameRow = pickExpandHit(
|
|
298
|
-
scanVerticalOnRow(addr.row, addr.col, 0, addr.col, getBindingAt),
|
|
299
|
-
preferGroup
|
|
300
|
-
)
|
|
301
|
-
if (sameRow) return sameRow
|
|
302
|
-
|
|
303
|
-
for (let row = addr.row - 1; row >= 0; row--) {
|
|
304
|
-
const found = pickExpandHit(
|
|
305
|
-
scanVerticalOnRow(row, addr.col, 0, DEFAULT_SCAN_COLS, getBindingAt),
|
|
306
|
-
preferGroup
|
|
307
|
-
)
|
|
308
|
-
if (found) return found
|
|
309
|
-
}
|
|
310
|
-
return null
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* 列方向父格推断(与行方向对称):
|
|
315
|
-
* 1. 同列向上:先找列分组头,否则最近横向扩展格
|
|
316
|
-
* 2. 左侧各列整列扫描:每列先找列分组头
|
|
317
|
-
* 列小计(preferGroup)禁止把交叉格/明细当成列父格
|
|
318
|
-
*/
|
|
319
|
-
export function inferColParentCandidate(
|
|
320
|
-
addr: CellAddress,
|
|
321
|
-
getBindingAt: GetBindingAt,
|
|
322
|
-
options?: InferParentOptions
|
|
323
|
-
): CellAddress | null {
|
|
324
|
-
const preferGroup = options?.preferGroup === true
|
|
325
|
-
|
|
326
|
-
const sameCol = pickExpandHit(
|
|
327
|
-
scanHorizontalOnCol(addr.col, addr.row, 0, addr.row, getBindingAt),
|
|
328
|
-
preferGroup
|
|
329
|
-
)
|
|
330
|
-
if (sameCol) return sameCol
|
|
331
|
-
|
|
332
|
-
for (let col = addr.col - 1; col >= 0; col--) {
|
|
333
|
-
const found = pickExpandHit(
|
|
334
|
-
scanHorizontalOnCol(col, addr.row, 0, DEFAULT_SCAN_ROWS, getBindingAt),
|
|
335
|
-
preferGroup
|
|
336
|
-
)
|
|
337
|
-
if (found) return found
|
|
338
|
-
}
|
|
339
|
-
return null
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function suggestsColumnSubtotal(above: ReportBinding | undefined): boolean {
|
|
343
|
-
if (!above) return false
|
|
344
|
-
return isHorizontalExpandBinding(above) || !!above.colParent || above.preset === 'cross'
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function suggestsRowSubtotal(left: ReportBinding | undefined): boolean {
|
|
348
|
-
if (!left) return false
|
|
349
|
-
return isVerticalExpandBinding(left) || !!left.rowParent || left.preset === 'cross'
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* 按预设写入落格父格:明细/分组/交叉双方向推断;小计按「下方行小计 / 右侧列小计」只挂对应轴。
|
|
354
|
-
*/
|
|
355
|
-
export function inferParentsForPreset(
|
|
356
|
-
addr: CellAddress,
|
|
357
|
-
preset: ReportPreset,
|
|
358
|
-
getBindingAt: GetBindingAt
|
|
359
|
-
): Pick<ReportBinding, 'rowParent' | 'colParent'> {
|
|
360
|
-
if (preset === 'grandTotal') return {}
|
|
361
|
-
|
|
362
|
-
const preferGroup = preset === 'subtotal' || preset === 'cross'
|
|
363
|
-
const rowParent = inferRowParentCandidate(addr, getBindingAt, { preferGroup }) ?? undefined
|
|
364
|
-
const colParent = inferColParentCandidate(addr, getBindingAt, { preferGroup }) ?? undefined
|
|
365
|
-
|
|
366
|
-
if (preset !== 'subtotal') {
|
|
367
|
-
return { ...(rowParent ? { rowParent } : {}), ...(colParent ? { colParent } : {}) }
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
const above = addr.row > 0 ? getBindingAt({ row: addr.row - 1, col: addr.col }) : undefined
|
|
371
|
-
const left = addr.col > 0 ? getBindingAt({ row: addr.row, col: addr.col - 1 }) : undefined
|
|
372
|
-
const belowBand = addr.row > 0 && isExpansionBandRow(addr.row - 1, getBindingAt)
|
|
373
|
-
const rightOfBand = addr.col > 0 && isExpansionBandCol(addr.col - 1, getBindingAt)
|
|
374
|
-
|
|
375
|
-
const columnSubtotal =
|
|
376
|
-
suggestsColumnSubtotal(above) || (rightOfBand && !suggestsRowSubtotal(left))
|
|
377
|
-
const rowSubtotal = suggestsRowSubtotal(left) || (belowBand && !columnSubtotal)
|
|
378
|
-
|
|
379
|
-
const result: Pick<ReportBinding, 'rowParent' | 'colParent'> = {}
|
|
380
|
-
if (rowSubtotal && rowParent) result.rowParent = rowParent
|
|
381
|
-
if (columnSubtotal && colParent) result.colParent = colParent
|
|
382
|
-
if (!rowSubtotal && !columnSubtotal) {
|
|
383
|
-
if (belowBand && rowParent) result.rowParent = rowParent
|
|
384
|
-
else if (rightOfBand && colParent) result.colParent = colParent
|
|
385
|
-
else {
|
|
386
|
-
if (rowParent) result.rowParent = rowParent
|
|
387
|
-
if (colParent) result.colParent = colParent
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return result
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/** 从绑定字段推断预设;不匹配任何预设时返回 null(自定义) */
|
|
394
|
-
export function inferReportPreset(binding: ReportBinding): ReportPreset | null {
|
|
395
|
-
if (binding.preset) return binding.preset
|
|
396
|
-
|
|
397
|
-
if (binding.expand === 'none' && isReductionAggregate(binding.aggregate)) {
|
|
398
|
-
if (binding.rowParent && binding.colParent) return 'cross'
|
|
399
|
-
if (binding.rowParent || binding.colParent) return 'subtotal'
|
|
400
|
-
return 'grandTotal'
|
|
401
|
-
}
|
|
402
|
-
if (binding.aggregate === 'group' && (binding.expand === 'down' || binding.expand === 'right')) {
|
|
403
|
-
return 'groupHeader'
|
|
404
|
-
}
|
|
405
|
-
if (binding.aggregate === 'list' && (binding.expand === 'down' || binding.expand === 'right')) {
|
|
406
|
-
return 'detail'
|
|
407
|
-
}
|
|
408
|
-
return null
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/** 默认明细 + 纵向扩展 */
|
|
412
|
-
export function createReportBinding(dataset: DatasetCatalogItem, fieldName: string): ReportBinding {
|
|
413
|
-
return {
|
|
414
|
-
dataset: dataset.id,
|
|
415
|
-
field: fieldName,
|
|
416
|
-
aggregate: 'list',
|
|
417
|
-
expand: 'down',
|
|
418
|
-
preset: 'detail',
|
|
419
|
-
sort: 'none',
|
|
420
|
-
conditionalRules: []
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/** 设计地址 → A1 标签(支持多字母列) */
|
|
425
|
-
export function formatCellAddress(addr: CellAddress): string {
|
|
426
|
-
return formatAddress(addr)
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/** A1 标签 → 设计地址;非法输入返回 null */
|
|
430
|
-
export function parseCellAddress(label: string): CellAddress | null {
|
|
431
|
-
return parseAddress(label)
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/** 解析字段中文标签(找不到时回退字段名);可传入报表配置中的 label */
|
|
435
|
-
function resolveFieldLabel(
|
|
436
|
-
datasetId: string,
|
|
437
|
-
fieldName: string,
|
|
438
|
-
resolveLabel?: (datasetId: string, fieldName: string) => string
|
|
439
|
-
): string {
|
|
440
|
-
const override = resolveLabel?.(datasetId, fieldName)
|
|
441
|
-
if (override) return override
|
|
442
|
-
const dataset = bindingCatalog.find((d) => d.id === datasetId)
|
|
443
|
-
const field = dataset?.fields.find((f) => f.name === fieldName)
|
|
444
|
-
return field?.label ?? fieldName
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/** Binding Placeholder 分段文案(聚合标签 + 字段标签),供徽章分色渲染等场景使用 */
|
|
448
|
-
export function formatBindingPlaceholderParts(
|
|
449
|
-
binding: ReportBinding,
|
|
450
|
-
resolveLabel?: (datasetId: string, fieldName: string) => string
|
|
451
|
-
): { tag: string; label: string } {
|
|
452
|
-
return {
|
|
453
|
-
tag: AGGREGATE_PLACEHOLDER_TAG[binding.aggregate],
|
|
454
|
-
label: resolveFieldLabel(binding.dataset, binding.field, resolveLabel)
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/** Binding Placeholder 中文可读文案(如「分组 · 客户」) */
|
|
459
|
-
export function formatBindingPlaceholder(
|
|
460
|
-
binding: ReportBinding,
|
|
461
|
-
resolveLabel?: (datasetId: string, fieldName: string) => string
|
|
462
|
-
): string {
|
|
463
|
-
const { tag, label } = formatBindingPlaceholderParts(binding, resolveLabel)
|
|
464
|
-
return `${tag} · ${label}`
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/** 父格下拉候选文案(如「分组 · 客户 (A2)」) */
|
|
468
|
-
export function formatParentCandidateLabel(
|
|
469
|
-
addr: CellAddress,
|
|
470
|
-
binding: ReportBinding,
|
|
471
|
-
resolveLabel?: (datasetId: string, fieldName: string) => string
|
|
472
|
-
): string {
|
|
473
|
-
return `${formatBindingPlaceholder(binding, resolveLabel)} (${formatCellAddress(addr)})`
|
|
474
|
-
}
|
package/src/report/connector.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import type { DatasetField, ParamValues } from './types'
|
|
2
|
-
|
|
3
|
-
/** 数据连接类型(ADR-0003 决策 3:收敛为 MySQL / PostgreSQL) */
|
|
4
|
-
export type ConnectionType = 'mysql' | 'postgresql'
|
|
5
|
-
|
|
6
|
-
/** 各连接类型的默认端口 */
|
|
7
|
-
export const DEFAULT_CONNECTION_PORTS: Record<ConnectionType, number> = {
|
|
8
|
-
mysql: 3306,
|
|
9
|
-
postgresql: 5432
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 切换连接类型时解析端口:若当前端口仍是上一类型的默认值(或 0),则切到新类型默认端口;
|
|
14
|
-
* 用户已自定义的端口保持不变。
|
|
15
|
-
*/
|
|
16
|
-
export function resolvePortOnTypeChange(
|
|
17
|
-
prevType: ConnectionType,
|
|
18
|
-
nextType: ConnectionType,
|
|
19
|
-
currentPort: number
|
|
20
|
-
): number {
|
|
21
|
-
if (prevType === nextType) return currentPort
|
|
22
|
-
if (currentPort === DEFAULT_CONNECTION_PORTS[prevType] || currentPort === 0) {
|
|
23
|
-
return DEFAULT_CONNECTION_PORTS[nextType]
|
|
24
|
-
}
|
|
25
|
-
return currentPort
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 数据连接(纯序列化对象,仅驻留内存)。
|
|
30
|
-
* 凭据持久化与安全存储由下游负责(ADR-0003 决策 4)。
|
|
31
|
-
*/
|
|
32
|
-
export interface DataConnection {
|
|
33
|
-
id: string
|
|
34
|
-
label: string
|
|
35
|
-
type: ConnectionType
|
|
36
|
-
host: string
|
|
37
|
-
port: number
|
|
38
|
-
database: string
|
|
39
|
-
username: string
|
|
40
|
-
password: string
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** 业务错误(`200 + { ok: false, error }`)或客户端传输层错误 */
|
|
44
|
-
export interface ConnectorError {
|
|
45
|
-
code: string
|
|
46
|
-
message: string
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** 统一结果:成功携带 data;失败携带 error(连接器不抛异常,调用方只处理一条错误路径) */
|
|
50
|
-
export type Result<T> = { ok: true; data: T } | { ok: false; error: ConnectorError }
|
|
51
|
-
|
|
52
|
-
/** query 成功结果:字段 schema + 行记录(契约 `{ fields, rows }` 归一化后) */
|
|
53
|
-
export interface QueryResult {
|
|
54
|
-
fields: DatasetField[]
|
|
55
|
-
rows: Record<string, unknown>[]
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 数据连接器(词汇表:Data Connector):test / describe / query 三方法镜像 HTTP 契约三端点。
|
|
60
|
-
* 真实数据库访问由下游后端以任意语言实现(BYO)。
|
|
61
|
-
*/
|
|
62
|
-
export interface DataConnector {
|
|
63
|
-
test(connection: DataConnection): Promise<Result<void>>
|
|
64
|
-
describe(connection: DataConnection, sql: string): Promise<Result<DatasetField[]>>
|
|
65
|
-
query(connection: DataConnection, sql: string, values: ParamValues): Promise<Result<QueryResult>>
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface CreateHttpConnectorOptions {
|
|
69
|
-
/** 契约端点前缀,如 `https://api.example.com/report`;三端点 = `{endpoint}/test|describe|query`(无版本段) */
|
|
70
|
-
endpoint: string
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ---- HTTP 契约响应形状(ADR-0003 决策 3)----
|
|
74
|
-
// 传输层错误用 HTTP 状态码;业务错误一律 `200 + { ok: false, error }`。
|
|
75
|
-
|
|
76
|
-
/** 契约字段 schema:`{ name, label?, type? }`(label 缺省视为 name,type 缺省视为 string) */
|
|
77
|
-
interface ContractField {
|
|
78
|
-
name: string
|
|
79
|
-
label?: string
|
|
80
|
-
type?: DatasetField['type']
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
interface ContractErrorBody {
|
|
84
|
-
ok: false
|
|
85
|
-
error: ConnectorError
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
type TestResponseBody = { ok: true } | ContractErrorBody
|
|
89
|
-
|
|
90
|
-
type DescribeResponseBody = { ok: true; fields: ContractField[] } | ContractErrorBody
|
|
91
|
-
|
|
92
|
-
type QueryResponseBody =
|
|
93
|
-
| { ok: true; fields: ContractField[]; rows: Record<string, unknown>[] }
|
|
94
|
-
| ContractErrorBody
|
|
95
|
-
|
|
96
|
-
/** 客户端错误:网络不可达 / 非 2xx / 响应不可解析(业务错误由服务端 200 透传) */
|
|
97
|
-
function badResponse(message: string): Result<never> {
|
|
98
|
-
return { ok: false, error: { code: 'BAD_RESPONSE', message } }
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
102
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function toConnectorError(value: unknown): ConnectorError {
|
|
106
|
-
if (isRecord(value)) {
|
|
107
|
-
const { code, message } = value
|
|
108
|
-
if (typeof code === 'string' && typeof message === 'string') {
|
|
109
|
-
return { code, message }
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return { code: 'SERVER_ERROR', message: '服务端返回未知错误' }
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** 契约字段 → 内核 DatasetField(label 缺省回退 name,type 缺省 string) */
|
|
116
|
-
function normalizeField(field: ContractField): DatasetField {
|
|
117
|
-
return { name: field.name, label: field.label ?? field.name, type: field.type ?? 'string' }
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** 校验并归一化契约 fields;形状不合法返回 null */
|
|
121
|
-
function normalizeFields(fields: unknown): DatasetField[] | null {
|
|
122
|
-
if (!Array.isArray(fields)) return null
|
|
123
|
-
const normalized: DatasetField[] = []
|
|
124
|
-
for (const field of fields) {
|
|
125
|
-
if (!isRecord(field) || typeof field.name !== 'string') return null
|
|
126
|
-
normalized.push(normalizeField(field as unknown as ContractField))
|
|
127
|
-
}
|
|
128
|
-
return normalized
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 创建 HTTP 数据连接器:三方法对应 `POST {endpoint}/test|describe|query`。
|
|
133
|
-
* - 请求体 JSON 序列化,`Content-Type: application/json`;
|
|
134
|
-
* - 网络异常与非 2xx(传输层错误)折叠为 `{ ok: false, error }`,不抛异常;
|
|
135
|
-
* - 业务错误(连接失败 / SQL 报错)由服务端以 `200 + { ok: false, error: { code, message } }` 返回并原样透传;
|
|
136
|
-
* - `describe` / `query` 的 fields 归一化为内核 `DatasetField`(label 回退 name,type 缺省 string)。
|
|
137
|
-
*/
|
|
138
|
-
export function createHttpConnector({ endpoint }: CreateHttpConnectorOptions): DataConnector {
|
|
139
|
-
async function postJson<TBody>(path: string, body: unknown): Promise<Result<TBody>> {
|
|
140
|
-
let response: Response
|
|
141
|
-
try {
|
|
142
|
-
response = await fetch(`${endpoint}${path}`, {
|
|
143
|
-
method: 'POST',
|
|
144
|
-
headers: { 'Content-Type': 'application/json' },
|
|
145
|
-
body: JSON.stringify(body)
|
|
146
|
-
})
|
|
147
|
-
} catch (error) {
|
|
148
|
-
return {
|
|
149
|
-
ok: false,
|
|
150
|
-
error: {
|
|
151
|
-
code: 'NETWORK_ERROR',
|
|
152
|
-
message: error instanceof Error ? error.message : String(error)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (!response.ok) {
|
|
158
|
-
return {
|
|
159
|
-
ok: false,
|
|
160
|
-
error: { code: `HTTP_${response.status}`, message: `请求失败(HTTP ${response.status})` }
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
let payload: unknown
|
|
165
|
-
try {
|
|
166
|
-
payload = await response.json()
|
|
167
|
-
} catch {
|
|
168
|
-
return badResponse('响应不是合法 JSON')
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (!isRecord(payload)) return badResponse('响应不是 JSON 对象')
|
|
172
|
-
return { ok: true, data: payload as TBody }
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return {
|
|
176
|
-
async test(connection) {
|
|
177
|
-
const result = await postJson<TestResponseBody>('/test', { connection })
|
|
178
|
-
if (!result.ok) return result
|
|
179
|
-
if (result.data.ok === true) return { ok: true, data: undefined }
|
|
180
|
-
return { ok: false, error: toConnectorError(result.data.error) }
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
async describe(connection, sql) {
|
|
184
|
-
const result = await postJson<DescribeResponseBody>('/describe', { connection, sql })
|
|
185
|
-
if (!result.ok) return result
|
|
186
|
-
if (result.data.ok !== true) {
|
|
187
|
-
return { ok: false, error: toConnectorError(result.data.error) }
|
|
188
|
-
}
|
|
189
|
-
const fields = normalizeFields(result.data.fields)
|
|
190
|
-
if (!fields) return badResponse('describe 响应缺少合法的 fields 数组')
|
|
191
|
-
return { ok: true, data: fields }
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
async query(connection, sql, values) {
|
|
195
|
-
const result = await postJson<QueryResponseBody>('/query', { connection, sql, values })
|
|
196
|
-
if (!result.ok) return result
|
|
197
|
-
if (result.data.ok !== true) {
|
|
198
|
-
return { ok: false, error: toConnectorError(result.data.error) }
|
|
199
|
-
}
|
|
200
|
-
const fields = normalizeFields(result.data.fields)
|
|
201
|
-
if (!fields) return badResponse('query 响应缺少合法的 fields 数组')
|
|
202
|
-
if (!Array.isArray(result.data.rows)) return badResponse('query 响应缺少 rows 数组')
|
|
203
|
-
return { ok: true, data: { fields, rows: result.data.rows } }
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Sheet } from '@veltra/sheet-core'
|
|
2
|
-
import { exportSheetXlsx } from '@veltra/sheet-core/core/io/export'
|
|
3
|
-
|
|
4
|
-
/** 列宽条目:模型列索引 → 像素宽(与 SheetSnapshot.colWidths 同构) */
|
|
5
|
-
export type ReportColWidthEntry = readonly [number, number]
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 将已填充的 Sheet(Filled Report)导出为保真 XLSX(合并 / 样式 / 行高 / 列宽 / 浮动图)。
|
|
9
|
-
* 组装与序列化委托 sheet-core `exportSheetXlsx`(与 `exportWorkbookXlsx` 同一套单表逻辑);
|
|
10
|
-
* 条件样式颜色已在 renderReport 展开阶段打平进 StylePool(ADR-0001 决策 2)。
|
|
11
|
-
* 列宽取自 sheet 模型(`getColWidths`)。
|
|
12
|
-
*/
|
|
13
|
-
export function exportFilledReportXlsx(sheet: Sheet): Promise<Uint8Array> {
|
|
14
|
-
return exportSheetXlsx(sheet, { fallbackName: '报表' })
|
|
15
|
-
}
|