@veltra/sheet 2.1.1 → 2.2.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 +76 -0
- package/dist/components/report/designer/cell-coords.js +46 -0
- package/dist/components/report/designer/col-widths.js +15 -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 +385 -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 +269 -0
- package/dist/components/report/designer/rules-dialog.js +135 -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/report-designer.js +343 -0
- package/dist/components/report/report-viewer.js +111 -0
- package/dist/components/report/style.d.ts +17 -0
- package/dist/components/report/style.js +18 -0
- package/dist/components/report/style2.css +869 -0
- package/dist/components/report/use-report-designer.js +360 -0
- package/dist/components/report/use-report-viewer.js +50 -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 +1 -1
- 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 +1 -1
- package/dist/{vue → components/sheet}/popups/find-popup.js +1 -1
- package/dist/{vue → components/sheet}/popups/font-color-popup.js +1 -1
- package/dist/{vue → components/sheet}/popups/font-size-popup.js +1 -1
- 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 +1 -1
- 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 +8 -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 +10 -2
- package/dist/{vue → components/sheet}/use-sheet-state.js +3 -3
- 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 +45 -0
- package/dist/report/binding.js +175 -0
- package/dist/report/connector.d.ts +66 -0
- package/dist/report/connector.js +159 -0
- package/dist/report/export-xlsx.d.ts +19 -0
- package/dist/report/export-xlsx.js +95 -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 +157 -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 +59 -0
- package/dist/report/template.js +80 -0
- package/dist/report/types.d.ts +85 -0
- package/dist/tools/context.d.ts +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/report-designer.d.ts +36 -0
- package/dist/types/report-viewer.d.ts +38 -0
- package/dist/types/sheet.d.ts +17 -1
- package/package.json +3 -5
- package/src/components/report/__test__/conditional-rules-helpers.test.ts +87 -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__/report-designer.test.ts +388 -0
- package/src/components/report/__test__/report-viewer.test.ts +334 -0
- package/src/components/report/__test__/topology.test.ts +143 -0
- package/src/components/report/__test__/use-report-designer.test.ts +565 -0
- package/src/components/report/binding-badge.ts +73 -0
- package/src/components/report/designer/cell-coords.ts +94 -0
- package/src/components/report/designer/col-widths.ts +33 -0
- package/src/components/report/designer/conditional-rules/helpers.ts +186 -0
- package/src/components/report/designer/drop-highlight-overlay.vue +74 -0
- package/src/components/report/designer/float-panel.vue +387 -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 +126 -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/report-designer.vue +356 -0
- package/src/components/report/report-viewer.vue +128 -0
- package/src/components/report/style-designer.scss +583 -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 +547 -0
- package/src/components/report/use-report-viewer.ts +79 -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 +40 -3
- package/src/{vue → components/sheet}/__test__/sheet-context-menu.test.ts +1 -1
- 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 +1 -1
- package/src/{vue → components/sheet}/popups/export-popup.vue +2 -2
- package/src/{vue → components/sheet}/popups/fill-color-popup.vue +1 -1
- package/src/{vue → components/sheet}/popups/find-popup.vue +1 -1
- package/src/{vue → components/sheet}/popups/font-color-popup.vue +1 -1
- package/src/{vue → components/sheet}/popups/font-size-popup.vue +1 -1
- package/src/{vue → components/sheet}/popups/insert-image-popup.vue +1 -1
- package/src/{vue → components/sheet}/sheet-context-menu.ts +2 -2
- package/src/{vue → components/sheet}/sheet-toolbar.vue +2 -2
- package/src/{vue → components/sheet}/sheet.vue +4 -3
- package/src/{vue → components/sheet}/use-find-replace.ts +1 -1
- package/src/{vue → components/sheet}/use-sheet-grid.ts +7 -3
- package/src/{vue → components/sheet}/use-sheet-state.ts +3 -3
- 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 +218 -0
- package/src/report/__test__/connector.test.ts +218 -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 +728 -0
- package/src/report/__test__/rules.test.ts +131 -0
- package/src/report/__test__/template.test.ts +355 -0
- package/src/report/binding.ts +243 -0
- package/src/report/connector.ts +205 -0
- package/src/report/export-xlsx.ts +118 -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 +240 -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 +141 -0
- package/src/report/types.ts +96 -0
- package/src/tools/builtin.ts +2 -2
- package/src/types/index.ts +2 -6
- package/src/types/report-designer.ts +36 -0
- package/src/types/report-viewer.ts +37 -0
- package/src/types/sheet.ts +22 -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,356 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="cls.b">
|
|
3
|
+
<div :class="cls.e('toolbar')">
|
|
4
|
+
<u-button size="small" plain @click="hubVisible = true">数据中枢</u-button>
|
|
5
|
+
|
|
6
|
+
<div :class="cls.e('mode-toggle')" role="group" aria-label="视图模式">
|
|
7
|
+
<u-button
|
|
8
|
+
size="small"
|
|
9
|
+
:type="!isPreview ? 'primary' : undefined"
|
|
10
|
+
:plain="isPreview"
|
|
11
|
+
@click="setViewMode('design')"
|
|
12
|
+
>
|
|
13
|
+
设计模式
|
|
14
|
+
</u-button>
|
|
15
|
+
<u-button
|
|
16
|
+
size="small"
|
|
17
|
+
:type="isPreview ? 'primary' : undefined"
|
|
18
|
+
:plain="!isPreview"
|
|
19
|
+
@click="setViewMode('preview')"
|
|
20
|
+
>
|
|
21
|
+
预览模式
|
|
22
|
+
</u-button>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<u-button
|
|
26
|
+
v-if="isPreview"
|
|
27
|
+
size="small"
|
|
28
|
+
type="primary"
|
|
29
|
+
plain
|
|
30
|
+
:loading="exporting"
|
|
31
|
+
@click="exportPreviewXlsx"
|
|
32
|
+
>
|
|
33
|
+
导出 XLSX
|
|
34
|
+
</u-button>
|
|
35
|
+
|
|
36
|
+
<span :class="cls.e('hint')">
|
|
37
|
+
在数据中枢配置连接与 SQL
|
|
38
|
+
数据集,再将左侧字段点击或拖拽到单元格完成绑定;选中已绑定格可通过悬浮卡片调整角色、聚合与条件样式。
|
|
39
|
+
</span>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div v-if="!isPreview" :class="cls.e('body')">
|
|
43
|
+
<u-report-field-panel
|
|
44
|
+
:class="cls.e('field-panel')"
|
|
45
|
+
:datasets="catalog"
|
|
46
|
+
:selection-label="selectionLabel"
|
|
47
|
+
:bound-keys="boundKeys"
|
|
48
|
+
@bind="bindField"
|
|
49
|
+
/>
|
|
50
|
+
|
|
51
|
+
<div
|
|
52
|
+
ref="gridHostRef"
|
|
53
|
+
:class="cls.e('grid')"
|
|
54
|
+
@dragover="onGridDragOver"
|
|
55
|
+
@dragleave="onGridDragLeave"
|
|
56
|
+
@drop="onGridDrop"
|
|
57
|
+
>
|
|
58
|
+
<u-sheet
|
|
59
|
+
ref="sheetRef"
|
|
60
|
+
:class="cls.e('sheet')"
|
|
61
|
+
:workbook="workbook"
|
|
62
|
+
:rows="DESIGN_ROWS"
|
|
63
|
+
:cols="DESIGN_COLS"
|
|
64
|
+
:show-tabs="false"
|
|
65
|
+
:resolve-cell-style="resolveCellStyle"
|
|
66
|
+
:resolve-cell-renderer="resolveCellRenderer"
|
|
67
|
+
/>
|
|
68
|
+
|
|
69
|
+
<u-report-topology-overlay
|
|
70
|
+
:cell="activeCell"
|
|
71
|
+
:binding="activeBinding ?? null"
|
|
72
|
+
:entries="bindingEntries"
|
|
73
|
+
:meta-tick="metaTick"
|
|
74
|
+
:host-el="gridHostEl"
|
|
75
|
+
:get-grid="getDesignGrid"
|
|
76
|
+
:get-binding-at="getBindingAt"
|
|
77
|
+
/>
|
|
78
|
+
|
|
79
|
+
<u-report-drop-highlight-overlay
|
|
80
|
+
:cell="dropTargetAddr"
|
|
81
|
+
:host-el="gridHostEl"
|
|
82
|
+
:get-grid="getDesignGrid"
|
|
83
|
+
:dragging="isFieldDragging"
|
|
84
|
+
:fallback-label="selectionLabel"
|
|
85
|
+
/>
|
|
86
|
+
|
|
87
|
+
<u-report-float-panel
|
|
88
|
+
:cell="activeCell"
|
|
89
|
+
:binding="activeBinding ?? null"
|
|
90
|
+
:resolved-row-parent-label="resolvedRowParentLabel"
|
|
91
|
+
:resolved-col-parent-label="resolvedColParentLabel"
|
|
92
|
+
:parent-pick-mode="parentPick?.mode ?? null"
|
|
93
|
+
:row-parent-candidates="rowParentCandidates"
|
|
94
|
+
:col-parent-candidates="colParentCandidates"
|
|
95
|
+
:resolve-field-label="resolveFieldLabel"
|
|
96
|
+
:host-el="gridHostEl"
|
|
97
|
+
:get-grid="getDesignGrid"
|
|
98
|
+
@patch="patchActiveBinding"
|
|
99
|
+
@remove="removeActiveBinding"
|
|
100
|
+
@open-rules="rulesDialogVisible = true"
|
|
101
|
+
@start-parent-pick="startParentPick"
|
|
102
|
+
@cancel-parent-pick="cancelParentPick"
|
|
103
|
+
@clear-parent="clearParent"
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div v-else-if="previewTemplate" :class="cls.e('preview')">
|
|
109
|
+
<u-report-viewer
|
|
110
|
+
ref="previewViewerRef"
|
|
111
|
+
:connector="props.connector"
|
|
112
|
+
:template="previewTemplate"
|
|
113
|
+
:workbook="previewWorkbook"
|
|
114
|
+
:col-widths="designColWidths"
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<u-drawer v-model="hubVisible" :class="cls.e('hub-drawer')" show-close>
|
|
119
|
+
<u-report-dataset-hub :hub="designer" @close="hubVisible = false" />
|
|
120
|
+
</u-drawer>
|
|
121
|
+
|
|
122
|
+
<u-report-rules-dialog
|
|
123
|
+
v-model="rulesDialogVisible"
|
|
124
|
+
:rules="activeBinding?.conditionalRules ?? EMPTY_CONDITIONAL_RULES"
|
|
125
|
+
:binding-field="activeBinding?.field ?? ''"
|
|
126
|
+
:dataset-fields="activeDatasetFields"
|
|
127
|
+
:field-type="activeFieldType"
|
|
128
|
+
@save="saveConditionalRules"
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
</template>
|
|
132
|
+
|
|
133
|
+
<script lang="ts" setup>
|
|
134
|
+
import { UButton, UDrawer } from '@veltra/desktop'
|
|
135
|
+
import type { CellAddress, SheetGrid } from '@veltra/sheet-core'
|
|
136
|
+
import { Workbook } from '@veltra/sheet-core'
|
|
137
|
+
import { bem } from '@veltra/utils'
|
|
138
|
+
import { computed, nextTick, ref, shallowRef, useTemplateRef, watch } from 'vue'
|
|
139
|
+
|
|
140
|
+
import type { ReportTemplate } from '../../report/template'
|
|
141
|
+
import type { ConditionalRule } from '../../report/types'
|
|
142
|
+
import type {
|
|
143
|
+
ReportDesignerEmits,
|
|
144
|
+
ReportDesignerProps,
|
|
145
|
+
ReportViewerExposed,
|
|
146
|
+
SheetExposed,
|
|
147
|
+
_ReportDesignerExposed
|
|
148
|
+
} from '../../types'
|
|
149
|
+
import { USheet } from '../sheet'
|
|
150
|
+
import UReportDatasetHub from './designer-hub.vue'
|
|
151
|
+
import { resolveGridDropAddress } from './designer/cell-coords'
|
|
152
|
+
import { applyGridColWidths, readGridColWidths } from './designer/col-widths'
|
|
153
|
+
import UReportDropHighlightOverlay from './designer/drop-highlight-overlay.vue'
|
|
154
|
+
import UReportFloatPanel from './designer/float-panel.vue'
|
|
155
|
+
import UReportRulesDialog from './designer/rules-dialog.vue'
|
|
156
|
+
import UReportTopologyOverlay from './designer/topology-overlay.vue'
|
|
157
|
+
import { FIELD_DRAG_MIME, parseFieldDragPayload } from './field-panel-helpers'
|
|
158
|
+
import UReportFieldPanel from './field-panel.vue'
|
|
159
|
+
import UReportViewer from './report-viewer.vue'
|
|
160
|
+
import { useReportDesigner } from './use-report-designer'
|
|
161
|
+
|
|
162
|
+
defineOptions({ name: 'UReportDesigner' })
|
|
163
|
+
|
|
164
|
+
const props = withDefaults(defineProps<ReportDesignerProps>(), { connections: () => [] })
|
|
165
|
+
const emit = defineEmits<ReportDesignerEmits>()
|
|
166
|
+
|
|
167
|
+
const cls = bem('report-designer')
|
|
168
|
+
|
|
169
|
+
/** 设计态网格尺寸(列宽捕获范围与之一致) */
|
|
170
|
+
const DESIGN_ROWS = 24
|
|
171
|
+
const DESIGN_COLS = 10
|
|
172
|
+
|
|
173
|
+
/** 条件样式弹窗在无绑定格时的空规则占位 */
|
|
174
|
+
const EMPTY_CONDITIONAL_RULES: ConditionalRule[] = []
|
|
175
|
+
|
|
176
|
+
/** `v-model:connections` 可写代理(连接为纯序列化对象,仅驻留内存) */
|
|
177
|
+
const connections = computed({
|
|
178
|
+
get: () => props.connections,
|
|
179
|
+
set: (value) => emit('update:connections', value)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
const designer = useReportDesigner({ props, connections })
|
|
183
|
+
const {
|
|
184
|
+
workbook,
|
|
185
|
+
catalog,
|
|
186
|
+
boundKeys,
|
|
187
|
+
activeCell,
|
|
188
|
+
selectionLabel,
|
|
189
|
+
activeBinding,
|
|
190
|
+
activeFieldType,
|
|
191
|
+
activeDatasetFields,
|
|
192
|
+
resolvedRowParentLabel,
|
|
193
|
+
resolvedColParentLabel,
|
|
194
|
+
parentPick,
|
|
195
|
+
rowParentCandidates,
|
|
196
|
+
colParentCandidates,
|
|
197
|
+
bindingEntries,
|
|
198
|
+
metaTick,
|
|
199
|
+
getBindingAt,
|
|
200
|
+
resolveFieldLabel,
|
|
201
|
+
bindField,
|
|
202
|
+
patchActiveBinding,
|
|
203
|
+
startParentPick,
|
|
204
|
+
cancelParentPick,
|
|
205
|
+
pickParentAt,
|
|
206
|
+
clearParent,
|
|
207
|
+
removeActiveBinding,
|
|
208
|
+
resolveCellStyle,
|
|
209
|
+
resolveCellRenderer,
|
|
210
|
+
getTemplate
|
|
211
|
+
} = designer
|
|
212
|
+
|
|
213
|
+
const hubVisible = ref(false)
|
|
214
|
+
const rulesDialogVisible = ref(false)
|
|
215
|
+
|
|
216
|
+
const sheetRef = useTemplateRef<SheetExposed>('sheetRef')
|
|
217
|
+
const previewViewerRef = useTemplateRef<ReportViewerExposed>('previewViewerRef')
|
|
218
|
+
const gridHostRef = useTemplateRef<HTMLElement>('gridHostRef')
|
|
219
|
+
const gridHostEl = computed(() => gridHostRef.value ?? null)
|
|
220
|
+
|
|
221
|
+
/** 字段拖拽落点高亮(dragover 时更新;落空时 overlay 提示回退当前选区) */
|
|
222
|
+
const isFieldDragging = ref(false)
|
|
223
|
+
const dropTargetAddr = ref<CellAddress | null>(null)
|
|
224
|
+
|
|
225
|
+
function getDesignGrid(): SheetGrid | undefined {
|
|
226
|
+
return sheetRef.value?.getGrid()
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ---- 设计 / 预览模式切换(预览态内嵌查看器路径,issue 05) ----
|
|
230
|
+
|
|
231
|
+
type ViewMode = 'design' | 'preview'
|
|
232
|
+
|
|
233
|
+
const viewMode = ref<ViewMode>('design')
|
|
234
|
+
const isPreview = computed(() => viewMode.value === 'preview')
|
|
235
|
+
|
|
236
|
+
/** 进入预览时的模板快照(getTemplate 吐出,设计态工作簿不受预览取数影响,切回绑定不丢) */
|
|
237
|
+
const previewTemplate = shallowRef<ReportTemplate | null>(null)
|
|
238
|
+
/** 预览工作簿自持(XLSX 导出需要拿到填充后的 sheet,05 票 workbook? prop 先例) */
|
|
239
|
+
const previewWorkbook = new Workbook()
|
|
240
|
+
/** 当前设计态列宽(sheet-core 列宽未进快照,经 VTable 运行时捕获;导出随快照写宽) */
|
|
241
|
+
const designColWidths = ref<Array<[number, number]>>([])
|
|
242
|
+
const exporting = ref(false)
|
|
243
|
+
|
|
244
|
+
/** 从当前设计网格捕获列宽(网格未就绪则保留旧值) */
|
|
245
|
+
function captureDesignColWidths(): void {
|
|
246
|
+
const widths = readGridColWidths(
|
|
247
|
+
getDesignGrid(),
|
|
248
|
+
Array.from({ length: DESIGN_COLS }, (_, col) => col)
|
|
249
|
+
)
|
|
250
|
+
if (widths) designColWidths.value = widths
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** 设计网格重建后补刷新与列宽(restore 不发 content-reset 的场景由 grid 自行订阅,这里只管列宽) */
|
|
254
|
+
function syncDesignGridView(): void {
|
|
255
|
+
const grid = getDesignGrid()
|
|
256
|
+
grid?.flushPending()
|
|
257
|
+
grid?.refresh()
|
|
258
|
+
applyGridColWidths(grid, designColWidths.value)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function setViewMode(mode: ViewMode): void {
|
|
262
|
+
if (viewMode.value === mode) return
|
|
263
|
+
if (mode === 'preview') {
|
|
264
|
+
captureDesignColWidths()
|
|
265
|
+
previewTemplate.value = getTemplate()
|
|
266
|
+
}
|
|
267
|
+
viewMode.value = mode
|
|
268
|
+
if (mode === 'design') void nextTick(syncDesignGridView)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// 模板 prop 更换:组合式函数内完成载入;组件层切回设计态(预览内容随之作废)
|
|
272
|
+
watch(
|
|
273
|
+
() => props.template,
|
|
274
|
+
() => {
|
|
275
|
+
viewMode.value = 'design'
|
|
276
|
+
}
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
// 父格点选:网格选区变更时写入父格并回到源格
|
|
280
|
+
watch(activeCell, (cell) => {
|
|
281
|
+
if (cell && parentPick.value) pickParentAt(cell)
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
// 徽章文案依赖 catalog(describe 完成 / label 覆盖变更后重绘绑定格;meta 变更由 grid 自行订阅)
|
|
285
|
+
watch(catalog, () => {
|
|
286
|
+
void nextTick(() => getDesignGrid()?.refresh())
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
async function exportPreviewXlsx(): Promise<void> {
|
|
290
|
+
if (!isPreview.value || exporting.value) return
|
|
291
|
+
const viewer = previewViewerRef.value
|
|
292
|
+
if (!viewer) {
|
|
293
|
+
throw new Error('预览查看器尚未就绪,请稍后再导出')
|
|
294
|
+
}
|
|
295
|
+
exporting.value = true
|
|
296
|
+
try {
|
|
297
|
+
await viewer.exportXlsx()
|
|
298
|
+
} finally {
|
|
299
|
+
exporting.value = false
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function saveConditionalRules(rules: ConditionalRule[]): void {
|
|
304
|
+
patchActiveBinding({ conditionalRules: rules })
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function clearDropState(): void {
|
|
308
|
+
isFieldDragging.value = false
|
|
309
|
+
dropTargetAddr.value = null
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function resolveDropAddress(event: DragEvent): CellAddress | null {
|
|
313
|
+
const grid = getDesignGrid()
|
|
314
|
+
const gridEl = gridHostRef.value?.querySelector('.u-sheet__grid-instance') as HTMLElement | null
|
|
315
|
+
if (!grid || !gridEl) return null
|
|
316
|
+
return resolveGridDropAddress(grid, gridEl, event.clientX, event.clientY)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function onGridDragOver(event: DragEvent): void {
|
|
320
|
+
if (!event.dataTransfer?.types.includes(FIELD_DRAG_MIME)) return
|
|
321
|
+
event.preventDefault()
|
|
322
|
+
event.dataTransfer.dropEffect = 'copy'
|
|
323
|
+
isFieldDragging.value = true
|
|
324
|
+
dropTargetAddr.value = resolveDropAddress(event)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function onGridDragLeave(event: DragEvent): void {
|
|
328
|
+
const host = gridHostRef.value
|
|
329
|
+
const related = event.relatedTarget
|
|
330
|
+
if (host && related instanceof Node && host.contains(related)) return
|
|
331
|
+
clearDropState()
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function onGridDrop(event: DragEvent): void {
|
|
335
|
+
event.preventDefault()
|
|
336
|
+
clearDropState()
|
|
337
|
+
const raw = event.dataTransfer?.getData(FIELD_DRAG_MIME)
|
|
338
|
+
const payload = raw ? parseFieldDragPayload(raw) : null
|
|
339
|
+
if (!payload) return
|
|
340
|
+
|
|
341
|
+
// 与旧设计器一致:网格未就绪直接放弃;仅 hit-test 落空时回退当前选区
|
|
342
|
+
const grid = getDesignGrid()
|
|
343
|
+
const gridEl = gridHostRef.value?.querySelector('.u-sheet__grid-instance') as HTMLElement | null
|
|
344
|
+
if (!grid || !gridEl) return
|
|
345
|
+
|
|
346
|
+
const dropAddr = resolveDropAddress(event)
|
|
347
|
+
if (dropAddr) {
|
|
348
|
+
bindField(payload.datasetId, payload.fieldName, dropAddr)
|
|
349
|
+
sheetRef.value?.getContext().selectCell(dropAddr)
|
|
350
|
+
} else {
|
|
351
|
+
bindField(payload.datasetId, payload.fieldName)
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
defineExpose<_ReportDesignerExposed>({ getTemplate })
|
|
356
|
+
</script>
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="cls.b">
|
|
3
|
+
<u-report-filter-bar
|
|
4
|
+
v-if="params.length"
|
|
5
|
+
:query-params="params"
|
|
6
|
+
:values="values"
|
|
7
|
+
@update:values="setValues"
|
|
8
|
+
/>
|
|
9
|
+
|
|
10
|
+
<div :class="cls.e('body')">
|
|
11
|
+
<div v-if="loading" :class="cls.e('loading')" aria-live="polite">
|
|
12
|
+
<div :class="cls.e('loading-spinner')" />
|
|
13
|
+
<span>正在加载报表数据…</span>
|
|
14
|
+
</div>
|
|
15
|
+
<div v-else-if="error" :class="cls.e('error')" role="alert">
|
|
16
|
+
{{ error.message }}
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<u-sheet
|
|
20
|
+
ref="sheetRef"
|
|
21
|
+
:class="cls.e('sheet')"
|
|
22
|
+
:workbook="workbook"
|
|
23
|
+
:rows="renderRows"
|
|
24
|
+
:cols="renderCols"
|
|
25
|
+
:show-toolbar="false"
|
|
26
|
+
:show-formula-bar="false"
|
|
27
|
+
:show-tabs="false"
|
|
28
|
+
readonly
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script lang="ts" setup>
|
|
35
|
+
import { saveBlob } from '@cat-kit/fe'
|
|
36
|
+
import type { SheetSnapshot } from '@veltra/sheet-core'
|
|
37
|
+
import { Workbook } from '@veltra/sheet-core'
|
|
38
|
+
import { bem } from '@veltra/utils'
|
|
39
|
+
import { computed, nextTick, useTemplateRef, watch } from 'vue'
|
|
40
|
+
|
|
41
|
+
import { exportFilledReportXlsx } from '../../report/export-xlsx'
|
|
42
|
+
import type { ReportViewerProps, _ReportViewerExposed } from '../../types'
|
|
43
|
+
import type { SheetExposed } from '../../types'
|
|
44
|
+
import { USheet } from '../sheet'
|
|
45
|
+
import { applyGridColWidths, readGridColWidths } from './designer/col-widths'
|
|
46
|
+
import UReportFilterBar from './filter-bar.vue'
|
|
47
|
+
import { useReportViewer } from './use-report-viewer'
|
|
48
|
+
|
|
49
|
+
defineOptions({ name: 'UReportViewer' })
|
|
50
|
+
|
|
51
|
+
const props = defineProps<ReportViewerProps>()
|
|
52
|
+
|
|
53
|
+
const cls = bem('report-viewer')
|
|
54
|
+
|
|
55
|
+
/** 网格最小渲染尺寸(与 playground 预览态一致);Filled Report 超出时按快照尺寸放大 */
|
|
56
|
+
const MIN_RENDER_ROWS = 50
|
|
57
|
+
const MIN_RENDER_COLS = 10
|
|
58
|
+
|
|
59
|
+
/** 取数未完成时拒绝导出的可读错误 */
|
|
60
|
+
const EXPORT_NOT_READY_MESSAGE = '报表数据尚未就绪,请等待取数完成后再导出'
|
|
61
|
+
const EXPORT_LOADING_MESSAGE = '报表数据加载中,请稍后再导出'
|
|
62
|
+
|
|
63
|
+
/** 查看器工作簿:宿主可注入(同 USheet `workbook?` 先例),缺省内部自建;模板 / 填充结果都 restore 进活动 sheet 只读展示 */
|
|
64
|
+
const internalWorkbook = new Workbook()
|
|
65
|
+
const workbook = computed(() => props.workbook ?? internalWorkbook)
|
|
66
|
+
|
|
67
|
+
const sheetRef = useTemplateRef<SheetExposed>('sheetRef')
|
|
68
|
+
|
|
69
|
+
const { params, values, loading, error, filledSnapshot, refresh, setValues } =
|
|
70
|
+
useReportViewer(props)
|
|
71
|
+
|
|
72
|
+
const renderRows = computed(() =>
|
|
73
|
+
Math.max(MIN_RENDER_ROWS, filledSnapshot.value?.rows ?? 0, props.template.rows)
|
|
74
|
+
)
|
|
75
|
+
const renderCols = computed(() =>
|
|
76
|
+
Math.max(MIN_RENDER_COLS, filledSnapshot.value?.cols ?? 0, props.template.cols)
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
function exportColIndexes(): number[] {
|
|
80
|
+
return Array.from({ length: renderCols.value }, (_, col) => col)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 将宿主传入的列宽写入 VTable 运行时(sheet-core 列宽未进快照) */
|
|
84
|
+
function applyRuntimeColWidths(): void {
|
|
85
|
+
if (!props.colWidths?.length) return
|
|
86
|
+
applyGridColWidths(sheetRef.value?.getGrid(), props.colWidths)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* restore 负责尺寸/冻结/行高/选区(静默),restoreContent 发 content-reset
|
|
91
|
+
* 触发网格全量刷新(grid 层订阅直刷,无需手动 flush);history.clear 使填充不进 undo
|
|
92
|
+
*/
|
|
93
|
+
function applySnapshot(snapshot: SheetSnapshot): void {
|
|
94
|
+
const sheet = workbook.value.activeSheet
|
|
95
|
+
sheet.restore(snapshot)
|
|
96
|
+
sheet.restoreContent(snapshot)
|
|
97
|
+
sheet.history.clear()
|
|
98
|
+
void nextTick(applyRuntimeColWidths)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 先铺模板静态结构(取数期间 / 取数失败时可见),取数成功后替换为 Filled Report
|
|
102
|
+
watch(() => props.template, applySnapshot, { immediate: true })
|
|
103
|
+
watch(filledSnapshot, (filled) => {
|
|
104
|
+
if (filled) applySnapshot(filled)
|
|
105
|
+
})
|
|
106
|
+
watch(() => props.colWidths, applyRuntimeColWidths)
|
|
107
|
+
|
|
108
|
+
async function exportXlsx(): Promise<void> {
|
|
109
|
+
if (loading.value) {
|
|
110
|
+
throw new Error(EXPORT_LOADING_MESSAGE)
|
|
111
|
+
}
|
|
112
|
+
if (!filledSnapshot.value) {
|
|
113
|
+
throw new Error(EXPORT_NOT_READY_MESSAGE)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const sheet = workbook.value.activeSheet
|
|
117
|
+
const colWidths = readGridColWidths(sheetRef.value?.getGrid(), exportColIndexes()) ?? []
|
|
118
|
+
const buffer = await exportFilledReportXlsx(sheet, colWidths)
|
|
119
|
+
saveBlob(
|
|
120
|
+
new Blob([buffer as unknown as BlobPart], {
|
|
121
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
122
|
+
}),
|
|
123
|
+
`${sheet.name || '报表'}.xlsx`
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
defineExpose<_ReportViewerExposed>({ refresh, exportXlsx })
|
|
128
|
+
</script>
|