@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,252 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="cls.b">
|
|
3
|
+
<span :class="cls.e('handle')" title="拖拽排序">⋮⋮</span>
|
|
4
|
+
|
|
5
|
+
<div :class="cls.e('main')">
|
|
6
|
+
<div :class="cls.e('when')">
|
|
7
|
+
<span :class="cls.e('lead')">当</span>
|
|
8
|
+
<u-select
|
|
9
|
+
size="small"
|
|
10
|
+
:class="cls.e('field-select')"
|
|
11
|
+
:model-value="rule.field ?? SELF_FIELD_VALUE"
|
|
12
|
+
:options="fieldOptions"
|
|
13
|
+
@update:model-value="onEvalField"
|
|
14
|
+
/>
|
|
15
|
+
<u-select
|
|
16
|
+
size="small"
|
|
17
|
+
:class="cls.e('operator')"
|
|
18
|
+
:model-value="rule.operator"
|
|
19
|
+
:options="operatorOptions"
|
|
20
|
+
@update:model-value="onOperator"
|
|
21
|
+
/>
|
|
22
|
+
<div :class="cls.e('value')">
|
|
23
|
+
<template v-if="rule.operator === 'between'">
|
|
24
|
+
<u-number-input
|
|
25
|
+
v-if="numericField"
|
|
26
|
+
size="small"
|
|
27
|
+
:class="cls.e('between-input')"
|
|
28
|
+
:model-value="betweenStart as number"
|
|
29
|
+
@update:model-value="(v) => patchBetween(0, v ?? 0)"
|
|
30
|
+
/>
|
|
31
|
+
<u-input
|
|
32
|
+
v-else
|
|
33
|
+
size="small"
|
|
34
|
+
:class="cls.e('between-input')"
|
|
35
|
+
:model-value="String(betweenStart)"
|
|
36
|
+
@update:model-value="(v) => patchBetween(0, String(v ?? ''))"
|
|
37
|
+
/>
|
|
38
|
+
<span :class="cls.e('between-sep')">至</span>
|
|
39
|
+
<u-number-input
|
|
40
|
+
v-if="numericField"
|
|
41
|
+
size="small"
|
|
42
|
+
:class="cls.e('between-input')"
|
|
43
|
+
:model-value="betweenEnd as number"
|
|
44
|
+
@update:model-value="(v) => patchBetween(1, v ?? 0)"
|
|
45
|
+
/>
|
|
46
|
+
<u-input
|
|
47
|
+
v-else
|
|
48
|
+
size="small"
|
|
49
|
+
:class="cls.e('between-input')"
|
|
50
|
+
:model-value="String(betweenEnd)"
|
|
51
|
+
@update:model-value="(v) => patchBetween(1, String(v ?? ''))"
|
|
52
|
+
/>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<u-input
|
|
56
|
+
v-else-if="rule.operator === 'contains' || (!numericField && rule.operator === 'eq')"
|
|
57
|
+
size="small"
|
|
58
|
+
:class="cls.e('scalar-input')"
|
|
59
|
+
:model-value="String(rule.value ?? '')"
|
|
60
|
+
placeholder="比较值"
|
|
61
|
+
@update:model-value="(v) => patchValue(String(v ?? ''))"
|
|
62
|
+
/>
|
|
63
|
+
|
|
64
|
+
<u-number-input
|
|
65
|
+
v-else
|
|
66
|
+
size="small"
|
|
67
|
+
:class="cls.e('scalar-input')"
|
|
68
|
+
:model-value="scalarNumber"
|
|
69
|
+
@update:model-value="(v) => patchValue(v ?? 0)"
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
<span :class="cls.e('lead')">时</span>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div :class="cls.e('then')">
|
|
76
|
+
<span :class="cls.e('lead')">样式</span>
|
|
77
|
+
<span title="背景">
|
|
78
|
+
<u-palette
|
|
79
|
+
size="small"
|
|
80
|
+
:model-value="rule.style.fill?.color ?? ''"
|
|
81
|
+
@update:model-value="patchFillColor"
|
|
82
|
+
/>
|
|
83
|
+
</span>
|
|
84
|
+
<span title="文字">
|
|
85
|
+
<u-palette
|
|
86
|
+
size="small"
|
|
87
|
+
:model-value="rule.style.font?.color ?? ''"
|
|
88
|
+
@update:model-value="patchFontColor"
|
|
89
|
+
/>
|
|
90
|
+
</span>
|
|
91
|
+
<u-button-group>
|
|
92
|
+
<u-button
|
|
93
|
+
size="small"
|
|
94
|
+
:class="cls.e('toggle')"
|
|
95
|
+
:type="rule.style.font?.bold ? 'primary' : undefined"
|
|
96
|
+
plain
|
|
97
|
+
title="加粗"
|
|
98
|
+
@click="toggleBold"
|
|
99
|
+
>
|
|
100
|
+
B
|
|
101
|
+
</u-button>
|
|
102
|
+
<u-button
|
|
103
|
+
size="small"
|
|
104
|
+
:class="cls.e('toggle')"
|
|
105
|
+
:type="rule.style.font?.italic ? 'primary' : undefined"
|
|
106
|
+
plain
|
|
107
|
+
title="斜体"
|
|
108
|
+
@click="toggleItalic"
|
|
109
|
+
>
|
|
110
|
+
I
|
|
111
|
+
</u-button>
|
|
112
|
+
</u-button-group>
|
|
113
|
+
<u-report-rule-preview :class="cls.e('preview')" :rule="rule" />
|
|
114
|
+
|
|
115
|
+
<span :class="cls.e('lead')">应用到</span>
|
|
116
|
+
<u-button-group>
|
|
117
|
+
<u-button
|
|
118
|
+
v-for="option in RULE_SCOPE_OPTIONS"
|
|
119
|
+
:key="option.value"
|
|
120
|
+
size="small"
|
|
121
|
+
plain
|
|
122
|
+
:type="(rule.scope ?? 'cell') === option.value ? 'primary' : undefined"
|
|
123
|
+
:title="
|
|
124
|
+
option.value === 'row' ? '染满物理输出行(交叉表会盖住同行所有列)' : '只改本格'
|
|
125
|
+
"
|
|
126
|
+
@click="onScope(option.value)"
|
|
127
|
+
>
|
|
128
|
+
{{ option.label }}
|
|
129
|
+
</u-button>
|
|
130
|
+
</u-button-group>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<u-button size="small" text type="danger" :class="cls.e('remove')" @click="emit('remove')">
|
|
135
|
+
删除
|
|
136
|
+
</u-button>
|
|
137
|
+
</div>
|
|
138
|
+
</template>
|
|
139
|
+
|
|
140
|
+
<script lang="ts" setup>
|
|
141
|
+
import { UButton, UButtonGroup, UInput, UNumberInput, UPalette, USelect } from '@veltra/desktop'
|
|
142
|
+
import { bem } from '@veltra/utils'
|
|
143
|
+
import { computed } from 'vue'
|
|
144
|
+
|
|
145
|
+
import type { ConditionalOperator, ConditionalRule, DatasetField } from '../../../report/types'
|
|
146
|
+
import {
|
|
147
|
+
coerceValueForOperator,
|
|
148
|
+
isNumericFieldType,
|
|
149
|
+
operatorsForFieldType,
|
|
150
|
+
readBetweenValue,
|
|
151
|
+
resolveEvalFieldType,
|
|
152
|
+
RULE_SCOPE_OPTIONS,
|
|
153
|
+
ruleEvalFieldOptions,
|
|
154
|
+
SELF_FIELD_VALUE,
|
|
155
|
+
writeBetweenValue
|
|
156
|
+
} from './conditional-rules/helpers'
|
|
157
|
+
import UReportRulePreview from './rule-preview.vue'
|
|
158
|
+
|
|
159
|
+
defineOptions({ name: 'UReportRuleRow' })
|
|
160
|
+
|
|
161
|
+
const props = defineProps<{
|
|
162
|
+
rule: ConditionalRule
|
|
163
|
+
bindingField: string
|
|
164
|
+
datasetFields: readonly DatasetField[]
|
|
165
|
+
}>()
|
|
166
|
+
|
|
167
|
+
const emit = defineEmits<{ 'update:rule': [rule: ConditionalRule]; remove: [] }>()
|
|
168
|
+
|
|
169
|
+
const cls = bem('report-rule-row')
|
|
170
|
+
|
|
171
|
+
const evalFieldType = computed(() =>
|
|
172
|
+
resolveEvalFieldType(props.rule, props.bindingField, props.datasetFields)
|
|
173
|
+
)
|
|
174
|
+
const operatorOptions = computed(() => operatorsForFieldType(evalFieldType.value))
|
|
175
|
+
const numericField = computed(() => isNumericFieldType(evalFieldType.value))
|
|
176
|
+
const fieldOptions = computed(() => ruleEvalFieldOptions(props.bindingField, props.datasetFields))
|
|
177
|
+
|
|
178
|
+
const betweenStart = computed(() => readBetweenValue(props.rule.value, 0, evalFieldType.value))
|
|
179
|
+
const betweenEnd = computed(() => readBetweenValue(props.rule.value, 1, evalFieldType.value))
|
|
180
|
+
|
|
181
|
+
const scalarNumber = computed((): number => {
|
|
182
|
+
const raw = props.rule.value
|
|
183
|
+
if (typeof raw === 'number' && Number.isFinite(raw)) return raw
|
|
184
|
+
const parsed = Number(raw)
|
|
185
|
+
return Number.isFinite(parsed) ? parsed : 0
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
function patchRule(patch: Partial<ConditionalRule>): void {
|
|
189
|
+
emit('update:rule', { ...props.rule, ...patch })
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function onEvalField(field: string | undefined): void {
|
|
193
|
+
const next: Partial<ConditionalRule> = {}
|
|
194
|
+
if (!field) {
|
|
195
|
+
next.field = undefined
|
|
196
|
+
} else {
|
|
197
|
+
next.field = field
|
|
198
|
+
}
|
|
199
|
+
const nextType = resolveEvalFieldType(
|
|
200
|
+
{ ...props.rule, ...next },
|
|
201
|
+
props.bindingField,
|
|
202
|
+
props.datasetFields
|
|
203
|
+
)
|
|
204
|
+
const operator = operatorsForFieldType(nextType)[0]?.value ?? props.rule.operator
|
|
205
|
+
next.operator = operator
|
|
206
|
+
next.value = coerceValueForOperator(operator, nextType, props.rule.value)
|
|
207
|
+
patchRule(next)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function onScope(scope: 'cell' | 'row'): void {
|
|
211
|
+
patchRule({ scope: scope === 'cell' ? undefined : scope })
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function onOperator(operator: ConditionalOperator): void {
|
|
215
|
+
patchRule({
|
|
216
|
+
operator,
|
|
217
|
+
value: coerceValueForOperator(operator, evalFieldType.value, props.rule.value)
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function patchValue(value: unknown): void {
|
|
222
|
+
patchRule({ value })
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function patchBetween(index: 0 | 1, next: number | string): void {
|
|
226
|
+
patchRule({ value: writeBetweenValue(props.rule.value, index, next, evalFieldType.value) })
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function patchFillColor(color: string): void {
|
|
230
|
+
patchRule({ style: { ...props.rule.style, fill: color ? { color } : undefined } })
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function patchFontColor(color: string): void {
|
|
234
|
+
patchRule({
|
|
235
|
+
style: { ...props.rule.style, font: { ...props.rule.style.font, color: color || undefined } }
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function toggleBold(): void {
|
|
240
|
+
const bold = !props.rule.style.font?.bold
|
|
241
|
+
patchRule({
|
|
242
|
+
style: { ...props.rule.style, font: { ...props.rule.style.font, bold: bold || undefined } }
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function toggleItalic(): void {
|
|
247
|
+
const italic = !props.rule.style.font?.italic
|
|
248
|
+
patchRule({
|
|
249
|
+
style: { ...props.rule.style, font: { ...props.rule.style.font, italic: italic || undefined } }
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
</script>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<u-dialog
|
|
3
|
+
v-model="visible"
|
|
4
|
+
title="条件样式"
|
|
5
|
+
style="width: min(600px, 92vw); max-height: 85vh"
|
|
6
|
+
@close="onClose"
|
|
7
|
+
>
|
|
8
|
+
<div :class="cls.b">
|
|
9
|
+
<p :class="cls.e('hint')">规则按顺序叠加。整行高亮适合明细表,交叉表会染满整行。</p>
|
|
10
|
+
|
|
11
|
+
<ul v-if="draftItems.length" ref="parentRef" :class="cls.e('list')">
|
|
12
|
+
<li v-for="(item, index) in draftItems" :key="item.id" :class="cls.e('item')">
|
|
13
|
+
<u-report-rule-row
|
|
14
|
+
:rule="item.rule"
|
|
15
|
+
:binding-field="bindingField"
|
|
16
|
+
:dataset-fields="datasetFields"
|
|
17
|
+
@update:rule="item.rule = $event"
|
|
18
|
+
@remove="removeRule(index)"
|
|
19
|
+
/>
|
|
20
|
+
</li>
|
|
21
|
+
</ul>
|
|
22
|
+
<p v-else :class="cls.e('empty')">还没有规则。</p>
|
|
23
|
+
|
|
24
|
+
<u-button size="small" plain @click="addRule">添加规则</u-button>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<template #footer>
|
|
28
|
+
<u-button size="small" @click="visible = false">取消</u-button>
|
|
29
|
+
<u-button size="small" type="primary" @click="confirm">确定</u-button>
|
|
30
|
+
</template>
|
|
31
|
+
</u-dialog>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script lang="ts" setup>
|
|
35
|
+
import { animations, useDnD } from '@veltra/compositions'
|
|
36
|
+
import { UButton, UDialog } from '@veltra/desktop'
|
|
37
|
+
import { bem } from '@veltra/utils'
|
|
38
|
+
import { computed, ref, watch } from 'vue'
|
|
39
|
+
|
|
40
|
+
import type { ConditionalRule, DatasetField } from '../../../report/types'
|
|
41
|
+
import {
|
|
42
|
+
cloneRulesFromDraft,
|
|
43
|
+
createDraftItem,
|
|
44
|
+
initDraftFromRules,
|
|
45
|
+
type DraftRuleItem
|
|
46
|
+
} from './conditional-rules/helpers'
|
|
47
|
+
import UReportRuleRow from './rule-row.vue'
|
|
48
|
+
|
|
49
|
+
defineOptions({ name: 'UReportRulesDialog' })
|
|
50
|
+
|
|
51
|
+
const props = withDefaults(
|
|
52
|
+
defineProps<{
|
|
53
|
+
modelValue: boolean
|
|
54
|
+
rules: ConditionalRule[]
|
|
55
|
+
bindingField: string
|
|
56
|
+
datasetFields?: readonly DatasetField[]
|
|
57
|
+
/** @deprecated 使用 datasetFields + resolveEvalFieldType */
|
|
58
|
+
fieldType?: DatasetField['type']
|
|
59
|
+
}>(),
|
|
60
|
+
{ datasetFields: () => [], fieldType: 'number' }
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
const emit = defineEmits<{
|
|
64
|
+
'update:modelValue': [value: boolean]
|
|
65
|
+
save: [rules: ConditionalRule[]]
|
|
66
|
+
}>()
|
|
67
|
+
|
|
68
|
+
const cls = bem('report-rules-dialog')
|
|
69
|
+
|
|
70
|
+
const draftItems = ref<DraftRuleItem[]>([])
|
|
71
|
+
|
|
72
|
+
const { parentRef } = useDnD<DraftRuleItem>({
|
|
73
|
+
values: draftItems,
|
|
74
|
+
dragHandle: '.u-report-rule-row__handle',
|
|
75
|
+
plugins: [animations()]
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const visible = computed({
|
|
79
|
+
get: () => props.modelValue,
|
|
80
|
+
set: (value: boolean) => emit('update:modelValue', value)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
watch(
|
|
84
|
+
() => props.modelValue,
|
|
85
|
+
(open) => {
|
|
86
|
+
if (!open) return
|
|
87
|
+
draftItems.value = initDraftFromRules(props.rules, props.fieldType, props.bindingField)
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
function addRule(): void {
|
|
92
|
+
draftItems.value = [
|
|
93
|
+
...draftItems.value,
|
|
94
|
+
createDraftItem(undefined, props.fieldType, props.bindingField)
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function removeRule(index: number): void {
|
|
99
|
+
draftItems.value = draftItems.value.filter((_, i) => i !== index)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function confirm(): void {
|
|
103
|
+
emit('save', cloneRulesFromDraft(draftItems.value))
|
|
104
|
+
visible.value = false
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function onClose(): void {
|
|
108
|
+
visible.value = false
|
|
109
|
+
}
|
|
110
|
+
</script>
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<svg v-if="visible" :class="cls.b" :width="svgWidth" :height="svgHeight" aria-hidden="true">
|
|
3
|
+
<defs>
|
|
4
|
+
<marker
|
|
5
|
+
:id="rowArrowMarkerId"
|
|
6
|
+
markerWidth="8"
|
|
7
|
+
markerHeight="8"
|
|
8
|
+
refX="6"
|
|
9
|
+
refY="4"
|
|
10
|
+
orient="auto"
|
|
11
|
+
markerUnits="strokeWidth"
|
|
12
|
+
>
|
|
13
|
+
<path d="M0,0 L8,4 L0,8 Z" fill="var(--u-color-primary, #2563eb)" />
|
|
14
|
+
</marker>
|
|
15
|
+
<marker
|
|
16
|
+
:id="colArrowMarkerId"
|
|
17
|
+
markerWidth="8"
|
|
18
|
+
markerHeight="8"
|
|
19
|
+
refX="6"
|
|
20
|
+
refY="4"
|
|
21
|
+
orient="auto"
|
|
22
|
+
markerUnits="strokeWidth"
|
|
23
|
+
>
|
|
24
|
+
<path d="M0,0 L8,4 L0,8 Z" fill="var(--u-color-warning, #d97706)" />
|
|
25
|
+
</marker>
|
|
26
|
+
</defs>
|
|
27
|
+
<path
|
|
28
|
+
v-for="(item, index) in arcPaths"
|
|
29
|
+
:key="index"
|
|
30
|
+
:class="[cls.e('arc'), cls.em('arc', item.direction)]"
|
|
31
|
+
:d="item.path"
|
|
32
|
+
:marker-end="`url(#${item.direction === 'row' ? rowArrowMarkerId : colArrowMarkerId})`"
|
|
33
|
+
/>
|
|
34
|
+
</svg>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script lang="ts" setup>
|
|
38
|
+
import type { CellAddress, SheetGrid } from '@veltra/sheet-core'
|
|
39
|
+
import { bem } from '@veltra/utils'
|
|
40
|
+
import { computed, ref, toRef } from 'vue'
|
|
41
|
+
|
|
42
|
+
import type { ReportBinding } from '../../../report/types'
|
|
43
|
+
import {
|
|
44
|
+
buildTopologyArcPath,
|
|
45
|
+
collectTopologyLinks,
|
|
46
|
+
type TopologyBindingEntry,
|
|
47
|
+
type TopologyLinkDirection
|
|
48
|
+
} from './topology'
|
|
49
|
+
import { readCellOverlayRect, readGridOverlaySize, useGridOverlaySync } from './use-grid-overlay'
|
|
50
|
+
|
|
51
|
+
defineOptions({ name: 'UReportTopologyOverlay' })
|
|
52
|
+
|
|
53
|
+
const props = defineProps<{
|
|
54
|
+
cell: CellAddress | null
|
|
55
|
+
binding: ReportBinding | null
|
|
56
|
+
entries: TopologyBindingEntry[]
|
|
57
|
+
metaTick: number
|
|
58
|
+
hostEl: HTMLElement | null
|
|
59
|
+
getGrid: () => SheetGrid | undefined
|
|
60
|
+
getBindingAt: (addr: CellAddress) => ReportBinding | undefined
|
|
61
|
+
}>()
|
|
62
|
+
|
|
63
|
+
const cls = bem('report-topology')
|
|
64
|
+
|
|
65
|
+
const instanceId = Math.random().toString(36).slice(2, 8)
|
|
66
|
+
const rowArrowMarkerId = `u-report-topology-row-arrow-${instanceId}`
|
|
67
|
+
const colArrowMarkerId = `u-report-topology-col-arrow-${instanceId}`
|
|
68
|
+
|
|
69
|
+
const hostEl = toRef(props, 'hostEl')
|
|
70
|
+
|
|
71
|
+
const svgWidth = ref(0)
|
|
72
|
+
const svgHeight = ref(0)
|
|
73
|
+
const arcPaths = ref<Array<{ path: string; direction: TopologyLinkDirection }>>([])
|
|
74
|
+
const inView = ref(false)
|
|
75
|
+
|
|
76
|
+
const visible = computed(
|
|
77
|
+
() => !!props.binding && !!props.cell && inView.value && arcPaths.value.length > 0
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
function updateOverlay(): void {
|
|
81
|
+
const cell = props.cell
|
|
82
|
+
const binding = props.binding
|
|
83
|
+
const host = props.hostEl
|
|
84
|
+
if (!cell || !binding || !host) {
|
|
85
|
+
inView.value = false
|
|
86
|
+
arcPaths.value = []
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const size = readGridOverlaySize(host)
|
|
91
|
+
if (!size) {
|
|
92
|
+
inView.value = false
|
|
93
|
+
arcPaths.value = []
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
svgWidth.value = size.width
|
|
98
|
+
svgHeight.value = size.height
|
|
99
|
+
|
|
100
|
+
const links = collectTopologyLinks(cell, binding, props.entries, props.getBindingAt)
|
|
101
|
+
const paths: Array<{ path: string; direction: TopologyLinkDirection }> = []
|
|
102
|
+
|
|
103
|
+
for (const link of links) {
|
|
104
|
+
const fromRect = readCellOverlayRect(link.from, host, props.getGrid)
|
|
105
|
+
const toRect = readCellOverlayRect(link.to, host, props.getGrid)
|
|
106
|
+
if (!fromRect || !toRect) continue
|
|
107
|
+
paths.push({
|
|
108
|
+
direction: link.direction,
|
|
109
|
+
path: buildTopologyArcPath(
|
|
110
|
+
{ x: fromRect.centerX, y: fromRect.centerY },
|
|
111
|
+
{ x: toRect.centerX, y: toRect.centerY }
|
|
112
|
+
)
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
arcPaths.value = paths
|
|
117
|
+
inView.value = paths.length > 0
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
useGridOverlaySync({
|
|
121
|
+
hostEl,
|
|
122
|
+
getGrid: () => props.getGrid(),
|
|
123
|
+
watchSources: () =>
|
|
124
|
+
[props.cell?.row, props.cell?.col, props.binding, props.metaTick, props.hostEl] as const,
|
|
125
|
+
update: updateOverlay
|
|
126
|
+
})
|
|
127
|
+
</script>
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { CellAddress } from '@veltra/sheet-core'
|
|
2
|
+
|
|
3
|
+
import type { ReportBinding } from '../../../report/types'
|
|
4
|
+
|
|
5
|
+
export type TopologyLinkDirection = 'row' | 'col'
|
|
6
|
+
|
|
7
|
+
export interface TopologyLink {
|
|
8
|
+
/** 子格(依赖方) */
|
|
9
|
+
from: CellAddress
|
|
10
|
+
/** 父绑定格 */
|
|
11
|
+
to: CellAddress
|
|
12
|
+
/** 连线方向:行方向父格 / 列方向父格 */
|
|
13
|
+
direction: TopologyLinkDirection
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TopologyBindingEntry {
|
|
17
|
+
addr: CellAddress
|
|
18
|
+
binding: ReportBinding
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function linkKey(from: CellAddress, to: CellAddress, direction: TopologyLinkDirection): string {
|
|
22
|
+
return `${direction}:${from.row},${from.col}->${to.row},${to.col}`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function sameAddress(a: CellAddress, b: CellAddress): boolean {
|
|
26
|
+
return a.row === b.row && a.col === b.col
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pushLink(
|
|
30
|
+
links: TopologyLink[],
|
|
31
|
+
seen: Set<string>,
|
|
32
|
+
from: CellAddress,
|
|
33
|
+
to: CellAddress,
|
|
34
|
+
direction: TopologyLinkDirection
|
|
35
|
+
): void {
|
|
36
|
+
const key = linkKey(from, to, direction)
|
|
37
|
+
if (seen.has(key)) return
|
|
38
|
+
links.push({ from, to, direction })
|
|
39
|
+
seen.add(key)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 查找将指定格作为行方向父格的绑定格 */
|
|
43
|
+
export function findCellsWithRowParent(
|
|
44
|
+
parent: CellAddress,
|
|
45
|
+
entries: readonly TopologyBindingEntry[]
|
|
46
|
+
): CellAddress[] {
|
|
47
|
+
const children: CellAddress[] = []
|
|
48
|
+
for (const { addr, binding } of entries) {
|
|
49
|
+
if (binding.rowParent && sameAddress(binding.rowParent, parent)) {
|
|
50
|
+
children.push(addr)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return children
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 查找将指定格作为列方向父格的绑定格 */
|
|
57
|
+
export function findCellsWithColParent(
|
|
58
|
+
parent: CellAddress,
|
|
59
|
+
entries: readonly TopologyBindingEntry[]
|
|
60
|
+
): CellAddress[] {
|
|
61
|
+
const children: CellAddress[] = []
|
|
62
|
+
for (const { addr, binding } of entries) {
|
|
63
|
+
if (binding.colParent && sameAddress(binding.colParent, parent)) {
|
|
64
|
+
children.push(addr)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return children
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 收集选中格相关的拓扑连线:沿 rowParent / colParent 链上行、下行到直接子绑定 */
|
|
71
|
+
export function collectTopologyLinks(
|
|
72
|
+
cell: CellAddress,
|
|
73
|
+
binding: ReportBinding,
|
|
74
|
+
entries: readonly TopologyBindingEntry[],
|
|
75
|
+
getBindingAt: (addr: CellAddress) => ReportBinding | undefined
|
|
76
|
+
): TopologyLink[] {
|
|
77
|
+
const links: TopologyLink[] = []
|
|
78
|
+
const seen = new Set<string>()
|
|
79
|
+
|
|
80
|
+
let rowCursor = cell
|
|
81
|
+
let rowBinding: ReportBinding | undefined = binding
|
|
82
|
+
while (rowBinding?.rowParent) {
|
|
83
|
+
const parent = rowBinding.rowParent
|
|
84
|
+
pushLink(links, seen, rowCursor, parent, 'row')
|
|
85
|
+
rowCursor = parent
|
|
86
|
+
rowBinding = getBindingAt(parent)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let colCursor = cell
|
|
90
|
+
let colBinding: ReportBinding | undefined = binding
|
|
91
|
+
while (colBinding?.colParent) {
|
|
92
|
+
const parent = colBinding.colParent
|
|
93
|
+
pushLink(links, seen, colCursor, parent, 'col')
|
|
94
|
+
colCursor = parent
|
|
95
|
+
colBinding = getBindingAt(parent)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (const child of findCellsWithRowParent(cell, entries)) {
|
|
99
|
+
pushLink(links, seen, child, cell, 'row')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (const child of findCellsWithColParent(cell, entries)) {
|
|
103
|
+
pushLink(links, seen, child, cell, 'col')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return links
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** @deprecated 05 将删除;暂保留别名 */
|
|
110
|
+
export const findCellsWithLeftParent = findCellsWithRowParent
|
|
111
|
+
|
|
112
|
+
/** 子格 → 父格的二次贝塞尔弧线路径 */
|
|
113
|
+
export function buildTopologyArcPath(
|
|
114
|
+
from: { x: number; y: number },
|
|
115
|
+
to: { x: number; y: number }
|
|
116
|
+
): string {
|
|
117
|
+
const dx = to.x - from.x
|
|
118
|
+
const dy = to.y - from.y
|
|
119
|
+
const distance = Math.hypot(dx, dy) || 1
|
|
120
|
+
const lift = Math.min(48, Math.max(16, distance * 0.35))
|
|
121
|
+
const cx = (from.x + to.x) / 2
|
|
122
|
+
const cy = (from.y + to.y) / 2 - lift * Math.sign(dy || -1)
|
|
123
|
+
return `M ${from.x} ${from.y} Q ${cx} ${cy} ${to.x} ${to.y}`
|
|
124
|
+
}
|