@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,63 @@
|
|
|
1
|
+
import type { SheetSnapshot } from '@veltra/sheet-core'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { previewGridSize } from '../preview-grid-size'
|
|
5
|
+
|
|
6
|
+
function snap(
|
|
7
|
+
partial: Partial<SheetSnapshot> & Pick<SheetSnapshot, 'cells'>
|
|
8
|
+
): Pick<SheetSnapshot, 'cells' | 'merges' | 'meta' | 'rows'> {
|
|
9
|
+
return { merges: [], rows: 0, ...partial }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('previewGridSize', () => {
|
|
13
|
+
it('template 模式用内容包围盒,忽略设计态 canvas 尺寸', () => {
|
|
14
|
+
expect(
|
|
15
|
+
previewGridSize(
|
|
16
|
+
snap({
|
|
17
|
+
cells: [
|
|
18
|
+
{ row: 0, col: 0, v: '客户' },
|
|
19
|
+
{ row: 0, col: 1, v: '金额' }
|
|
20
|
+
],
|
|
21
|
+
rows: 24,
|
|
22
|
+
cols: 10
|
|
23
|
+
}),
|
|
24
|
+
'template'
|
|
25
|
+
)
|
|
26
|
+
).toEqual({ rows: 1, cols: 2 })
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('filled 模式行保留展开布局尺寸,列按包围盒收敛(去掉设计态撑大的列)', () => {
|
|
30
|
+
expect(
|
|
31
|
+
previewGridSize(
|
|
32
|
+
snap({
|
|
33
|
+
cells: [
|
|
34
|
+
{ row: 0, col: 0, v: '客户' },
|
|
35
|
+
{ row: 3, col: 1, v: 300 }
|
|
36
|
+
],
|
|
37
|
+
rows: 4,
|
|
38
|
+
cols: 10
|
|
39
|
+
}),
|
|
40
|
+
'filled'
|
|
41
|
+
)
|
|
42
|
+
).toEqual({ rows: 4, cols: 2 })
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('空快照至少 1×1(VTable 需要非零网格)', () => {
|
|
46
|
+
expect(previewGridSize(snap({ cells: [] }), 'template')).toEqual({ rows: 1, cols: 1 })
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('包围盒计入合并区终点与 meta 绑定格', () => {
|
|
50
|
+
expect(
|
|
51
|
+
previewGridSize(
|
|
52
|
+
snap({
|
|
53
|
+
cells: [{ row: 0, col: 0, v: '标题' }],
|
|
54
|
+
merges: [{ start: { row: 0, col: 0 }, end: { row: 0, col: 2 } }],
|
|
55
|
+
meta: [{ row: 2, col: 1, namespace: 'report', payload: {} }],
|
|
56
|
+
rows: 24,
|
|
57
|
+
cols: 10
|
|
58
|
+
}),
|
|
59
|
+
'template'
|
|
60
|
+
)
|
|
61
|
+
).toEqual({ rows: 3, cols: 3 })
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { Workbook } from '@veltra/sheet-core'
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { createApp, h, nextTick, ref, type App } from 'vue'
|
|
4
|
+
|
|
5
|
+
import { UReportDesigner } from '../../../index'
|
|
6
|
+
import { REPORT_META_NAMESPACE } from '../../../report/binding'
|
|
7
|
+
import type { DataConnection, DataConnector } from '../../../report/connector'
|
|
8
|
+
import type { ReportTemplate } from '../../../report/template'
|
|
9
|
+
import type { ParamValues, ReportBinding } from '../../../report/types'
|
|
10
|
+
import type { ReportDesignerExposed } from '../../../types'
|
|
11
|
+
import * as cellCoords from '../designer/cell-coords'
|
|
12
|
+
import * as gridOverlay from '../designer/use-grid-overlay'
|
|
13
|
+
import { FIELD_DRAG_MIME } from '../field-panel-helpers'
|
|
14
|
+
|
|
15
|
+
// ---- 内联 fixtures:stub connector(实现 DataConnector 接口的内存测试夹具)----
|
|
16
|
+
|
|
17
|
+
function createStubConnector() {
|
|
18
|
+
const calls = {
|
|
19
|
+
test: [] as DataConnection[],
|
|
20
|
+
describe: [] as Array<{ connection: DataConnection; sql: string }>,
|
|
21
|
+
query: [] as Array<{ connection: DataConnection; sql: string; values: ParamValues }>
|
|
22
|
+
}
|
|
23
|
+
/** test 结果可变(失败路径用例切换为业务错误) */
|
|
24
|
+
const state = {
|
|
25
|
+
testOutcome: { ok: true, data: undefined } as Awaited<ReturnType<DataConnector['test']>>
|
|
26
|
+
}
|
|
27
|
+
const connector: DataConnector = {
|
|
28
|
+
test: (connection) => {
|
|
29
|
+
calls.test.push(connection)
|
|
30
|
+
return Promise.resolve(state.testOutcome)
|
|
31
|
+
},
|
|
32
|
+
describe: (connection, sql) => {
|
|
33
|
+
calls.describe.push({ connection, sql })
|
|
34
|
+
return Promise.resolve({
|
|
35
|
+
ok: true,
|
|
36
|
+
data: [
|
|
37
|
+
{ name: 'customer', label: '客户', type: 'string' as const },
|
|
38
|
+
{ name: 'amount', label: '金额', type: 'number' as const }
|
|
39
|
+
]
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
query: (connection, sql, values) => {
|
|
43
|
+
calls.query.push({ connection, sql, values })
|
|
44
|
+
return Promise.resolve({
|
|
45
|
+
ok: true,
|
|
46
|
+
data: {
|
|
47
|
+
fields: [
|
|
48
|
+
{ name: 'customer', label: '客户', type: 'string' as const },
|
|
49
|
+
{ name: 'amount', label: '金额', type: 'number' as const }
|
|
50
|
+
],
|
|
51
|
+
rows: [
|
|
52
|
+
{ customer: '甲公司', amount: 100 },
|
|
53
|
+
{ customer: '乙公司', amount: 400 }
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { connector, calls, state }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ---- 挂载与等待 ----
|
|
63
|
+
|
|
64
|
+
const apps: App[] = []
|
|
65
|
+
const containers: HTMLElement[] = []
|
|
66
|
+
|
|
67
|
+
function mountDesigner(workbook: Workbook, options?: { template?: ReportTemplate }) {
|
|
68
|
+
const { connector, calls, state } = createStubConnector()
|
|
69
|
+
const el = document.createElement('div')
|
|
70
|
+
el.style.width = '960px'
|
|
71
|
+
el.style.height = '600px'
|
|
72
|
+
document.body.appendChild(el)
|
|
73
|
+
containers.push(el)
|
|
74
|
+
const connections = ref<DataConnection[]>([])
|
|
75
|
+
const exposedRef = { value: undefined as ReportDesignerExposed | undefined }
|
|
76
|
+
const app = createApp({
|
|
77
|
+
render: () =>
|
|
78
|
+
h(UReportDesigner, {
|
|
79
|
+
connector,
|
|
80
|
+
workbook,
|
|
81
|
+
connections: connections.value,
|
|
82
|
+
template: options?.template,
|
|
83
|
+
'onUpdate:connections': (value: DataConnection[]) => {
|
|
84
|
+
connections.value = value
|
|
85
|
+
},
|
|
86
|
+
ref: (value: unknown) => {
|
|
87
|
+
exposedRef.value = value as ReportDesignerExposed | undefined
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
app.mount(el)
|
|
92
|
+
apps.push(app)
|
|
93
|
+
return { app, el, connections, exposedRef, calls, state }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 等待抽屉(teleport + transition)与连接器微任务落定 */
|
|
97
|
+
async function flush(): Promise<void> {
|
|
98
|
+
await nextTick()
|
|
99
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
100
|
+
await nextTick()
|
|
101
|
+
await nextTick()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** 按文本定位按钮(drawer 经 Teleport 挂到 body,统一在 document 范围找) */
|
|
105
|
+
function findButton(text: string): HTMLButtonElement | undefined {
|
|
106
|
+
return [...document.querySelectorAll<HTMLButtonElement>('button')].find((button) =>
|
|
107
|
+
button.textContent?.includes(text)
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function click(button: HTMLElement): Promise<void> {
|
|
112
|
+
button.dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
113
|
+
await flush()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 构造字段拖拽 drop 事件(happy-dom 无 DataTransfer 构造器,注入最小桩) */
|
|
117
|
+
function dispatchFieldDrop(target: HTMLElement, payload: string): void {
|
|
118
|
+
const event = new Event('drop', { bubbles: true, cancelable: true })
|
|
119
|
+
Object.defineProperty(event, 'dataTransfer', {
|
|
120
|
+
value: {
|
|
121
|
+
types: [FIELD_DRAG_MIME],
|
|
122
|
+
getData: (type: string) => (type === FIELD_DRAG_MIME ? payload : '')
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
// 落点超出网格视口 → hit-test 落空,回退当前选区(确定性断言)
|
|
126
|
+
Object.defineProperty(event, 'clientX', { value: 99999 })
|
|
127
|
+
Object.defineProperty(event, 'clientY', { value: 99999 })
|
|
128
|
+
target.dispatchEvent(event)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 构造字段拖拽 dragover 事件 */
|
|
132
|
+
function dispatchFieldDragOver(target: HTMLElement, clientX = 100, clientY = 100): void {
|
|
133
|
+
const event = new Event('dragover', { bubbles: true, cancelable: true })
|
|
134
|
+
Object.defineProperty(event, 'dataTransfer', {
|
|
135
|
+
value: { types: [FIELD_DRAG_MIME], dropEffect: 'copy' }
|
|
136
|
+
})
|
|
137
|
+
Object.defineProperty(event, 'clientX', { value: clientX })
|
|
138
|
+
Object.defineProperty(event, 'clientY', { value: clientY })
|
|
139
|
+
target.dispatchEvent(event)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
afterEach(() => {
|
|
143
|
+
while (apps.length) apps.pop()!.unmount()
|
|
144
|
+
while (containers.length) containers.pop()!.remove()
|
|
145
|
+
// drawer Teleport 到 body,卸载后清理残留
|
|
146
|
+
document.querySelectorAll('.u-drawer-overlay').forEach((node) => node.remove())
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('UReportDesigner 最小闭环(数据中枢 + 拖拽绑定 + getTemplate)', () => {
|
|
150
|
+
it('连接 CRUD / 真实测试连接走 v-model:connections 与连接器;落格写 meta;getTemplate 吐出快照', async () => {
|
|
151
|
+
const workbook = new Workbook()
|
|
152
|
+
const { el, connections, exposedRef, calls } = mountDesigner(workbook)
|
|
153
|
+
await flush()
|
|
154
|
+
|
|
155
|
+
// 打开数据中枢 drawer(Teleport 到 body)
|
|
156
|
+
const hubTrigger = el.querySelector<HTMLButtonElement>('.u-report-designer__toolbar button')!
|
|
157
|
+
expect(hubTrigger.textContent).toContain('数据中枢')
|
|
158
|
+
await click(hubTrigger)
|
|
159
|
+
expect(document.querySelector('.u-report-hub')).toBeTruthy()
|
|
160
|
+
|
|
161
|
+
// 新建连接:表单出现 → 真实测试连接(经 stub connector)→ 保存
|
|
162
|
+
await click(findButton('新建连接')!)
|
|
163
|
+
expect(document.querySelector('.u-report-hub-connection-form')).toBeTruthy()
|
|
164
|
+
|
|
165
|
+
await click(findButton('测试连接')!)
|
|
166
|
+
expect(calls.test).toHaveLength(1)
|
|
167
|
+
expect(calls.test[0]).toMatchObject({ label: '新连接', type: 'mysql' })
|
|
168
|
+
expect(document.querySelector('.u-report-hub-connection-form__test')?.textContent).toContain(
|
|
169
|
+
'连接成功'
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
await click(findButton('保存')!)
|
|
173
|
+
expect(connections.value).toHaveLength(1)
|
|
174
|
+
expect(connections.value[0]).toMatchObject({ label: '新连接', type: 'mysql' })
|
|
175
|
+
const connectionId = connections.value[0]!.id
|
|
176
|
+
|
|
177
|
+
// 在该连接下新建数据集(编辑器出现,含 SQL 编辑与 schema/preview tabs)
|
|
178
|
+
await click(findButton('+ 新建数据集')!)
|
|
179
|
+
expect(document.querySelector('.u-report-hub-dataset-editor')).toBeTruthy()
|
|
180
|
+
const datasetId = document.querySelector('.u-report-hub__dataset-id')!.textContent!
|
|
181
|
+
|
|
182
|
+
// 关闭 drawer,回到设计态
|
|
183
|
+
await click(findButton('完成')!)
|
|
184
|
+
|
|
185
|
+
// 拖拽字段落格 → 写入 Cell Meta 绑定(落点 hit-test 落空 → 回退当前选区 A1)
|
|
186
|
+
const gridHost = el.querySelector<HTMLElement>('.u-report-designer__grid')!
|
|
187
|
+
dispatchFieldDrop(gridHost, `${datasetId}:customer`)
|
|
188
|
+
await flush()
|
|
189
|
+
|
|
190
|
+
const metas = [...workbook.activeSheet.entriesCellMeta()].filter(
|
|
191
|
+
([, namespace]) => namespace === REPORT_META_NAMESPACE
|
|
192
|
+
)
|
|
193
|
+
expect(metas).toHaveLength(1)
|
|
194
|
+
const [addr, , payload] = metas[0]!
|
|
195
|
+
expect(addr).toEqual({ row: 0, col: 0 })
|
|
196
|
+
expect(payload as ReportBinding).toMatchObject({
|
|
197
|
+
dataset: datasetId,
|
|
198
|
+
field: 'customer',
|
|
199
|
+
preset: 'detail',
|
|
200
|
+
aggregate: 'list',
|
|
201
|
+
expand: 'down'
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// getTemplate() 返回含 meta 绑定与内嵌数据集定义(连接对象内嵌,凭据随模板流转)
|
|
205
|
+
const template = exposedRef.value!.getTemplate()
|
|
206
|
+
expect(template.version).toBe(1)
|
|
207
|
+
expect(template.meta).toHaveLength(1)
|
|
208
|
+
expect(template.meta![0]).toMatchObject({ row: 0, col: 0, namespace: 'report' })
|
|
209
|
+
expect(template.datasets).toEqual([
|
|
210
|
+
{
|
|
211
|
+
id: datasetId,
|
|
212
|
+
label: '新数据集',
|
|
213
|
+
connection: { ...connections.value[0]!, id: connectionId },
|
|
214
|
+
sql: ''
|
|
215
|
+
}
|
|
216
|
+
])
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('测试连接业务失败(ok:false)时展示可读错误提示', async () => {
|
|
220
|
+
const workbook = new Workbook()
|
|
221
|
+
const { el, state } = mountDesigner(workbook)
|
|
222
|
+
state.testOutcome = {
|
|
223
|
+
ok: false,
|
|
224
|
+
error: { code: 'CONNECTION_FAILED', message: '数据库连接失败' }
|
|
225
|
+
}
|
|
226
|
+
await flush()
|
|
227
|
+
|
|
228
|
+
await click(el.querySelector<HTMLButtonElement>('.u-report-designer__toolbar button')!)
|
|
229
|
+
await click(findButton('新建连接')!)
|
|
230
|
+
await click(findButton('测试连接')!)
|
|
231
|
+
|
|
232
|
+
const banner = document.querySelector('.u-report-hub-connection-form__test')
|
|
233
|
+
expect(banner?.textContent).toContain('数据库连接失败')
|
|
234
|
+
expect(banner?.classList.contains('is-ok')).toBe(false)
|
|
235
|
+
})
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
describe('UReportDesigner 全量:template 载入与预览模式(内嵌查看器路径)', () => {
|
|
239
|
+
const TEMPLATE_CONNECTION: DataConnection = {
|
|
240
|
+
id: 'conn-template',
|
|
241
|
+
label: '模板连接',
|
|
242
|
+
type: 'mysql',
|
|
243
|
+
host: '127.0.0.1',
|
|
244
|
+
port: 3306,
|
|
245
|
+
database: 'demo',
|
|
246
|
+
username: 'root',
|
|
247
|
+
password: ''
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function buildTemplate(): ReportTemplate {
|
|
251
|
+
const group: ReportBinding = {
|
|
252
|
+
dataset: 'ds-template',
|
|
253
|
+
field: 'customer',
|
|
254
|
+
preset: 'groupHeader',
|
|
255
|
+
aggregate: 'group',
|
|
256
|
+
expand: 'down',
|
|
257
|
+
sort: 'none',
|
|
258
|
+
conditionalRules: []
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
version: 1,
|
|
262
|
+
cells: [{ row: 0, col: 0, v: '客户' }],
|
|
263
|
+
styles: [],
|
|
264
|
+
merges: [],
|
|
265
|
+
frozen: { rows: 0, cols: 0 },
|
|
266
|
+
rows: 24,
|
|
267
|
+
cols: 10,
|
|
268
|
+
meta: [{ row: 1, col: 0, namespace: REPORT_META_NAMESPACE, payload: group }],
|
|
269
|
+
datasets: [
|
|
270
|
+
{
|
|
271
|
+
id: 'ds-template',
|
|
272
|
+
label: '订单',
|
|
273
|
+
connection: TEMPLATE_CONNECTION,
|
|
274
|
+
sql: 'SELECT customer, amount FROM orders'
|
|
275
|
+
}
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function reportMetas(workbook: Workbook) {
|
|
281
|
+
return [...workbook.activeSheet.entriesCellMeta()].filter(
|
|
282
|
+
([, namespace]) => namespace === REPORT_META_NAMESPACE
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
it('template prop 载入恢复绑定与连接;预览切换经内嵌查看器取数展开;切回设计态绑定不丢', async () => {
|
|
287
|
+
const workbook = new Workbook()
|
|
288
|
+
const { el, connections, exposedRef, calls } = mountDesigner(workbook, {
|
|
289
|
+
template: buildTemplate()
|
|
290
|
+
})
|
|
291
|
+
await flush()
|
|
292
|
+
|
|
293
|
+
// 模板载入:绑定恢复 + 内嵌连接合并进 v-model 列表
|
|
294
|
+
expect(reportMetas(workbook)).toHaveLength(1)
|
|
295
|
+
expect(connections.value.map((item) => item.id)).toEqual(['conn-template'])
|
|
296
|
+
|
|
297
|
+
// 切预览:内嵌查看器按模板内嵌数据集取数(含 Filter Bar 参数默认值)
|
|
298
|
+
await click(findButton('预览模式')!)
|
|
299
|
+
expect(el.querySelector('.u-report-viewer')).toBeTruthy()
|
|
300
|
+
expect(calls.query).toHaveLength(1)
|
|
301
|
+
expect(calls.query[0]!.connection.id).toBe('conn-template')
|
|
302
|
+
expect(calls.query[0]!.sql).toBe('SELECT customer, amount FROM orders')
|
|
303
|
+
// 取数成功:无业务错误 banner;设计格线已卸载
|
|
304
|
+
expect(el.querySelector('.u-report-viewer__error')).toBeFalsy()
|
|
305
|
+
expect(el.querySelector('.u-report-designer__grid')).toBeFalsy()
|
|
306
|
+
|
|
307
|
+
// 切回设计态:绑定不丢,可继续设计
|
|
308
|
+
await click(findButton('设计模式')!)
|
|
309
|
+
expect(el.querySelector('.u-report-viewer')).toBeFalsy()
|
|
310
|
+
expect(el.querySelector('.u-report-designer__grid')).toBeTruthy()
|
|
311
|
+
expect(reportMetas(workbook)).toHaveLength(1)
|
|
312
|
+
|
|
313
|
+
// getTemplate 往返:绑定与内嵌数据集定义完整
|
|
314
|
+
const roundTrip = exposedRef.value!.getTemplate()
|
|
315
|
+
expect(roundTrip.meta).toHaveLength(1)
|
|
316
|
+
expect(roundTrip.datasets).toHaveLength(1)
|
|
317
|
+
expect(roundTrip.datasets![0]).toMatchObject({ id: 'ds-template', label: '订单' })
|
|
318
|
+
expect(roundTrip.datasets![0]!.connection.id).toBe('conn-template')
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
it('预览态导出 XLSX 按钮可见且转调查看器 exportXlsx()', async () => {
|
|
322
|
+
const workbook = new Workbook()
|
|
323
|
+
const { el } = mountDesigner(workbook, { template: buildTemplate() })
|
|
324
|
+
await flush()
|
|
325
|
+
|
|
326
|
+
// 设计态无导出按钮
|
|
327
|
+
expect(findButton('导出 XLSX')).toBeUndefined()
|
|
328
|
+
|
|
329
|
+
await click(findButton('预览模式')!)
|
|
330
|
+
const exportButton = findButton('导出 XLSX')
|
|
331
|
+
expect(exportButton).toBeTruthy()
|
|
332
|
+
await flush()
|
|
333
|
+
|
|
334
|
+
const exportModule = await import('../../../report/export-xlsx')
|
|
335
|
+
const catKitFe = await import('@cat-kit/fe')
|
|
336
|
+
const exportSpy = vi
|
|
337
|
+
.spyOn(exportModule, 'exportFilledReportXlsx')
|
|
338
|
+
.mockResolvedValue(new Uint8Array([80, 75, 3, 4]))
|
|
339
|
+
const saveBlobSpy = vi.spyOn(catKitFe, 'saveBlob').mockImplementation(() => {})
|
|
340
|
+
|
|
341
|
+
await click(exportButton!)
|
|
342
|
+
expect(exportSpy).toHaveBeenCalled()
|
|
343
|
+
expect(saveBlobSpy).toHaveBeenCalled()
|
|
344
|
+
expect(el.querySelector('.u-report-viewer')).toBeTruthy()
|
|
345
|
+
|
|
346
|
+
exportSpy.mockRestore()
|
|
347
|
+
saveBlobSpy.mockRestore()
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it('字段拖拽 dragover 时落点高亮随 hit-test 更新;落空时提示回退当前选区', async () => {
|
|
351
|
+
const workbook = new Workbook()
|
|
352
|
+
workbook.activeSheet.selectCell({ row: 2, col: 1 })
|
|
353
|
+
const { el } = mountDesigner(workbook)
|
|
354
|
+
await flush()
|
|
355
|
+
|
|
356
|
+
const gridHost = el.querySelector<HTMLElement>('.u-report-designer__grid')!
|
|
357
|
+
const overlayRect = {
|
|
358
|
+
left: 10,
|
|
359
|
+
top: 20,
|
|
360
|
+
right: 90,
|
|
361
|
+
bottom: 44,
|
|
362
|
+
width: 80,
|
|
363
|
+
height: 24,
|
|
364
|
+
centerX: 50,
|
|
365
|
+
centerY: 32
|
|
366
|
+
}
|
|
367
|
+
const hitTestSpy = vi
|
|
368
|
+
.spyOn(cellCoords, 'resolveGridDropAddress')
|
|
369
|
+
.mockReturnValueOnce({ row: 1, col: 2 })
|
|
370
|
+
.mockReturnValue(null)
|
|
371
|
+
const overlaySpy = vi.spyOn(gridOverlay, 'readCellOverlayRect').mockReturnValue(overlayRect)
|
|
372
|
+
|
|
373
|
+
dispatchFieldDragOver(gridHost, 120, 140)
|
|
374
|
+
await flush()
|
|
375
|
+
expect(el.querySelector('.u-report-drop-highlight')).toBeTruthy()
|
|
376
|
+
expect(el.querySelector('.u-report-drop-highlight__fallback')).toBeNull()
|
|
377
|
+
|
|
378
|
+
dispatchFieldDragOver(gridHost, 99999, 99999)
|
|
379
|
+
await flush()
|
|
380
|
+
expect(el.querySelector('.u-report-drop-highlight')).toBeNull()
|
|
381
|
+
const fallback = el.querySelector('.u-report-drop-highlight__fallback')
|
|
382
|
+
expect(fallback).toBeTruthy()
|
|
383
|
+
expect(fallback!.textContent).toContain('B3')
|
|
384
|
+
|
|
385
|
+
hitTestSpy.mockRestore()
|
|
386
|
+
overlaySpy.mockRestore()
|
|
387
|
+
})
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
describe('UReportDesigner Action Pill', () => {
|
|
391
|
+
const overlayRect = {
|
|
392
|
+
left: 10,
|
|
393
|
+
top: 80,
|
|
394
|
+
right: 90,
|
|
395
|
+
bottom: 104,
|
|
396
|
+
width: 80,
|
|
397
|
+
height: 24,
|
|
398
|
+
centerX: 50,
|
|
399
|
+
centerY: 92
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function spyOverlay() {
|
|
403
|
+
const layoutSpy = vi
|
|
404
|
+
.spyOn(cellCoords, 'resolveGridOverlayLayout')
|
|
405
|
+
.mockReturnValue({
|
|
406
|
+
gridEl: document.createElement('div'),
|
|
407
|
+
layout: { offsetX: 0, offsetY: 77, viewW: 640, viewH: 400 }
|
|
408
|
+
})
|
|
409
|
+
const overlaySpy = vi.spyOn(gridOverlay, 'readCellOverlayRect').mockReturnValue(overlayRect)
|
|
410
|
+
return () => {
|
|
411
|
+
layoutSpy.mockRestore()
|
|
412
|
+
overlaySpy.mockRestore()
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
it('小计预设默认条显示聚合、隐藏展开方向,并提供删除绑定', async () => {
|
|
417
|
+
const workbook = new Workbook()
|
|
418
|
+
workbook.activeSheet.setCellMeta({ row: 0, col: 0 }, REPORT_META_NAMESPACE, {
|
|
419
|
+
dataset: 'ds',
|
|
420
|
+
field: 'amount',
|
|
421
|
+
aggregate: 'sum',
|
|
422
|
+
expand: 'none',
|
|
423
|
+
preset: 'subtotal'
|
|
424
|
+
} satisfies ReportBinding)
|
|
425
|
+
workbook.activeSheet.selectCell({ row: 0, col: 0 })
|
|
426
|
+
|
|
427
|
+
const restore = spyOverlay()
|
|
428
|
+
const { el } = mountDesigner(workbook)
|
|
429
|
+
await flush()
|
|
430
|
+
|
|
431
|
+
const panel = el.querySelector('.u-report-float-panel')
|
|
432
|
+
expect(panel).toBeTruthy()
|
|
433
|
+
expect(panel!.querySelector('.u-report-float-panel__body')).toBeNull()
|
|
434
|
+
expect(panel!.querySelector('.u-report-float-panel__select--aggregate')).toBeTruthy()
|
|
435
|
+
expect(panel!.querySelector('.u-report-float-panel__select--expand')).toBeNull()
|
|
436
|
+
const deleteBtn = [...panel!.querySelectorAll('button')].find((button) =>
|
|
437
|
+
button.textContent?.includes('删除绑定')
|
|
438
|
+
)
|
|
439
|
+
expect(deleteBtn).toBeTruthy()
|
|
440
|
+
restore()
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
it('明细预设默认条显示展开方向、隐藏聚合', async () => {
|
|
444
|
+
const workbook = new Workbook()
|
|
445
|
+
workbook.activeSheet.setCellMeta({ row: 0, col: 0 }, REPORT_META_NAMESPACE, {
|
|
446
|
+
dataset: 'ds',
|
|
447
|
+
field: 'orderNo',
|
|
448
|
+
aggregate: 'list',
|
|
449
|
+
expand: 'down',
|
|
450
|
+
preset: 'detail'
|
|
451
|
+
} satisfies ReportBinding)
|
|
452
|
+
workbook.activeSheet.selectCell({ row: 0, col: 0 })
|
|
453
|
+
|
|
454
|
+
const restore = spyOverlay()
|
|
455
|
+
const { el } = mountDesigner(workbook)
|
|
456
|
+
await flush()
|
|
457
|
+
|
|
458
|
+
const panel = el.querySelector('.u-report-float-panel')
|
|
459
|
+
expect(panel).toBeTruthy()
|
|
460
|
+
expect(panel!.querySelector('.u-report-float-panel__select--expand')).toBeTruthy()
|
|
461
|
+
expect(panel!.querySelector('.u-report-float-panel__select--aggregate')).toBeNull()
|
|
462
|
+
restore()
|
|
463
|
+
})
|
|
464
|
+
})
|