@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,369 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<section v-if="dataset" :class="cls.b">
|
|
3
|
+
<div :class="cls.e('head')">
|
|
4
|
+
<div :class="cls.e('rename')">
|
|
5
|
+
<span :class="cls.e('label')">数据集名称</span>
|
|
6
|
+
<u-input
|
|
7
|
+
:model-value="dataset.label"
|
|
8
|
+
size="small"
|
|
9
|
+
@update:model-value="(v) => patchDataset({ label: String(v ?? '') })"
|
|
10
|
+
/>
|
|
11
|
+
</div>
|
|
12
|
+
<u-pop-confirm title="确定删除该数据集?" @confirm="emit('remove')">
|
|
13
|
+
<template #reference>
|
|
14
|
+
<u-button size="small" type="danger" plain>删除数据集</u-button>
|
|
15
|
+
</template>
|
|
16
|
+
</u-pop-confirm>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div :class="cls.e('sql')">
|
|
20
|
+
<p :class="cls.e('section-title')">SQL 查询</p>
|
|
21
|
+
<u-code-editor
|
|
22
|
+
v-model="sqlDraft"
|
|
23
|
+
lang="sql"
|
|
24
|
+
:langs="['sql']"
|
|
25
|
+
:default-lines="6"
|
|
26
|
+
@change="onSqlChange"
|
|
27
|
+
/>
|
|
28
|
+
<p v-if="describeError" :class="cls.e('sql-error')" role="alert">{{ describeError }}</p>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div v-if="paramRows.length" :class="cls.e('params')">
|
|
32
|
+
<p :class="cls.e('section-title')">查询参数(从 SQL 自动提取)</p>
|
|
33
|
+
<u-table
|
|
34
|
+
:class="cls.e('param-table')"
|
|
35
|
+
:data="paramRows"
|
|
36
|
+
:columns="paramColumns"
|
|
37
|
+
border
|
|
38
|
+
text-ellipsis
|
|
39
|
+
>
|
|
40
|
+
<template #column:label="{ rowData }">
|
|
41
|
+
<u-input
|
|
42
|
+
:model-value="rowData.label"
|
|
43
|
+
size="small"
|
|
44
|
+
@update:model-value="(v) => patchParam(rowData.id, { label: String(v ?? '') })"
|
|
45
|
+
/>
|
|
46
|
+
</template>
|
|
47
|
+
<template #column:type="{ rowData }">
|
|
48
|
+
<u-select
|
|
49
|
+
:model-value="rowData.type"
|
|
50
|
+
size="small"
|
|
51
|
+
:options="paramTypeOptions"
|
|
52
|
+
@update:model-value="(v) => patchParam(rowData.id, { type: v as QueryParamType })"
|
|
53
|
+
/>
|
|
54
|
+
</template>
|
|
55
|
+
<template #column:defaultValue="{ rowData }">
|
|
56
|
+
<u-input
|
|
57
|
+
v-if="rowData.type === 'number'"
|
|
58
|
+
:model-value="String(rowData.defaultValue ?? '')"
|
|
59
|
+
size="small"
|
|
60
|
+
type="number"
|
|
61
|
+
@update:model-value="(v) => patchParam(rowData.id, { defaultValue: Number(v) })"
|
|
62
|
+
/>
|
|
63
|
+
<u-input
|
|
64
|
+
v-else-if="rowData.type === 'date'"
|
|
65
|
+
:model-value="String(rowData.defaultValue ?? '')"
|
|
66
|
+
size="small"
|
|
67
|
+
type="date"
|
|
68
|
+
@update:model-value="(v) => patchParam(rowData.id, { defaultValue: v })"
|
|
69
|
+
/>
|
|
70
|
+
<u-select
|
|
71
|
+
v-else-if="rowData.type === 'select'"
|
|
72
|
+
:model-value="String(rowData.defaultValue ?? '')"
|
|
73
|
+
size="small"
|
|
74
|
+
:options="rowData.options ?? []"
|
|
75
|
+
@update:model-value="(v) => patchParam(rowData.id, { defaultValue: v })"
|
|
76
|
+
/>
|
|
77
|
+
<u-input
|
|
78
|
+
v-else
|
|
79
|
+
:model-value="formatDefaultValue(rowData.defaultValue)"
|
|
80
|
+
size="small"
|
|
81
|
+
@update:model-value="(v) => patchParam(rowData.id, { defaultValue: v })"
|
|
82
|
+
/>
|
|
83
|
+
</template>
|
|
84
|
+
<template #column:options="{ rowData }">
|
|
85
|
+
<u-input
|
|
86
|
+
v-if="rowData.type === 'select'"
|
|
87
|
+
:model-value="formatOptions(rowData.options)"
|
|
88
|
+
size="small"
|
|
89
|
+
placeholder="华东|华东,华南|华南"
|
|
90
|
+
@update:model-value="
|
|
91
|
+
(v) => patchParam(rowData.id, { options: parseOptions(String(v ?? '')) })
|
|
92
|
+
"
|
|
93
|
+
/>
|
|
94
|
+
<span v-else :class="cls.e('muted')">—</span>
|
|
95
|
+
</template>
|
|
96
|
+
</u-table>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
<u-tabs v-model="detailTab" :items="detailTabItems" :class="cls.e('tabs')">
|
|
100
|
+
<template #schema>
|
|
101
|
+
<p v-if="describing" :class="cls.e('muted')">正在解析字段…</p>
|
|
102
|
+
<u-table
|
|
103
|
+
v-else
|
|
104
|
+
:class="cls.e('schema-table')"
|
|
105
|
+
:data="schemaRows"
|
|
106
|
+
:columns="schemaColumns"
|
|
107
|
+
border
|
|
108
|
+
text-ellipsis
|
|
109
|
+
>
|
|
110
|
+
<template #column:label="{ rowData }">
|
|
111
|
+
<u-input
|
|
112
|
+
:model-value="rowData.label"
|
|
113
|
+
size="small"
|
|
114
|
+
placeholder="中文显示名"
|
|
115
|
+
@update:model-value="(v) => patchFieldLabel(rowData.name, String(v ?? ''))"
|
|
116
|
+
/>
|
|
117
|
+
</template>
|
|
118
|
+
<template #column:type="{ rowData }">
|
|
119
|
+
<u-tag size="small" :type="fieldTypeColor(rowData.type)">{{ rowData.type }}</u-tag>
|
|
120
|
+
</template>
|
|
121
|
+
</u-table>
|
|
122
|
+
</template>
|
|
123
|
+
<template #preview>
|
|
124
|
+
<div :class="cls.e('preview-actions')">
|
|
125
|
+
<u-button size="small" plain :loading="previewing" @click="runPreview">
|
|
126
|
+
刷新预览(按参数默认值取数)
|
|
127
|
+
</u-button>
|
|
128
|
+
</div>
|
|
129
|
+
<u-table
|
|
130
|
+
:class="cls.e('preview-table')"
|
|
131
|
+
:data="previewRows"
|
|
132
|
+
:columns="previewColumns"
|
|
133
|
+
show-index
|
|
134
|
+
border
|
|
135
|
+
text-ellipsis
|
|
136
|
+
/>
|
|
137
|
+
<p v-if="previewError" :class="cls.e('preview-error')" role="alert">{{ previewError }}</p>
|
|
138
|
+
</template>
|
|
139
|
+
</u-tabs>
|
|
140
|
+
</section>
|
|
141
|
+
</template>
|
|
142
|
+
|
|
143
|
+
<script lang="ts" setup>
|
|
144
|
+
import {
|
|
145
|
+
UButton,
|
|
146
|
+
UCodeEditor,
|
|
147
|
+
UInput,
|
|
148
|
+
UPopConfirm,
|
|
149
|
+
USelect,
|
|
150
|
+
UTable,
|
|
151
|
+
UTabs,
|
|
152
|
+
UTag,
|
|
153
|
+
defineTableColumns
|
|
154
|
+
} from '@veltra/desktop'
|
|
155
|
+
import type { ColorType } from '@veltra/utils'
|
|
156
|
+
import { bem } from '@veltra/utils'
|
|
157
|
+
import { computed, onBeforeUnmount, ref, shallowRef, watch } from 'vue'
|
|
158
|
+
|
|
159
|
+
import { buildParamDefs } from '../../report/params'
|
|
160
|
+
import type { DatasetField, QueryParamDef, QueryParamType } from '../../report/types'
|
|
161
|
+
import type { DatasetHubController, DesignerDataset } from './use-report-designer'
|
|
162
|
+
|
|
163
|
+
defineOptions({ name: 'UReportHubDatasetEditor' })
|
|
164
|
+
|
|
165
|
+
const props = defineProps<{ hub: DatasetHubController; datasetId: string }>()
|
|
166
|
+
|
|
167
|
+
const emit = defineEmits<{ remove: [] }>()
|
|
168
|
+
|
|
169
|
+
const cls = bem('report-hub-dataset-editor')
|
|
170
|
+
|
|
171
|
+
const detailTab = ref('schema')
|
|
172
|
+
const detailTabItems = [
|
|
173
|
+
{ key: 'schema', name: '字段 Schema' },
|
|
174
|
+
{ key: 'preview', name: '数据预览' }
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
const paramTypeOptions = [
|
|
178
|
+
{ label: '文本', value: 'text' },
|
|
179
|
+
{ label: '数字', value: 'number' },
|
|
180
|
+
{ label: '日期', value: 'date' },
|
|
181
|
+
{ label: '日期范围', value: 'date-range' },
|
|
182
|
+
{ label: '下拉', value: 'select' }
|
|
183
|
+
]
|
|
184
|
+
|
|
185
|
+
const dataset = computed((): DesignerDataset | undefined =>
|
|
186
|
+
props.hub.datasets.value.find((item) => item.id === props.datasetId)
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
// ---- describe / 预览状态(声明先于下方 immediate watcher 使用) ----
|
|
190
|
+
|
|
191
|
+
const describing = ref(false)
|
|
192
|
+
const describeError = shallowRef('')
|
|
193
|
+
let describeSeq = 0
|
|
194
|
+
|
|
195
|
+
const previewing = ref(false)
|
|
196
|
+
const previewError = shallowRef('')
|
|
197
|
+
const previewRows = shallowRef<Record<string, unknown>[]>([])
|
|
198
|
+
const previewFields = shallowRef<DatasetField[]>([])
|
|
199
|
+
|
|
200
|
+
function resetPreview(): void {
|
|
201
|
+
previewing.value = false
|
|
202
|
+
previewError.value = ''
|
|
203
|
+
previewRows.value = []
|
|
204
|
+
previewFields.value = []
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ---- SQL 编辑:debounce 写回数据集并触发 describe ----
|
|
208
|
+
|
|
209
|
+
const sqlDraft = ref('')
|
|
210
|
+
let sqlTimer: ReturnType<typeof setTimeout> | undefined
|
|
211
|
+
|
|
212
|
+
watch(
|
|
213
|
+
() => props.datasetId,
|
|
214
|
+
() => {
|
|
215
|
+
sqlDraft.value = dataset.value?.sql ?? ''
|
|
216
|
+
resetPreview()
|
|
217
|
+
void runDescribe()
|
|
218
|
+
},
|
|
219
|
+
{ immediate: true }
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
function onSqlChange(value: string): void {
|
|
223
|
+
sqlDraft.value = value
|
|
224
|
+
if (sqlTimer) clearTimeout(sqlTimer)
|
|
225
|
+
sqlTimer = setTimeout(() => {
|
|
226
|
+
props.hub.updateDataset(props.datasetId, { sql: value })
|
|
227
|
+
void runDescribe()
|
|
228
|
+
}, 280)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
onBeforeUnmount(() => {
|
|
232
|
+
if (sqlTimer) clearTimeout(sqlTimer)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
// ---- describe 字段解析(经连接器;结果写入数据集字段缓存) ----
|
|
236
|
+
|
|
237
|
+
async function runDescribe(): Promise<void> {
|
|
238
|
+
const seq = ++describeSeq
|
|
239
|
+
if (!sqlDraft.value.trim()) {
|
|
240
|
+
describeError.value = ''
|
|
241
|
+
// SQL 清空 = 无查询:清掉字段缓存,字段面板不再残留旧字段
|
|
242
|
+
props.hub.updateDataset(props.datasetId, { fields: undefined })
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
describing.value = true
|
|
246
|
+
const result = await props.hub.describeDataset(props.datasetId)
|
|
247
|
+
if (seq !== describeSeq) return
|
|
248
|
+
describing.value = false
|
|
249
|
+
describeError.value = result.ok ? '' : result.error.message
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ---- 查询参数(`${param}` 提取 + 元数据覆盖) ----
|
|
253
|
+
|
|
254
|
+
const paramRows = computed(() => {
|
|
255
|
+
const current = dataset.value
|
|
256
|
+
if (!current || !current.sql.trim()) return []
|
|
257
|
+
return buildParamDefs(current.sql, current.paramOverrides)
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
// ---- 字段 schema(describe 缓存 + fieldOverrides) ----
|
|
261
|
+
|
|
262
|
+
const schemaRows = computed(() => {
|
|
263
|
+
const current = dataset.value
|
|
264
|
+
if (!current) return []
|
|
265
|
+
return (current.fields ?? []).map((field) => ({
|
|
266
|
+
...field,
|
|
267
|
+
label: current.fieldOverrides?.[field.name]?.label ?? field.label
|
|
268
|
+
}))
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
// ---- 记录预览(按参数默认值经连接器取数) ----
|
|
272
|
+
|
|
273
|
+
async function runPreview(): Promise<void> {
|
|
274
|
+
previewing.value = true
|
|
275
|
+
previewError.value = ''
|
|
276
|
+
const result = await props.hub.previewDataset(props.datasetId)
|
|
277
|
+
previewing.value = false
|
|
278
|
+
if (result.ok) {
|
|
279
|
+
previewRows.value = result.data.rows
|
|
280
|
+
previewFields.value = result.data.fields
|
|
281
|
+
} else {
|
|
282
|
+
previewRows.value = []
|
|
283
|
+
previewError.value = result.error.message
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
watch(detailTab, (tab) => {
|
|
288
|
+
if (tab === 'preview') void runPreview()
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
// ---- 表格列与编辑 ----
|
|
292
|
+
|
|
293
|
+
const paramColumns = defineTableColumns([
|
|
294
|
+
{ key: 'id', name: '参数名', minWidth: 100 },
|
|
295
|
+
{ key: 'label', name: '显示名', minWidth: 120 },
|
|
296
|
+
{ key: 'type', name: '类型', width: 120 },
|
|
297
|
+
{ key: 'defaultValue', name: '默认值', minWidth: 140 },
|
|
298
|
+
{ key: 'options', name: '选项(select)', minWidth: 160 }
|
|
299
|
+
])
|
|
300
|
+
|
|
301
|
+
const schemaColumns = defineTableColumns([
|
|
302
|
+
{ key: 'name', name: '字段名(name)', minWidth: 140 },
|
|
303
|
+
{ key: 'label', name: '中文描述(label)', minWidth: 160 },
|
|
304
|
+
{ key: 'type', name: '类型', width: 88 }
|
|
305
|
+
])
|
|
306
|
+
|
|
307
|
+
const previewColumns = computed(() =>
|
|
308
|
+
defineTableColumns(
|
|
309
|
+
previewFields.value.map((field) => ({
|
|
310
|
+
key: field.name,
|
|
311
|
+
name: field.label,
|
|
312
|
+
minWidth: field.type === 'number' ? 88 : 112
|
|
313
|
+
}))
|
|
314
|
+
)
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
function fieldTypeColor(type: DatasetField['type']): ColorType {
|
|
318
|
+
if (type === 'number') return 'success'
|
|
319
|
+
if (type === 'date') return 'warning'
|
|
320
|
+
return 'info'
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function formatDefaultValue(value: unknown): string {
|
|
324
|
+
if (Array.isArray(value)) return value.join(', ')
|
|
325
|
+
return String(value ?? '')
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function formatOptions(options?: { label: string; value: string }[]): string {
|
|
329
|
+
if (!options?.length) return ''
|
|
330
|
+
return options.map((item) => `${item.label}|${item.value}`).join(',')
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function parseOptions(raw: string): { label: string; value: string }[] {
|
|
334
|
+
return raw
|
|
335
|
+
.split(',')
|
|
336
|
+
.map((part) => part.trim())
|
|
337
|
+
.filter(Boolean)
|
|
338
|
+
.map((part) => {
|
|
339
|
+
const [label, value] = part.split('|')
|
|
340
|
+
const text = (label ?? '').trim()
|
|
341
|
+
const val = (value ?? text).trim()
|
|
342
|
+
return { label: text, value: val }
|
|
343
|
+
})
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function patchDataset(patch: Partial<Omit<DesignerDataset, 'id'>>): void {
|
|
347
|
+
props.hub.updateDataset(props.datasetId, patch)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function patchParam(paramId: string, patch: Partial<Omit<QueryParamDef, 'id'>>): void {
|
|
351
|
+
const current = dataset.value
|
|
352
|
+
if (!current) return
|
|
353
|
+
const nextOverrides = {
|
|
354
|
+
...current.paramOverrides,
|
|
355
|
+
[paramId]: { ...current.paramOverrides?.[paramId], ...patch }
|
|
356
|
+
}
|
|
357
|
+
patchDataset({ paramOverrides: nextOverrides })
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function patchFieldLabel(fieldName: string, label: string): void {
|
|
361
|
+
const current = dataset.value
|
|
362
|
+
if (!current) return
|
|
363
|
+
const nextOverrides = {
|
|
364
|
+
...current.fieldOverrides,
|
|
365
|
+
[fieldName]: { ...current.fieldOverrides?.[fieldName], label }
|
|
366
|
+
}
|
|
367
|
+
patchDataset({ fieldOverrides: nextOverrides })
|
|
368
|
+
}
|
|
369
|
+
</script>
|