@veltra/sheet 2.3.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -17
- package/dist/index.js +2 -13
- package/dist/types/index.d.ts +1 -3
- package/package.json +5 -6
- package/src/index.ts +1 -27
- package/src/types/index.ts +0 -2
- package/dist/components/report/binding-badge.js +0 -112
- package/dist/components/report/designer/cell-coords.js +0 -46
- package/dist/components/report/designer/col-widths.js +0 -29
- package/dist/components/report/designer/conditional-rules/helpers.js +0 -139
- package/dist/components/report/designer/drop-highlight-overlay.js +0 -76
- package/dist/components/report/designer/float-panel.js +0 -422
- package/dist/components/report/designer/role.js +0 -17
- package/dist/components/report/designer/rule-preview.js +0 -33
- package/dist/components/report/designer/rule-row.js +0 -253
- package/dist/components/report/designer/rules-dialog.js +0 -118
- package/dist/components/report/designer/topology-overlay.js +0 -122
- package/dist/components/report/designer/topology.js +0 -64
- package/dist/components/report/designer/use-grid-overlay.js +0 -75
- package/dist/components/report/designer-hub.js +0 -177
- package/dist/components/report/field-panel-helpers.js +0 -33
- package/dist/components/report/field-panel.js +0 -132
- package/dist/components/report/filter-bar.js +0 -74
- package/dist/components/report/hub-connection-form.js +0 -145
- package/dist/components/report/hub-dataset-editor.js +0 -409
- package/dist/components/report/preview-grid-size.js +0 -32
- package/dist/components/report/report-designer.js +0 -393
- package/dist/components/report/report-viewer.js +0 -124
- package/dist/components/report/style.d.ts +0 -17
- package/dist/components/report/style.js +0 -18
- package/dist/components/report/style2.css +0 -874
- package/dist/components/report/use-report-designer.js +0 -386
- package/dist/components/report/use-report-viewer.js +0 -55
- package/dist/report/binding.d.ts +0 -83
- package/dist/report/binding.js +0 -334
- package/dist/report/connector.d.ts +0 -66
- package/dist/report/connector.js +0 -159
- package/dist/report/export-xlsx.d.ts +0 -13
- package/dist/report/export-xlsx.js +0 -13
- package/dist/report/filter-bar.d.ts +0 -10
- package/dist/report/filter-bar.js +0 -31
- package/dist/report/index.d.ts +0 -12
- package/dist/report/params.d.ts +0 -13
- package/dist/report/params.js +0 -61
- package/dist/report/render/aggregate.js +0 -169
- package/dist/report/render/builder.d.ts +0 -12
- package/dist/report/render/builder.js +0 -139
- package/dist/report/render/coordinate.d.ts +0 -25
- package/dist/report/render/coordinate.js +0 -733
- package/dist/report/render/index.d.ts +0 -14
- package/dist/report/render/index.js +0 -21
- package/dist/report/render/style-resolver.js +0 -50
- package/dist/report/render/template-index.d.ts +0 -24
- package/dist/report/render/template-index.js +0 -137
- package/dist/report/rules/evaluate.d.ts +0 -25
- package/dist/report/rules/evaluate.js +0 -82
- package/dist/report/rules/index.d.ts +0 -2
- package/dist/report/template.d.ts +0 -63
- package/dist/report/template.js +0 -83
- package/dist/report/types.d.ts +0 -85
- package/dist/types/report-designer.d.ts +0 -38
- package/dist/types/report-viewer.d.ts +0 -38
- package/src/components/report/__test__/binding-badge.test.ts +0 -92
- package/src/components/report/__test__/conditional-rules-helpers.test.ts +0 -88
- package/src/components/report/__test__/field-panel-helpers.test.ts +0 -65
- package/src/components/report/__test__/float-panel-position.test.ts +0 -45
- package/src/components/report/__test__/preview-grid-size.test.ts +0 -63
- package/src/components/report/__test__/report-designer.test.ts +0 -464
- package/src/components/report/__test__/report-viewer.test.ts +0 -357
- package/src/components/report/__test__/topology.test.ts +0 -143
- package/src/components/report/__test__/use-report-designer.test.ts +0 -697
- package/src/components/report/binding-badge.ts +0 -117
- package/src/components/report/designer/cell-coords.ts +0 -95
- package/src/components/report/designer/col-widths.ts +0 -56
- package/src/components/report/designer/conditional-rules/helpers.ts +0 -189
- package/src/components/report/designer/drop-highlight-overlay.vue +0 -75
- package/src/components/report/designer/float-panel.vue +0 -432
- package/src/components/report/designer/role.ts +0 -32
- package/src/components/report/designer/rule-preview.vue +0 -40
- package/src/components/report/designer/rule-row.vue +0 -252
- package/src/components/report/designer/rules-dialog.vue +0 -110
- package/src/components/report/designer/topology-overlay.vue +0 -128
- package/src/components/report/designer/topology.ts +0 -124
- package/src/components/report/designer/use-grid-overlay.ts +0 -114
- package/src/components/report/designer-hub.vue +0 -198
- package/src/components/report/field-panel-helpers.ts +0 -44
- package/src/components/report/field-panel.vue +0 -136
- package/src/components/report/filter-bar.vue +0 -77
- package/src/components/report/hub-connection-form.vue +0 -124
- package/src/components/report/hub-dataset-editor.vue +0 -387
- package/src/components/report/index.ts +0 -2
- package/src/components/report/preview-grid-size.ts +0 -33
- package/src/components/report/report-designer.vue +0 -421
- package/src/components/report/report-viewer.vue +0 -136
- package/src/components/report/style-designer.scss +0 -587
- package/src/components/report/style-hub.scss +0 -292
- package/src/components/report/style-viewer.scss +0 -104
- package/src/components/report/style.scss +0 -3
- package/src/components/report/style.ts +0 -20
- package/src/components/report/use-report-designer.ts +0 -602
- package/src/components/report/use-report-viewer.ts +0 -88
- package/src/report/__test__/binding.test.ts +0 -320
- package/src/report/__test__/connector.test.ts +0 -239
- package/src/report/__test__/export-xlsx.test.ts +0 -96
- package/src/report/__test__/filter-bar.test.ts +0 -58
- package/src/report/__test__/params.test.ts +0 -156
- package/src/report/__test__/render.test.ts +0 -856
- package/src/report/__test__/rules.test.ts +0 -131
- package/src/report/__test__/template.test.ts +0 -366
- package/src/report/binding.ts +0 -474
- package/src/report/connector.ts +0 -206
- package/src/report/export-xlsx.ts +0 -15
- package/src/report/filter-bar.ts +0 -36
- package/src/report/index.ts +0 -13
- package/src/report/params.ts +0 -96
- package/src/report/render/__test__/aggregate.test.ts +0 -16
- package/src/report/render/__test__/coordinate.test.ts +0 -405
- package/src/report/render/aggregate.ts +0 -261
- package/src/report/render/builder.ts +0 -211
- package/src/report/render/coordinate.ts +0 -1239
- package/src/report/render/index.ts +0 -30
- package/src/report/render/style-resolver.ts +0 -68
- package/src/report/render/template-index.ts +0 -200
- package/src/report/rules/evaluate.ts +0 -113
- package/src/report/rules/index.ts +0 -7
- package/src/report/template.ts +0 -145
- package/src/report/types.ts +0 -96
- package/src/types/report-designer.ts +0 -38
- package/src/types/report-viewer.ts +0 -37
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { CellAddress } from '@veltra/sheet-core'
|
|
2
|
-
import type { SheetGrid } from '@veltra/sheet-core/grid'
|
|
3
|
-
import { onBeforeUnmount, watch, type Ref } from 'vue'
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
getCellOverlayRect,
|
|
7
|
-
resolveGridOverlayLayout,
|
|
8
|
-
type CellOverlayRect,
|
|
9
|
-
type GridOverlayLayout
|
|
10
|
-
} from './cell-coords'
|
|
11
|
-
|
|
12
|
-
type GridGetter = () => SheetGrid | undefined
|
|
13
|
-
|
|
14
|
-
/** 网格滚动时重算 overlay 坐标;避免在 props 不稳定时重复绑定监听 */
|
|
15
|
-
export function useGridOverlaySync(options: {
|
|
16
|
-
hostEl: Ref<HTMLElement | null>
|
|
17
|
-
getGrid: GridGetter
|
|
18
|
-
watchSources: () => readonly unknown[]
|
|
19
|
-
update: () => void
|
|
20
|
-
}): void {
|
|
21
|
-
let offScroll: (() => void) | undefined
|
|
22
|
-
let rafId = 0
|
|
23
|
-
|
|
24
|
-
function scheduleUpdate(): void {
|
|
25
|
-
cancelAnimationFrame(rafId)
|
|
26
|
-
rafId = requestAnimationFrame(options.update)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function bindScroll(): void {
|
|
30
|
-
offScroll?.()
|
|
31
|
-
offScroll = undefined
|
|
32
|
-
const grid = options.getGrid()
|
|
33
|
-
if (!grid) return
|
|
34
|
-
|
|
35
|
-
const table = grid.getTable()
|
|
36
|
-
const onScroll = (): void => scheduleUpdate()
|
|
37
|
-
const scrollEvent = 'scroll'
|
|
38
|
-
table.on(scrollEvent, onScroll)
|
|
39
|
-
offScroll = () => table.off(scrollEvent, onScroll)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
watch(
|
|
43
|
-
options.watchSources,
|
|
44
|
-
() => {
|
|
45
|
-
bindScroll()
|
|
46
|
-
scheduleUpdate()
|
|
47
|
-
},
|
|
48
|
-
{ immediate: true, flush: 'post' }
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
onBeforeUnmount(() => {
|
|
52
|
-
cancelAnimationFrame(rafId)
|
|
53
|
-
offScroll?.()
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function readCellOverlayRect(
|
|
58
|
-
cell: CellAddress,
|
|
59
|
-
host: HTMLElement,
|
|
60
|
-
getGrid: GridGetter
|
|
61
|
-
): ReturnType<typeof getCellOverlayRect> {
|
|
62
|
-
const grid = getGrid()
|
|
63
|
-
if (!grid) return null
|
|
64
|
-
const resolved = resolveGridOverlayLayout(host)
|
|
65
|
-
if (!resolved) return null
|
|
66
|
-
return getCellOverlayRect(grid, cell, resolved.layout)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function readGridOverlaySize(host: HTMLElement): { width: number; height: number } | null {
|
|
70
|
-
const resolved = resolveGridOverlayLayout(host)
|
|
71
|
-
if (!resolved) return null
|
|
72
|
-
const { layout } = resolved
|
|
73
|
-
return { width: layout.viewW + layout.offsetX, height: layout.viewH + layout.offsetY }
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface BindingFloatPanelPosition {
|
|
77
|
-
placement: 'above' | 'below'
|
|
78
|
-
left: number
|
|
79
|
-
top: number
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** 悬浮编辑卡锚点:空间按网格画布(非宿主顶)计算,避免顶行格误判为上方可放 */
|
|
83
|
-
export function resolveBindingFloatPanelPosition(
|
|
84
|
-
rect: CellOverlayRect,
|
|
85
|
-
layout: GridOverlayLayout,
|
|
86
|
-
panelWidth: number,
|
|
87
|
-
panelHeight: number,
|
|
88
|
-
hostWidth: number,
|
|
89
|
-
options?: { gap?: number; edgePad?: number }
|
|
90
|
-
): BindingFloatPanelPosition {
|
|
91
|
-
const gap = options?.gap ?? 8
|
|
92
|
-
const edgePad = options?.edgePad ?? 10
|
|
93
|
-
const gridTop = layout.offsetY
|
|
94
|
-
const gridBottom = layout.offsetY + layout.viewH
|
|
95
|
-
|
|
96
|
-
let left = rect.centerX
|
|
97
|
-
const halfW = panelWidth / 2
|
|
98
|
-
left = Math.max(edgePad + halfW, Math.min(hostWidth - edgePad - halfW, left))
|
|
99
|
-
|
|
100
|
-
const spaceAbove = rect.top - gridTop
|
|
101
|
-
const spaceBelow = gridBottom - rect.bottom
|
|
102
|
-
const need = panelHeight + gap
|
|
103
|
-
|
|
104
|
-
let placement: 'above' | 'below' =
|
|
105
|
-
spaceAbove >= need || spaceAbove >= spaceBelow ? 'above' : 'below'
|
|
106
|
-
|
|
107
|
-
if (placement === 'above' && rect.top - gap - panelHeight < gridTop + edgePad) {
|
|
108
|
-
if (spaceBelow >= need || spaceBelow > spaceAbove) placement = 'below'
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const top = placement === 'above' ? rect.top - gap : rect.bottom + gap
|
|
112
|
-
|
|
113
|
-
return { placement, left: Math.round(left), top: Math.round(top) }
|
|
114
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div :class="cls.b">
|
|
3
|
-
<header :class="cls.e('head')">
|
|
4
|
-
<h3 :class="cls.e('title')">数据中枢</h3>
|
|
5
|
-
<u-button size="small" type="primary" @click="emit('close')">完成</u-button>
|
|
6
|
-
</header>
|
|
7
|
-
|
|
8
|
-
<div :class="cls.e('body')">
|
|
9
|
-
<aside :class="cls.e('sidebar')">
|
|
10
|
-
<div :class="cls.e('sidebar-head')">
|
|
11
|
-
<span :class="cls.e('sidebar-title')">连接与数据集</span>
|
|
12
|
-
<u-button size="small" plain @click="startNewConnection">新建连接</u-button>
|
|
13
|
-
</div>
|
|
14
|
-
|
|
15
|
-
<div :class="cls.e('tree')">
|
|
16
|
-
<section v-for="conn in connections" :key="conn.id" :class="cls.e('conn-group')">
|
|
17
|
-
<div
|
|
18
|
-
:class="[
|
|
19
|
-
cls.e('conn'),
|
|
20
|
-
bem.is('active', activeConnectionId === conn.id && !activeDatasetId)
|
|
21
|
-
]"
|
|
22
|
-
@click="selectConnection(conn.id)"
|
|
23
|
-
>
|
|
24
|
-
<span :class="cls.e('conn-label')">{{ conn.label }}</span>
|
|
25
|
-
<u-tag size="small" type="info">{{ conn.type }}</u-tag>
|
|
26
|
-
</div>
|
|
27
|
-
|
|
28
|
-
<ul :class="cls.e('dataset-list')">
|
|
29
|
-
<li
|
|
30
|
-
v-for="item in datasetsByConnection(conn.id)"
|
|
31
|
-
:key="item.id"
|
|
32
|
-
:class="[cls.e('dataset-item'), bem.is('active', activeDatasetId === item.id)]"
|
|
33
|
-
@click="selectDataset(item.id)"
|
|
34
|
-
>
|
|
35
|
-
<span>{{ item.label }}</span>
|
|
36
|
-
<span :class="cls.e('dataset-id')">{{ item.id }}</span>
|
|
37
|
-
</li>
|
|
38
|
-
</ul>
|
|
39
|
-
|
|
40
|
-
<u-button size="small" text :class="cls.e('add-dataset')" @click="addDataset(conn.id)">
|
|
41
|
-
+ 新建数据集
|
|
42
|
-
</u-button>
|
|
43
|
-
</section>
|
|
44
|
-
|
|
45
|
-
<p v-if="connections.length === 0" :class="cls.e('sidebar-empty')">
|
|
46
|
-
尚无连接。点「新建连接」配置 MySQL / PostgreSQL 数据连接。
|
|
47
|
-
</p>
|
|
48
|
-
</div>
|
|
49
|
-
</aside>
|
|
50
|
-
|
|
51
|
-
<div :class="cls.e('main')">
|
|
52
|
-
<u-report-hub-dataset-editor
|
|
53
|
-
v-if="activeDatasetId"
|
|
54
|
-
:hub="hub"
|
|
55
|
-
:dataset-id="activeDatasetId"
|
|
56
|
-
@remove="removeActiveDataset"
|
|
57
|
-
/>
|
|
58
|
-
<u-report-hub-connection-form
|
|
59
|
-
v-else-if="connectionDraft"
|
|
60
|
-
:connection="connectionDraft"
|
|
61
|
-
:is-new="creatingConnection"
|
|
62
|
-
:test="hub.testConnection"
|
|
63
|
-
@save="saveConnection"
|
|
64
|
-
@remove="removeActiveConnection"
|
|
65
|
-
/>
|
|
66
|
-
<div v-else :class="cls.e('empty')">
|
|
67
|
-
<p>选择左侧连接或数据集开始配置;数据集字段解析后即可在字段面板拖拽绑定。</p>
|
|
68
|
-
</div>
|
|
69
|
-
</div>
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
</template>
|
|
73
|
-
|
|
74
|
-
<script lang="ts" setup>
|
|
75
|
-
import { UButton, UTag } from '@veltra/desktop'
|
|
76
|
-
import { bem } from '@veltra/utils'
|
|
77
|
-
import { computed, ref, watch } from 'vue'
|
|
78
|
-
|
|
79
|
-
import type { DataConnection } from '../../report/connector'
|
|
80
|
-
import { DEFAULT_CONNECTION_PORTS } from '../../report/connector'
|
|
81
|
-
import UReportHubConnectionForm from './hub-connection-form.vue'
|
|
82
|
-
import UReportHubDatasetEditor from './hub-dataset-editor.vue'
|
|
83
|
-
import type { DatasetHubController } from './use-report-designer'
|
|
84
|
-
|
|
85
|
-
defineOptions({ name: 'UReportDatasetHub' })
|
|
86
|
-
|
|
87
|
-
const props = defineProps<{ hub: DatasetHubController }>()
|
|
88
|
-
|
|
89
|
-
const emit = defineEmits<{ close: [] }>()
|
|
90
|
-
|
|
91
|
-
const cls = bem('report-hub')
|
|
92
|
-
|
|
93
|
-
const connections = computed(() => props.hub.connections.value)
|
|
94
|
-
const datasets = computed(() => props.hub.datasets.value)
|
|
95
|
-
|
|
96
|
-
function datasetsByConnection(connectionId: string) {
|
|
97
|
-
return datasets.value.filter((item) => item.connectionId === connectionId)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const activeConnectionId = ref<string>()
|
|
101
|
-
const activeDatasetId = ref<string>()
|
|
102
|
-
const creatingConnection = ref(false)
|
|
103
|
-
const connectionDraft = ref<DataConnection>()
|
|
104
|
-
|
|
105
|
-
// 打开时默认选中首个连接 / 数据集
|
|
106
|
-
watch(
|
|
107
|
-
connections,
|
|
108
|
-
() => {
|
|
109
|
-
if (!activeConnectionId.value && connections.value[0]) {
|
|
110
|
-
activeConnectionId.value = connections.value[0]!.id
|
|
111
|
-
syncConnectionDraft()
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
{ immediate: true }
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
function syncConnectionDraft(): void {
|
|
118
|
-
if (activeDatasetId.value) {
|
|
119
|
-
connectionDraft.value = undefined
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
if (creatingConnection.value) return
|
|
123
|
-
const id = activeConnectionId.value
|
|
124
|
-
const conn = id ? connections.value.find((item) => item.id === id) : undefined
|
|
125
|
-
connectionDraft.value = conn ? { ...conn } : undefined
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function selectConnection(connectionId: string): void {
|
|
129
|
-
activeConnectionId.value = connectionId
|
|
130
|
-
activeDatasetId.value = undefined
|
|
131
|
-
creatingConnection.value = false
|
|
132
|
-
syncConnectionDraft()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function selectDataset(datasetId: string): void {
|
|
136
|
-
activeDatasetId.value = datasetId
|
|
137
|
-
const dataset = datasets.value.find((item) => item.id === datasetId)
|
|
138
|
-
if (dataset) activeConnectionId.value = dataset.connectionId
|
|
139
|
-
connectionDraft.value = undefined
|
|
140
|
-
creatingConnection.value = false
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let connectionSeq = 0
|
|
144
|
-
function startNewConnection(): void {
|
|
145
|
-
creatingConnection.value = true
|
|
146
|
-
activeDatasetId.value = undefined
|
|
147
|
-
connectionDraft.value = {
|
|
148
|
-
id: `conn-${Date.now()}-${connectionSeq++}`,
|
|
149
|
-
label: '新连接',
|
|
150
|
-
type: 'mysql',
|
|
151
|
-
host: '127.0.0.1',
|
|
152
|
-
port: DEFAULT_CONNECTION_PORTS.mysql,
|
|
153
|
-
database: '',
|
|
154
|
-
username: '',
|
|
155
|
-
password: ''
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function saveConnection(conn: DataConnection): void {
|
|
160
|
-
if (creatingConnection.value) {
|
|
161
|
-
props.hub.addConnection(conn)
|
|
162
|
-
creatingConnection.value = false
|
|
163
|
-
} else {
|
|
164
|
-
props.hub.updateConnection(conn)
|
|
165
|
-
}
|
|
166
|
-
activeConnectionId.value = conn.id
|
|
167
|
-
syncConnectionDraft()
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function removeActiveConnection(): void {
|
|
171
|
-
const id = activeConnectionId.value
|
|
172
|
-
if (!id) return
|
|
173
|
-
// removeConnection 级联删除其数据集
|
|
174
|
-
props.hub.removeConnection(id)
|
|
175
|
-
activeDatasetId.value = undefined
|
|
176
|
-
activeConnectionId.value = connections.value[0]?.id
|
|
177
|
-
creatingConnection.value = false
|
|
178
|
-
syncConnectionDraft()
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function addDataset(connectionId: string): void {
|
|
182
|
-
const dataset = props.hub.addDataset(connectionId)
|
|
183
|
-
activeConnectionId.value = connectionId
|
|
184
|
-
activeDatasetId.value = dataset.id
|
|
185
|
-
creatingConnection.value = false
|
|
186
|
-
connectionDraft.value = undefined
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function removeActiveDataset(): void {
|
|
190
|
-
const id = activeDatasetId.value
|
|
191
|
-
if (!id) return
|
|
192
|
-
props.hub.removeDataset(id)
|
|
193
|
-
activeDatasetId.value = datasets.value.find(
|
|
194
|
-
(item) => item.connectionId === activeConnectionId.value
|
|
195
|
-
)?.id
|
|
196
|
-
syncConnectionDraft()
|
|
197
|
-
}
|
|
198
|
-
</script>
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { DatasetCatalogItem, DatasetField } from '../../report/types'
|
|
2
|
-
|
|
3
|
-
/** 字段拖拽的 dataTransfer MIME(字段面板 dragstart / 网格 drop 共用) */
|
|
4
|
-
export const FIELD_DRAG_MIME = 'application/x-sheet-report-field'
|
|
5
|
-
|
|
6
|
-
/** 字段拖拽负载:`${datasetId}:${fieldName}` */
|
|
7
|
-
export function formatFieldDragPayload(datasetId: string, fieldName: string): string {
|
|
8
|
-
return `${datasetId}:${fieldName}`
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** 解析字段拖拽负载;非法输入返回 null */
|
|
12
|
-
export function parseFieldDragPayload(
|
|
13
|
-
raw: string
|
|
14
|
-
): { datasetId: string; fieldName: string } | null {
|
|
15
|
-
const sep = raw.indexOf(':')
|
|
16
|
-
if (sep <= 0) return null
|
|
17
|
-
const fieldName = raw.slice(sep + 1)
|
|
18
|
-
if (!fieldName) return null
|
|
19
|
-
return { datasetId: raw.slice(0, sep), fieldName }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function fieldTypeGlyph(type: DatasetField['type']): string {
|
|
23
|
-
if (type === 'number') return '#'
|
|
24
|
-
if (type === 'date') return '日'
|
|
25
|
-
return '文'
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function filterDatasetsByQuery(
|
|
29
|
-
datasets: DatasetCatalogItem[],
|
|
30
|
-
query: string
|
|
31
|
-
): DatasetCatalogItem[] {
|
|
32
|
-
const keyword = query.trim().toLowerCase()
|
|
33
|
-
if (!keyword) return datasets
|
|
34
|
-
|
|
35
|
-
return datasets
|
|
36
|
-
.map((dataset) => ({
|
|
37
|
-
...dataset,
|
|
38
|
-
fields: dataset.fields.filter(
|
|
39
|
-
(field) =>
|
|
40
|
-
field.label.toLowerCase().includes(keyword) || field.name.toLowerCase().includes(keyword)
|
|
41
|
-
)
|
|
42
|
-
}))
|
|
43
|
-
.filter((dataset) => dataset.fields.length > 0)
|
|
44
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<aside :class="cls.b">
|
|
3
|
-
<h3 :class="cls.e('title')">数据集字段</h3>
|
|
4
|
-
<p :class="cls.e('meta')">
|
|
5
|
-
当前选区:
|
|
6
|
-
<u-tag size="small" type="primary">{{ selectionLabel }}</u-tag>
|
|
7
|
-
</p>
|
|
8
|
-
|
|
9
|
-
<u-input
|
|
10
|
-
v-model="searchQuery"
|
|
11
|
-
:class="cls.e('search')"
|
|
12
|
-
size="small"
|
|
13
|
-
clearable
|
|
14
|
-
placeholder="搜索字段…"
|
|
15
|
-
/>
|
|
16
|
-
|
|
17
|
-
<p :class="cls.e('hint')">点击或拖拽字段到网格;中文名为主,英文键为绑定标识。</p>
|
|
18
|
-
|
|
19
|
-
<section v-for="dataset in visibleDatasets" :key="dataset.id" :class="cls.e('dataset')">
|
|
20
|
-
<u-button
|
|
21
|
-
text
|
|
22
|
-
size="small"
|
|
23
|
-
:class="cls.e('dataset-toggle')"
|
|
24
|
-
:aria-expanded="isDatasetExpanded(dataset.id)"
|
|
25
|
-
@click="toggleDataset(dataset.id)"
|
|
26
|
-
>
|
|
27
|
-
<span
|
|
28
|
-
:class="[cls.e('dataset-chevron'), bem.is('expanded', isDatasetExpanded(dataset.id))]"
|
|
29
|
-
aria-hidden="true"
|
|
30
|
-
>
|
|
31
|
-
▸
|
|
32
|
-
</span>
|
|
33
|
-
<span :class="cls.e('dataset-name')">{{ dataset.label }}</span>
|
|
34
|
-
<span :class="cls.e('dataset-count')">{{ dataset.fields.length }}</span>
|
|
35
|
-
</u-button>
|
|
36
|
-
|
|
37
|
-
<div v-show="isDatasetExpanded(dataset.id)" :class="cls.e('fields')">
|
|
38
|
-
<div
|
|
39
|
-
v-for="field in dataset.fields"
|
|
40
|
-
:key="field.name"
|
|
41
|
-
role="button"
|
|
42
|
-
tabindex="0"
|
|
43
|
-
:class="[cls.e('pill'), bem.is('bound', isBound(dataset.id, field.name))]"
|
|
44
|
-
draggable="true"
|
|
45
|
-
:title="`${field.label}(${field.name})`"
|
|
46
|
-
@click="emit('bind', dataset.id, field.name)"
|
|
47
|
-
@keydown.enter.prevent="emit('bind', dataset.id, field.name)"
|
|
48
|
-
@keydown.space.prevent="emit('bind', dataset.id, field.name)"
|
|
49
|
-
@dragstart="onDragStart($event, dataset.id, field.name)"
|
|
50
|
-
>
|
|
51
|
-
<span :class="cls.e('pill-icon')" :data-type="field.type">{{
|
|
52
|
-
fieldTypeGlyph(field.type)
|
|
53
|
-
}}</span>
|
|
54
|
-
<span :class="cls.e('pill-label')">{{ field.label }}</span>
|
|
55
|
-
<span v-if="isBound(dataset.id, field.name)" :class="cls.e('pill-bound')" title="已绑定"
|
|
56
|
-
>✓</span
|
|
57
|
-
>
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
</section>
|
|
61
|
-
|
|
62
|
-
<p v-if="datasets.length === 0" :class="cls.e('empty')">
|
|
63
|
-
尚无可用数据集,请点「数据中枢」创建连接与 SQL 数据集。
|
|
64
|
-
</p>
|
|
65
|
-
<p v-else-if="visibleDatasets.length === 0" :class="cls.e('empty')">没有匹配的字段。</p>
|
|
66
|
-
</aside>
|
|
67
|
-
</template>
|
|
68
|
-
|
|
69
|
-
<script lang="ts" setup>
|
|
70
|
-
import { UButton, UInput, UTag } from '@veltra/desktop'
|
|
71
|
-
import { bem } from '@veltra/utils'
|
|
72
|
-
import { computed, ref } from 'vue'
|
|
73
|
-
|
|
74
|
-
import type { DatasetCatalogItem } from '../../report/types'
|
|
75
|
-
import {
|
|
76
|
-
FIELD_DRAG_MIME,
|
|
77
|
-
fieldTypeGlyph,
|
|
78
|
-
filterDatasetsByQuery,
|
|
79
|
-
formatFieldDragPayload
|
|
80
|
-
} from './field-panel-helpers'
|
|
81
|
-
|
|
82
|
-
defineOptions({ name: 'UReportFieldPanel' })
|
|
83
|
-
|
|
84
|
-
const props = defineProps<{
|
|
85
|
-
/** 本报表已选用的数据集(含可编辑中文 label) */
|
|
86
|
-
datasets: DatasetCatalogItem[]
|
|
87
|
-
selectionLabel: string
|
|
88
|
-
/** 已绑定字段键:`${datasetId}:${fieldName}` */
|
|
89
|
-
boundKeys: Set<string>
|
|
90
|
-
}>()
|
|
91
|
-
|
|
92
|
-
const emit = defineEmits<{ bind: [datasetId: string, fieldName: string] }>()
|
|
93
|
-
|
|
94
|
-
const cls = bem('report-field-panel')
|
|
95
|
-
|
|
96
|
-
const searchQuery = ref('')
|
|
97
|
-
const collapsedDatasetIds = ref<Set<string>>(new Set())
|
|
98
|
-
|
|
99
|
-
const visibleDatasets = computed(() => filterDatasetsByQuery(props.datasets, searchQuery.value))
|
|
100
|
-
|
|
101
|
-
/** 折叠集合;搜索时视为全部展开(返回空集) */
|
|
102
|
-
const effectiveCollapsed = computed(() => {
|
|
103
|
-
const keyword = searchQuery.value.trim()
|
|
104
|
-
if (!keyword) return collapsedDatasetIds.value
|
|
105
|
-
return new Set<string>()
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
function isDatasetExpanded(datasetId: string): boolean {
|
|
109
|
-
return !effectiveCollapsed.value.has(datasetId)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function isBound(datasetId: string, fieldName: string): boolean {
|
|
113
|
-
return props.boundKeys.has(`${datasetId}:${fieldName}`)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function toggleDataset(datasetId: string): void {
|
|
117
|
-
const next = new Set(collapsedDatasetIds.value)
|
|
118
|
-
if (next.has(datasetId)) next.delete(datasetId)
|
|
119
|
-
else next.add(datasetId)
|
|
120
|
-
collapsedDatasetIds.value = next
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function onDragStart(event: DragEvent, datasetId: string, fieldName: string): void {
|
|
124
|
-
event.dataTransfer?.setData(FIELD_DRAG_MIME, formatFieldDragPayload(datasetId, fieldName))
|
|
125
|
-
if (event.dataTransfer) event.dataTransfer.effectAllowed = 'copy'
|
|
126
|
-
|
|
127
|
-
const target = event.currentTarget
|
|
128
|
-
if (event.dataTransfer && target instanceof HTMLElement) {
|
|
129
|
-
event.dataTransfer.setDragImage(
|
|
130
|
-
target,
|
|
131
|
-
Math.round(target.offsetWidth / 2),
|
|
132
|
-
Math.round(target.offsetHeight / 2)
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
</script>
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<section v-if="queryParams.length" :class="cls.b">
|
|
3
|
-
<span :class="cls.e('label')">筛选参数</span>
|
|
4
|
-
<div :class="cls.e('fields')">
|
|
5
|
-
<div v-for="param in queryParams" :key="param.id" :class="cls.e('field')">
|
|
6
|
-
<span :class="cls.e('field-label')">{{ param.label }}</span>
|
|
7
|
-
<u-date-picker
|
|
8
|
-
v-if="param.type === 'date'"
|
|
9
|
-
:model-value="String(values[param.id] ?? '')"
|
|
10
|
-
size="small"
|
|
11
|
-
@update:model-value="(v) => emitChange(param.id, v)"
|
|
12
|
-
/>
|
|
13
|
-
<u-date-range-picker
|
|
14
|
-
v-else-if="param.type === 'date-range'"
|
|
15
|
-
:model-value="dateRangeModel(param.id)"
|
|
16
|
-
size="small"
|
|
17
|
-
@update:model-value="(v) => emitDateRangeChange(param.id, v)"
|
|
18
|
-
/>
|
|
19
|
-
<u-select
|
|
20
|
-
v-else-if="param.type === 'select'"
|
|
21
|
-
:model-value="String(values[param.id] ?? '')"
|
|
22
|
-
size="small"
|
|
23
|
-
:options="param.options ?? []"
|
|
24
|
-
@update:model-value="(v) => emitChange(param.id, v)"
|
|
25
|
-
/>
|
|
26
|
-
<u-number-input
|
|
27
|
-
v-else-if="param.type === 'number'"
|
|
28
|
-
:model-value="numberModel(param.id)"
|
|
29
|
-
size="small"
|
|
30
|
-
@update:model-value="(v) => emitChange(param.id, v)"
|
|
31
|
-
/>
|
|
32
|
-
<u-input
|
|
33
|
-
v-else
|
|
34
|
-
:model-value="String(values[param.id] ?? '')"
|
|
35
|
-
size="small"
|
|
36
|
-
@update:model-value="(v) => emitChange(param.id, v)"
|
|
37
|
-
/>
|
|
38
|
-
</div>
|
|
39
|
-
</div>
|
|
40
|
-
</section>
|
|
41
|
-
</template>
|
|
42
|
-
|
|
43
|
-
<script lang="ts" setup>
|
|
44
|
-
import { UDatePicker, UDateRangePicker, UInput, UNumberInput, USelect } from '@veltra/desktop'
|
|
45
|
-
import { bem } from '@veltra/utils'
|
|
46
|
-
|
|
47
|
-
import {
|
|
48
|
-
parseDateRangeValue,
|
|
49
|
-
patchParamValues,
|
|
50
|
-
resolveNumberParamValue
|
|
51
|
-
} from '../../report/filter-bar'
|
|
52
|
-
import type { ParamValues, QueryParamDef } from '../../report/types'
|
|
53
|
-
|
|
54
|
-
defineOptions({ name: 'UReportFilterBar' })
|
|
55
|
-
|
|
56
|
-
const props = defineProps<{ queryParams: QueryParamDef[]; values: ParamValues }>()
|
|
57
|
-
|
|
58
|
-
const emit = defineEmits<{ 'update:values': [values: ParamValues] }>()
|
|
59
|
-
|
|
60
|
-
const cls = bem('report-filter-bar')
|
|
61
|
-
|
|
62
|
-
function dateRangeModel(paramId: string): [string, string] {
|
|
63
|
-
return parseDateRangeValue(props.values[paramId])
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function numberModel(paramId: string): number | undefined {
|
|
67
|
-
return resolveNumberParamValue(props.values[paramId])
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function emitChange(id: string, value: unknown): void {
|
|
71
|
-
emit('update:values', patchParamValues(props.values, id, value))
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function emitDateRangeChange(id: string, value?: [string, string]): void {
|
|
75
|
-
emit('update:values', patchParamValues(props.values, id, value ?? ['', '']))
|
|
76
|
-
}
|
|
77
|
-
</script>
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<section :class="cls.b">
|
|
3
|
-
<h4 :class="cls.e('title')">{{ isNew ? '新建连接' : '编辑连接' }}</h4>
|
|
4
|
-
<div :class="cls.e('grid')">
|
|
5
|
-
<div :class="cls.e('field')">
|
|
6
|
-
<span :class="cls.e('label')">显示名</span>
|
|
7
|
-
<u-input v-model="draft.label" size="small" placeholder="连接名称" />
|
|
8
|
-
</div>
|
|
9
|
-
<div :class="cls.e('field')">
|
|
10
|
-
<span :class="cls.e('label')">类型</span>
|
|
11
|
-
<u-select v-model="draft.type" size="small" :options="typeOptions" />
|
|
12
|
-
</div>
|
|
13
|
-
<div :class="cls.e('field')">
|
|
14
|
-
<span :class="cls.e('label')">主机</span>
|
|
15
|
-
<u-input v-model="draft.host" size="small" placeholder="127.0.0.1" />
|
|
16
|
-
</div>
|
|
17
|
-
<div :class="cls.e('field')">
|
|
18
|
-
<span :class="cls.e('label')">端口</span>
|
|
19
|
-
<u-input v-model="portText" size="small" type="number" :placeholder="String(defaultPort)" />
|
|
20
|
-
</div>
|
|
21
|
-
<div :class="cls.e('field')">
|
|
22
|
-
<span :class="cls.e('label')">数据库</span>
|
|
23
|
-
<u-input v-model="draft.database" size="small" placeholder="数据库名" />
|
|
24
|
-
</div>
|
|
25
|
-
<div :class="cls.e('field')">
|
|
26
|
-
<span :class="cls.e('label')">用户名</span>
|
|
27
|
-
<u-input v-model="draft.username" size="small" />
|
|
28
|
-
</div>
|
|
29
|
-
<div :class="cls.e('field')">
|
|
30
|
-
<span :class="cls.e('label')">密码</span>
|
|
31
|
-
<u-input v-model="draft.password" size="small" type="password" show-password />
|
|
32
|
-
</div>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<div v-if="testMessage" :class="[cls.e('test'), bem.is('ok', testOk)]" role="status">
|
|
36
|
-
{{ testMessage }}
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
|
-
<div :class="cls.e('actions')">
|
|
40
|
-
<u-button size="small" :loading="testing" @click="onTest">测试连接</u-button>
|
|
41
|
-
<u-button v-if="!isNew" size="small" type="danger" plain @click="emit('remove')">
|
|
42
|
-
删除连接
|
|
43
|
-
</u-button>
|
|
44
|
-
<u-button size="small" type="primary" @click="onSave">保存</u-button>
|
|
45
|
-
</div>
|
|
46
|
-
</section>
|
|
47
|
-
</template>
|
|
48
|
-
|
|
49
|
-
<script lang="ts" setup>
|
|
50
|
-
import { UButton, UInput, USelect } from '@veltra/desktop'
|
|
51
|
-
import { bem } from '@veltra/utils'
|
|
52
|
-
import { computed, reactive, ref, watch } from 'vue'
|
|
53
|
-
|
|
54
|
-
import type { ConnectionType, DataConnection, Result } from '../../report/connector'
|
|
55
|
-
import { DEFAULT_CONNECTION_PORTS, resolvePortOnTypeChange } from '../../report/connector'
|
|
56
|
-
|
|
57
|
-
defineOptions({ name: 'UReportHubConnectionForm' })
|
|
58
|
-
|
|
59
|
-
const props = defineProps<{
|
|
60
|
-
connection: DataConnection
|
|
61
|
-
isNew?: boolean
|
|
62
|
-
/** 真实测试连接(经 DataConnector;契约无状态,新建草稿同样可测) */
|
|
63
|
-
test: (connection: DataConnection) => Promise<Result<void>>
|
|
64
|
-
}>()
|
|
65
|
-
|
|
66
|
-
const emit = defineEmits<{ save: [connection: DataConnection]; remove: [] }>()
|
|
67
|
-
|
|
68
|
-
const cls = bem('report-hub-connection-form')
|
|
69
|
-
|
|
70
|
-
/** 连接类型收敛为 MySQL / PostgreSQL(ADR-0003 决策 3) */
|
|
71
|
-
const typeOptions: { label: string; value: ConnectionType }[] = [
|
|
72
|
-
{ label: 'MySQL', value: 'mysql' },
|
|
73
|
-
{ label: 'PostgreSQL', value: 'postgresql' }
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
const draft = reactive<DataConnection>({ ...props.connection })
|
|
77
|
-
|
|
78
|
-
const defaultPort = computed(() => DEFAULT_CONNECTION_PORTS[draft.type])
|
|
79
|
-
|
|
80
|
-
const portText = computed({
|
|
81
|
-
get: () => String(draft.port),
|
|
82
|
-
set: (value: string) => {
|
|
83
|
-
const n = Number(value)
|
|
84
|
-
draft.port = Number.isFinite(n) ? n : 0
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
const testing = ref(false)
|
|
89
|
-
const testMessage = ref('')
|
|
90
|
-
const testOk = ref(false)
|
|
91
|
-
|
|
92
|
-
watch(
|
|
93
|
-
() => props.connection,
|
|
94
|
-
(conn) => {
|
|
95
|
-
testMessage.value = ''
|
|
96
|
-
testOk.value = false
|
|
97
|
-
Object.assign(draft, conn)
|
|
98
|
-
},
|
|
99
|
-
{ immediate: true }
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
watch(
|
|
103
|
-
() => draft.type,
|
|
104
|
-
(type, prevType) => {
|
|
105
|
-
if (!prevType) return
|
|
106
|
-
draft.port = resolvePortOnTypeChange(prevType, type, draft.port)
|
|
107
|
-
}
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
async function onTest(): Promise<void> {
|
|
111
|
-
testing.value = true
|
|
112
|
-
testMessage.value = ''
|
|
113
|
-
const result = await props.test({ ...draft })
|
|
114
|
-
testing.value = false
|
|
115
|
-
testOk.value = result.ok
|
|
116
|
-
testMessage.value = result.ok
|
|
117
|
-
? `连接成功:${draft.label}(${draft.host}:${draft.port}/${draft.database})`
|
|
118
|
-
: result.error.message
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function onSave(): void {
|
|
122
|
-
emit('save', { ...draft })
|
|
123
|
-
}
|
|
124
|
-
</script>
|